mirror of
https://github.com/acid-info/logos-ordinals-dashboard.git
synced 2025-02-06 18:44:36 +00:00
feat: support operator api
This commit is contained in:
parent
41e02ff915
commit
2ed6880a87
@ -1,22 +1,15 @@
|
|||||||
import { breakpoints } from '@/configs/ui.configs'
|
import { breakpoints } from '@/configs/ui.configs'
|
||||||
|
import { ProcessedOperator } from '@/containers/Dashboard/DashboardContainer'
|
||||||
import styled from '@emotion/styled'
|
import styled from '@emotion/styled'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
|
||||||
interface Operator {
|
|
||||||
id: string
|
|
||||||
image: string
|
|
||||||
name: string
|
|
||||||
pointsPerHour: number
|
|
||||||
isStaked: boolean
|
|
||||||
isPinned: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
interface OperatorGridProps {
|
interface OperatorGridProps {
|
||||||
isLoading: boolean
|
isLoading: boolean
|
||||||
|
data: ProcessedOperator[]
|
||||||
}
|
}
|
||||||
|
|
||||||
const operators: Operator[] = [
|
const operators: ProcessedOperator[] = [
|
||||||
{
|
{
|
||||||
id: '1',
|
id: '1',
|
||||||
image: '/dashboard/mock/operators/1.gif',
|
image: '/dashboard/mock/operators/1.gif',
|
||||||
@ -77,6 +70,7 @@ const operators: Operator[] = [
|
|||||||
|
|
||||||
const OperatorGrid: React.FC<OperatorGridProps> = ({
|
const OperatorGrid: React.FC<OperatorGridProps> = ({
|
||||||
isLoading,
|
isLoading,
|
||||||
|
data,
|
||||||
}: OperatorGridProps) => {
|
}: OperatorGridProps) => {
|
||||||
return (
|
return (
|
||||||
<StyledOperatorGrid>
|
<StyledOperatorGrid>
|
||||||
@ -117,7 +111,7 @@ const OperatorGrid: React.FC<OperatorGridProps> = ({
|
|||||||
<Placeholder />
|
<Placeholder />
|
||||||
</OperatorCard>
|
</OperatorCard>
|
||||||
))
|
))
|
||||||
: operators.map((operator) => (
|
: data.map((operator) => (
|
||||||
<OperatorCard key={operator.id}>
|
<OperatorCard key={operator.id}>
|
||||||
<Link href={`/operators/${operator.id}`} key={operator.id}>
|
<Link href={`/operators/${operator.id}`} key={operator.id}>
|
||||||
<OperatorImage src={operator.image} alt={operator.name} />
|
<OperatorImage src={operator.image} alt={operator.name} />
|
||||||
|
@ -11,12 +11,54 @@ export type DashboardPageProps = React.DetailedHTMLProps<
|
|||||||
HTMLDivElement
|
HTMLDivElement
|
||||||
>
|
>
|
||||||
|
|
||||||
|
export interface Operator {
|
||||||
|
id: number
|
||||||
|
name: string
|
||||||
|
image_400_url: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Group {
|
||||||
|
id: number
|
||||||
|
name: string
|
||||||
|
operators: Operator[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ProcessedOperator {
|
||||||
|
id: string
|
||||||
|
image: string
|
||||||
|
name: string
|
||||||
|
pointsPerHour: number
|
||||||
|
isStaked: boolean
|
||||||
|
isPinned: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
function processOperators(data: Group[]): ProcessedOperator[] {
|
||||||
|
return data?.flatMap((group) =>
|
||||||
|
group.operators.map((operator) => ({
|
||||||
|
id: operator.id.toString(), // Convert ID to string
|
||||||
|
image: operator.image_400_url,
|
||||||
|
name: `OP ${operator.id}`,
|
||||||
|
pointsPerHour: Math.floor(Math.random() * 500), // Random value for points per hour
|
||||||
|
isStaked: false,
|
||||||
|
isPinned: false,
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const DashboardContainer: React.FC<DashboardPageProps> = ({
|
const DashboardContainer: React.FC<DashboardPageProps> = ({
|
||||||
children,
|
children,
|
||||||
...props
|
...props
|
||||||
}) => {
|
}) => {
|
||||||
const { data, isLoading } = useGetOperators()
|
const { data, isLoading } = useGetOperators()
|
||||||
console.log(data)
|
|
||||||
|
const processedOperators = processOperators(data)
|
||||||
|
|
||||||
|
function getRandomSubset<T>(array: T[], count: number): T[] {
|
||||||
|
const shuffled = array?.sort(() => 0.5 - Math.random())
|
||||||
|
return shuffled?.slice(0, count)
|
||||||
|
}
|
||||||
|
|
||||||
|
const random20Operators = getRandomSubset(processedOperators, 20)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container {...props}>
|
<Container {...props}>
|
||||||
@ -26,7 +68,7 @@ const DashboardContainer: React.FC<DashboardPageProps> = ({
|
|||||||
</LeftColumn>
|
</LeftColumn>
|
||||||
<RightColumn>
|
<RightColumn>
|
||||||
<ProgressBar progress={20} claimPosition={60} />
|
<ProgressBar progress={20} claimPosition={60} />
|
||||||
<OperatorGrid isLoading={isLoading} />
|
<OperatorGrid data={random20Operators} isLoading={isLoading} />
|
||||||
</RightColumn>
|
</RightColumn>
|
||||||
</Wrapper>
|
</Wrapper>
|
||||||
</Container>
|
</Container>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user