From 3734b99119e1a66e7b22e77b5fa28c97cdd4eb0c Mon Sep 17 00:00:00 2001 From: mewdev Date: Wed, 1 Jan 2025 18:27:29 +0100 Subject: [PATCH] wip: toggleImportant (recapitulation) --- apps/web/app/xyz/rekapitulace/page.tsx | 5 ++ apps/web/app/xyz/store.ts | 16 ++++- .../src/ui/iconButton/starIconButton.tsx | 3 +- .../recapitulationCard/recapitulationCard.tsx | 71 ++++++++++--------- 4 files changed, 61 insertions(+), 34 deletions(-) diff --git a/apps/web/app/xyz/rekapitulace/page.tsx b/apps/web/app/xyz/rekapitulace/page.tsx index 0587e8c..1a42338 100644 --- a/apps/web/app/xyz/rekapitulace/page.tsx +++ b/apps/web/app/xyz/rekapitulace/page.tsx @@ -7,6 +7,9 @@ export default function Page() { const questions = useQuestionsStore((state) => state.questions); const toggleYes = useQuestionsStore((state) => state.toggleYes); const toggleNo = useQuestionsStore((state) => state.toggleNo); + const toggleImportantRec = useQuestionsStore( + (state) => state.toggleImportantRec, + ); function handleAnswer(event, buttonType) { // console.log(event.currentTarget.dataset.buttoncardid); @@ -16,6 +19,8 @@ export default function Page() { toggleYes(id); } else if (buttonType === "No") { toggleNo(id); + } else if (buttonType === "Togglerecimportant") { + toggleImportantRec(id); } } diff --git a/apps/web/app/xyz/store.ts b/apps/web/app/xyz/store.ts index 3bfae96..6b91f8c 100644 --- a/apps/web/app/xyz/store.ts +++ b/apps/web/app/xyz/store.ts @@ -1,6 +1,5 @@ import { create } from "zustand"; import { Question } from "@repo/schema/dist"; -import { devtools } from "zustand/middleware"; type ExtendedQuestions = Question & { isImportant: true | false | null; @@ -16,8 +15,10 @@ type QuestionsStore = { toggleImportant: () => void; answerYes: () => void; answerNo: () => void; + // fix no unused vars error toggleYes: (cardId: string) => void; toggleNo: (cardId: string) => void; + toggleImportantRec: (cardId: string) => void; setCurrentQuestion: (number: number) => void; }; @@ -130,6 +131,19 @@ export const useQuestionsStore = create((set) => ({ }); return { ...state, questions: updatedQuestions }; }), + toggleImportantRec: (cardId) => + set((state) => { + const updatedQuestions = state.questions.map((question) => { + if (cardId === question.id) { + return { + ...question, + isImportant: !question.isImportant, + }; + } + return { ...question }; + }); + return { ...state, questions: updatedQuestions }; + }), })); export type { ExtendedQuestions }; diff --git a/packages/design-system/src/ui/iconButton/starIconButton.tsx b/packages/design-system/src/ui/iconButton/starIconButton.tsx index cadd56e..15b0777 100644 --- a/packages/design-system/src/ui/iconButton/starIconButton.tsx +++ b/packages/design-system/src/ui/iconButton/starIconButton.tsx @@ -6,7 +6,7 @@ import { StarIconFilled } from "@repo/design-system/icons"; type Props = { children?: React.ReactNode; starPressed?: boolean; - onClick: () => void; + onClick: (event) => void; } & Omit< ComponentProps, "iconDefault" | "iconPressed" @@ -24,6 +24,7 @@ const StarIconButton = ({ iconPressed={StarIconFilled} onClick={onClick} togglePressed={starPressed} + data-togleiconbuttonid="Dupa" {...props} > {children} diff --git a/packages/design-system/src/ui/recapitulationCard/recapitulationCard.tsx b/packages/design-system/src/ui/recapitulationCard/recapitulationCard.tsx index e1af1ec..61525c9 100644 --- a/packages/design-system/src/ui/recapitulationCard/recapitulationCard.tsx +++ b/packages/design-system/src/ui/recapitulationCard/recapitulationCard.tsx @@ -12,6 +12,8 @@ type ExtendedQuestions = Question & { answerType: true | false | null | undefined; }; +// type answerType: true || false || null || undefined; + export interface Props { question: ExtendedQuestions; currentQuestion: number; @@ -101,7 +103,10 @@ export function RecapitulationCard({ >
{/* toggle star */} - alert("Important toggled")} /> + onClick(event, "Togglerecimportant")} + />
@@ -121,39 +126,41 @@ export function RecapitulationCard({
{switchButton(answerType)}
-
- - -
{detailToggled && (
-

- {detail} -

+
+ + +
+
+

+ {detail} +

+
)}