Added other filter & animations

This commit is contained in:
Théo 2023-04-21 17:03:34 +02:00
parent 9825f7b3de
commit 065f517d54
5 changed files with 30 additions and 13 deletions

View file

@ -20,10 +20,10 @@ export default async function Page() {
} }
return ( return (
<div className="flex flex-col space-y-6"> <section className="flex w-full flex-col space-y-6">
<SWRFallback fallback={{ ['puzzles']: puzzles }}> <SWRFallback fallback={{ ['puzzles']: puzzles }}>
<Puzzles token={token!} /> <Puzzles token={token!} />
</SWRFallback> </SWRFallback>
</div> </section>
); );
} }

View file

@ -2,7 +2,8 @@ export const getChapters = async ({ token }: { token: string }): Promise<Chapter
const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/chapters`, { const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/chapters`, {
headers: { headers: {
Authorization: `Bearer ${token}` Authorization: `Bearer ${token}`
} },
cache: 'force-cache'
}); });
const chapters = (await res.json()) as Chapter[]; const chapters = (await res.json()) as Chapter[];

View file

@ -43,7 +43,17 @@ export default function Puzzles({ token }: { token: string }) {
const filteredData = useMemo(() => { const filteredData = useMemo(() => {
if (filter && filterChapter) { if (filter && filterChapter) {
console.log(filter); if (filter === 'completed' || filter === 'no-completed') {
return data
?.find((chapter) => chapter.id === filterChapter)
?.puzzles.filter((puzzle) => {
if (filter === 'completed') {
return puzzle!.score;
}
return !puzzle!.score;
})
.map((puzzle) => puzzle);
}
return data return data
?.find((chapter) => chapter.id === filterChapter) ?.find((chapter) => chapter.id === filterChapter)
?.puzzles.filter((puzzle) => puzzle!.tags!.some((tag) => tag.name === filter)) ?.puzzles.filter((puzzle) => puzzle!.tags!.some((tag) => tag.name === filter))
@ -193,7 +203,7 @@ function PuzzleProp({ puzzle, chapter }: { puzzle: Puzzle; chapter: Chapter }) {
return ( return (
<li <li
className={cn( className={cn(
'group relative flex h-full w-full rounded-md border-2 bg-primary-700 font-code hover:bg-primary-600', 'group relative flex h-full w-full rounded-md border-2 bg-primary-700 font-code transition-colors duration-150 hover:bg-primary-600',
{ {
'border-green-600/30': puzzle.tags?.find((tag) => tag.name.toLowerCase() === 'easy'), 'border-green-600/30': puzzle.tags?.find((tag) => tag.name.toLowerCase() === 'easy'),
'border-yellow-600/30': puzzle.tags?.find((tag) => tag.name.toLowerCase() === 'medium'), 'border-yellow-600/30': puzzle.tags?.find((tag) => tag.name.toLowerCase() === 'medium'),
@ -284,6 +294,9 @@ function FilterChapter({
return { title: t!.name, value: t!.name }; return { title: t!.name, value: t!.name };
}) as { title: string; value: string }[]; }) as { title: string; value: string }[];
options?.unshift({ title: 'Pas encore terminé', value: 'no-completed' });
options?.unshift({ title: 'Terminés', value: 'completed' });
options?.unshift({ title: 'Tout les puzzles', value: '' }); options?.unshift({ title: 'Tout les puzzles', value: '' });
setFilterChapter(chapter.id); setFilterChapter(chapter.id);

View file

@ -16,7 +16,7 @@ const Select = forwardRef<
<Label label={label} description={description} required={props.required} className={className}> <Label label={label} description={description} required={props.required} className={className}>
<select <select
className={ className={
'w-full cursor-pointer overflow-hidden rounded-lg border-2 border-highlight-primary bg-transparent px-5 py-2.5 text-sm font-medium text-secondary opacity-80 outline-none outline-0 transition-opacity hover:opacity-100 focus:outline-none focus:ring-1 focus:ring-brand disabled:opacity-50' 'w-full cursor-pointer overflow-hidden rounded-lg border-2 border-highlight-primary bg-highlight-primary px-5 py-2.5 text-sm font-medium text-secondary opacity-80 outline-none outline-0 transition-opacity hover:opacity-100 focus:outline-none disabled:opacity-50'
} }
{...props} {...props}
ref={ref} ref={ref}

View file

@ -99,13 +99,16 @@ function NavItem({
href={isHttp ? item.slug : `dashboard/${item.slug}`} href={isHttp ? item.slug : `dashboard/${item.slug}`}
target={isHttp ? '_blank' : undefined} target={isHttp ? '_blank' : undefined}
rel={isHttp ? 'noopener noreferrer' : undefined} rel={isHttp ? 'noopener noreferrer' : undefined}
className={cn('flex justify-center rounded-md px-3 py-3 text-sm lg:justify-start', { className={cn(
'flex justify-center rounded-md px-3 py-3 text-sm transition-colors duration-150 lg:justify-start',
{
'text-muted hover:text-secondary': !isActive, 'text-muted hover:text-secondary': !isActive,
'bg-highlight-primary text-secondary': isActive, 'bg-highlight-primary text-secondary hover:text-white': isActive,
'cursor-not-allowed text-gray-600 hover:text-gray-600': item.disabled, 'cursor-not-allowed text-gray-600 hover:text-gray-600': item.disabled,
'justify-center lg:justify-start': isOpen, 'justify-center lg:justify-start': isOpen,
'justify-start sm:justify-center': !isOpen 'justify-start sm:justify-center': !isOpen
})} }
)}
onClick={onClick} onClick={onClick}
> >
<div className="flex items-center space-x-2"> <div className="flex items-center space-x-2">