Skip to content

Commit

Permalink
wip: toggleImportant (recapitulation)
Browse files Browse the repository at this point in the history
  • Loading branch information
mewdev committed Jan 1, 2025
1 parent e7b46be commit 3734b99
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 34 deletions.
5 changes: 5 additions & 0 deletions apps/web/app/xyz/rekapitulace/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -16,6 +19,8 @@ export default function Page() {
toggleYes(id);
} else if (buttonType === "No") {
toggleNo(id);
} else if (buttonType === "Togglerecimportant") {
toggleImportantRec(id);
}
}

Expand Down
16 changes: 15 additions & 1 deletion apps/web/app/xyz/store.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
};

Expand Down Expand Up @@ -130,6 +131,19 @@ export const useQuestionsStore = create<QuestionsStore>((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 };
3 changes: 2 additions & 1 deletion packages/design-system/src/ui/iconButton/starIconButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { StarIconFilled } from "@repo/design-system/icons";
type Props = {
children?: React.ReactNode;
starPressed?: boolean;
onClick: () => void;
onClick: (event) => void;

Check warning on line 9 in packages/design-system/src/ui/iconButton/starIconButton.tsx

View workflow job for this annotation

GitHub Actions / Build & lint

'event' is defined but never used
} & Omit<
ComponentProps<typeof ToggleIconButton>,
"iconDefault" | "iconPressed"
Expand All @@ -24,6 +24,7 @@ const StarIconButton = ({
iconPressed={StarIconFilled}
onClick={onClick}
togglePressed={starPressed}
data-togleiconbuttonid="Dupa"
{...props}
>
{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -101,7 +103,10 @@ export function RecapitulationCard({
>
<div className="k1-flex k1-items-center k1-justify-between">
{/* toggle star */}
<StarIconButton onClick={() => alert("Important toggled")} />
<StarIconButton
data-togglebuttonid="Testid"
onClick={(event) => onClick(event, "Togglerecimportant")}
/>

<div className="k1-mr-auto k1-flex k1-flex-col">
<div className="k1-flex k1-flex-wrap k1-items-center k1-gap-4">
Expand All @@ -121,39 +126,41 @@ export function RecapitulationCard({
<DetailIconButton onClick={toggleDetail} />
<div>{switchButton(answerType)}</div>
</div>
<div className="k1-flex k1-w-full">
<Button
kind="inverse"
color="primary"
size="default"
hasIcon
icon={YesIcon}
compactable
wider
data-buttonCardId={id}
onClick={(event) => onClick(event, "Yes")}
>
Ano
</Button>
<Button
kind="inverse"
color="secondary"
size="default"
hasIcon
icon={NoIcon}
compactable
wider
data-buttonCardId={id}
onClick={(event) => onClick(event, "No")}
>
Ne
</Button>
</div>
{detailToggled && (
<div>
<p className="k1-text-base k1-font-normal k1-text-neutral">
{detail}
</p>
<div className="k1-flex k1-w-full">
<Button
kind="inverse"
color="primary"
size="default"
hasIcon
icon={YesIcon}
compactable
wider
data-buttonCardId={id}
onClick={(event) => onClick(event, "Yes")}
>
Ano
</Button>
<Button
kind="inverse"
color="secondary"
size="default"
hasIcon
icon={NoIcon}
compactable
wider
data-buttonCardId={id}
onClick={(event) => onClick(event, "No")}
>
Ne
</Button>
</div>
<div>
<p className="k1-text-base k1-font-normal k1-text-neutral">
{detail}
</p>
</div>
</div>
)}
</Card>
Expand Down

0 comments on commit 3734b99

Please sign in to comment.