- {puzzle.name} ({puzzle.scoreMax})
+ {puzzle.name}{' '}
+
+ ({puzzle.score ? `${puzzle.score}` : '?'}/{puzzle.scoreMax} points)
+
{puzzle.tags?.length && (
@@ -280,7 +312,7 @@ function PuzzleProp({ puzzle, chapter }: { puzzle: Puzzle; chapter: Chapter }) {
);
}
-function FilterChapter({
+function FilterDifficulty({
chapters,
chapter,
filter,
@@ -294,7 +326,7 @@ function FilterChapter({
setFilterChapter: (chapter: number) => void;
}) {
const [stored, setStored] = useLocalStorage({
- key: 'puzzles-filter',
+ key: 'filter-difficulty',
initialValue: ''
});
@@ -304,12 +336,65 @@ function FilterChapter({
.find((c) => c.id === chapter.id)
?.puzzles?.map((p) => p.tags)
.flat()
+ .filter((tag) => difficulty.some((d) => tag?.name === d.value))
.filter((tag, index, self) => self.findIndex((t) => t!.name === tag!.name) === index)
.map((t) => {
return { title: t!.name, value: t!.name };
}) as { title: string; value: string }[];
- options?.unshift({ title: 'Pas encore terminé(s)', value: 'no-completed' });
+ options?.unshift({ title: 'Toutes les difficultés', value: '' });
+
+ setFilterChapter(chapter.id);
+
+ function handleChange(event: ChangeEvent) {
+ setFilter(event.target.value);
+ // TODO OPTI
+ // @ts-ignore
+ setStored(event.target.value);
+ }
+
+ useEffect(() => {
+ if (stored) {
+ // TODO OPTI
+ // @ts-ignore
+ setFilter(stored);
+ }
+ }, [stored]);
+
+ return ;
+}
+
+function FilterTags({
+ chapters,
+ chapter,
+ filter,
+ setFilter,
+ setFilterChapter
+}: {
+ chapters: Chapter[];
+ chapter: Chapter;
+ filter: string;
+ setFilter: (filter: string) => void;
+ setFilterChapter: (chapter: number) => void;
+}) {
+ const [stored, setStored] = useLocalStorage({
+ key: 'filter-tags',
+ initialValue: ''
+ });
+
+ let options = [] as { title: string; value: string }[];
+
+ options = chapters
+ .find((c) => c.id === chapter.id)
+ ?.puzzles?.map((p) => p.tags)
+ .flat()
+ .filter((tag) => !difficulty.some((d) => tag?.name === d.value))
+ .filter((tag, index, self) => self.findIndex((t) => t!.name === tag!.name) === index)
+ .map((t) => {
+ return { title: t!.name, value: t!.name };
+ }) as { title: string; value: string }[];
+
+ options?.unshift({ title: 'Pas encore terminé(s)', value: 'not-completed' });
options?.unshift({ title: 'Terminé(s)', value: 'completed' });
options?.unshift({ title: 'Tout les puzzles', value: '' });
diff --git a/ui/Select.tsx b/ui/Select.tsx
index d27a0fa..c2af9eb 100644
--- a/ui/Select.tsx
+++ b/ui/Select.tsx
@@ -22,7 +22,7 @@ const Select = forwardRef<
ref={ref}
>
{options.map((option) => (
-
))}