-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
135 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Card, CardContent, CardHeader } from '@/components/ui/card'; | ||
import { Skeleton } from '@/components/ui/skeleton'; | ||
|
||
const CardLoading = () => { | ||
return ( | ||
<Card className='cursor-pointer aspect-square'> | ||
<CardHeader> | ||
<div className='flex items-center justify-center'> | ||
<Skeleton className='w-[128px] aspect-square duration-10 opacity-100' /> | ||
</div> | ||
</CardHeader> | ||
<CardContent> | ||
<div className='flex flex-col items-center justify-center gap-2'> | ||
<Skeleton className='w-40 h-4 opacity-100 duration-10' /> | ||
<div className='flex justify-center gap-2'> | ||
<Skeleton className='w-16 h-4 opacity-100 duration-10' /> | ||
<Skeleton className='w-16 h-4 opacity-100 duration-10' /> | ||
</div> | ||
</div> | ||
</CardContent> | ||
</Card> | ||
); | ||
}; | ||
|
||
export default CardLoading; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,83 @@ | ||
import { | ||
Pagination, | ||
PaginationContent, | ||
PaginationItem, | ||
PaginationLink, | ||
PaginationNext, | ||
PaginationPrevious | ||
} from "@/components/ui/pagination"; | ||
import { Skeleton } from "@/components/ui/skeleton"; | ||
import { GetAllPokemonParams } from "@/types"; | ||
import { Link, createFileRoute } from "@tanstack/react-router"; | ||
import PokemonCard from "./-components/PokemonCard"; | ||
import { usePokemonImpl } from "./-usePokemonImpl"; | ||
Pagination, | ||
PaginationContent, | ||
PaginationItem, | ||
PaginationLink, | ||
PaginationNext, | ||
PaginationPrevious | ||
} from '@/components/ui/pagination'; | ||
import { GetAllPokemonParams } from '@/types'; | ||
import { Link, createFileRoute } from '@tanstack/react-router'; | ||
import CardLoading from './-components/CardLoading'; | ||
import PokemonCard from './-components/PokemonCard'; | ||
import { usePokemonImpl } from './-usePokemonImpl'; | ||
|
||
export const Route = createFileRoute("/pokemon/")({ | ||
component: Pokemon, | ||
validateSearch: (search: Record<string, unknown>): GetAllPokemonParams => { | ||
return { | ||
limit: (search.limit as number) ?? 15, | ||
offset: (search.offset as number) ?? 0 | ||
}; | ||
} | ||
export const Route = createFileRoute('/pokemon/')({ | ||
component: Pokemon, | ||
validateSearch: (search: Record<string, unknown>): GetAllPokemonParams => { | ||
return { | ||
limit: (search.limit as number) ?? 15, | ||
offset: (search.offset as number) ?? 0 | ||
}; | ||
} | ||
}); | ||
|
||
function Pokemon() { | ||
const params = Route.useSearch(); | ||
const params = Route.useSearch(); | ||
|
||
const { data, isLoading } = usePokemonImpl({ params }); | ||
const { data, isLoading } = usePokemonImpl({ params }); | ||
|
||
return ( | ||
<> | ||
{isLoading ? ( | ||
<div className='grid grid-cols-5 gap-4 mb-6'> | ||
{Array(15) | ||
.fill(0) | ||
.map(() => ( | ||
<Skeleton className='w-full aspect-square' /> | ||
))} | ||
</div> | ||
) : ( | ||
<div className='grid grid-cols-5 gap-4 mb-6'> | ||
{data?.results.map((pokemon) => ( | ||
<PokemonCard {...pokemon} key={pokemon.name} /> | ||
))} | ||
</div> | ||
)} | ||
return ( | ||
<> | ||
{isLoading ? ( | ||
<div className='grid grid-cols-5 gap-4 mb-6'> | ||
{Array(15) | ||
.fill(0) | ||
.map(() => ( | ||
<CardLoading /> | ||
))} | ||
</div> | ||
) : ( | ||
<div className='grid grid-cols-5 gap-4 mb-6'> | ||
{data?.results.map((pokemon) => ( | ||
<PokemonCard {...pokemon} key={pokemon.name} /> | ||
))} | ||
</div> | ||
)} | ||
|
||
<Pagination> | ||
<PaginationContent> | ||
<PaginationItem> | ||
<Link | ||
href='#' | ||
search={{ | ||
...params, | ||
offset: params.offset - params.limit | ||
}} | ||
disabled={params.offset === 0} | ||
> | ||
<PaginationPrevious /> | ||
</Link> | ||
</PaginationItem> | ||
<PaginationItem> | ||
<PaginationLink href='#' isActive> | ||
{params.offset / params.limit + 1} | ||
</PaginationLink> | ||
</PaginationItem> | ||
<PaginationItem> | ||
<Link | ||
href='#' | ||
disabled={params.offset === data?.count} | ||
search={{ | ||
...params, | ||
offset: params.offset + params.limit | ||
}} | ||
> | ||
<PaginationNext href='#' /> | ||
</Link> | ||
</PaginationItem> | ||
</PaginationContent> | ||
</Pagination> | ||
</> | ||
); | ||
<Pagination> | ||
<PaginationContent> | ||
<PaginationItem> | ||
<Link | ||
href='#' | ||
search={{ | ||
...params, | ||
offset: params.offset - params.limit | ||
}} | ||
disabled={params.offset === 0} | ||
> | ||
<PaginationPrevious /> | ||
</Link> | ||
</PaginationItem> | ||
<PaginationItem> | ||
<PaginationLink href='#' isActive> | ||
{params.offset / params.limit + 1} | ||
</PaginationLink> | ||
</PaginationItem> | ||
<PaginationItem> | ||
<Link | ||
href='#' | ||
disabled={params.offset === data?.count} | ||
search={{ | ||
...params, | ||
offset: params.offset + params.limit | ||
}} | ||
> | ||
<PaginationNext href='#' /> | ||
</Link> | ||
</PaginationItem> | ||
</PaginationContent> | ||
</Pagination> | ||
</> | ||
); | ||
} |