Skip to content

Commit

Permalink
wip: url dynamic changing, updated button urls
Browse files Browse the repository at this point in the history
  • Loading branch information
mewdev committed Jan 15, 2025
1 parent 711874a commit 42a718d
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 15 deletions.
31 changes: 21 additions & 10 deletions apps/web/app/abc/navod/[guideNumber]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,22 @@ import {
ArrowIconRight,
ForwardIcon,
} from "@repo/design-system/icons";
import { useParams } from "next/navigation";
import { useEffect } from "react";

export default function Page() {
const params = useParams();
const guide = useQuestionsStore((state) => state.guide);
const guideNumber = useQuestionsStore((state) => state.guideNumber);
const setGuideNumber = useQuestionsStore((state) => state.setGuideNumber);
const prevGuide = useQuestionsStore((state) => state.prevGuide);
const nextGuide = useQuestionsStore((state) => state.nextGuide);

// ** NEEEDS REFACTOR! ** set question from params
useEffect(() => {
setGuideNumber(Number(params.guideNumber));
}, []);

const guideCardSwitcher = (number: number) => {
switch (number) {
case 1: {
Expand Down Expand Up @@ -144,16 +153,18 @@ export default function Page() {
Další krok
</Button>
) : (
<Button
kind="filled"
size="default"
color="primary"
iconPosition="right"
icon={ArrowIconRight}
hasIcon
>
<Link href="/abc/otazka/1">První otázka</Link>
</Button>
<Link href="/abc/otazka/1">
<Button
kind="filled"
size="default"
color="primary"
iconPosition="right"
icon={ArrowIconRight}
hasIcon
>
První otázka
</Button>
</Link>
)}
</div>
{/* grid col 4 */}
Expand Down
11 changes: 11 additions & 0 deletions apps/web/app/abc/otazka/[questionNumber]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,32 @@
import { BottomBar, QuestionWrapper } from "@repo/design-system/ui";
import { useQuestionsStore } from "../../providers/storeProvider";
import { Question } from "@repo/schema/dist";
import { useEffect } from "react";
import { useParams } from "next/navigation";

type ExtendedQuestions = Question & {
isImportant: true | false | null;
answerType: true | false | null;
};

export default function Page() {
const params = useParams();
const questions = useQuestionsStore((state) => state.questions);
const currentQuestion = useQuestionsStore((state) => state.currentQuestion);
const setCurrentQuestion = useQuestionsStore(
(state) => state.setCurrentQuestion,
);
const prevQuestion = useQuestionsStore((state) => state.prevQuestion);
const skipQuestion = useQuestionsStore((state) => state.skipQuestion);
const toggleImportant = useQuestionsStore((state) => state.toggleImportant);
const answerYes = useQuestionsStore((state) => state.answerYes);
const answerNo = useQuestionsStore((state) => state.answerNo);

// ** NEEEDS REFACTOR! ** set question from params
useEffect(() => {
setCurrentQuestion(Number(params.questionNumber));
}, []);

return (
<>
<main className="relative flex h-screen items-center justify-center">
Expand Down
3 changes: 3 additions & 0 deletions apps/web/app/abc/providers/storeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Store = {
guide: Guide;
isRekapitulace: boolean;
currentLocation: "navod" | "otazka" | "rekapitulace" | null;
setGuideNumber: (guideNumber: number) => void;
setCurrentLocation: (
currentLocation: "navod" | "otazka" | "rekapitulace",
) => void;
Expand Down Expand Up @@ -120,6 +121,8 @@ export const StoreProvider = ({ children, questions }: StoreProviderProps) => {
set((state) => ({ currentQuestion: state.currentQuestion + 1 })),
guideNumber: 1,
guide: guide,
setGuideNumber: (guideNumber) =>
set(() => ({ guideNumber: guideNumber })),
prevGuide: () => set((state) => ({ guideNumber: state.guideNumber - 1 })),
nextGuide: () => {
set((state) => ({ guideNumber: state.guideNumber + 1 }));
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/abc/utils/urlUpdater.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function UrlUpdater({ children }: Props) {
}, []);

useEffect(() => {
// cleanups ?
// !!! implement cleanups!
// change url
function changeUrl() {
// insert conditionals here for edge cases?
Expand Down
22 changes: 18 additions & 4 deletions packages/design-system/src/ui/layout/questionWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Button } from "@repo/design-system/ui";
import { ArrowIconLeft, ArrowIconRight } from "@repo/design-system/icons";
import { QuestionCard } from "@repo/design-system/ui";
import type { Question } from "@repo/schema/dist/question.schema";
import Link from "next/link";

type ExtendedQuestions = Question & {
isImportant: true | false | null;
Expand All @@ -28,6 +29,7 @@ export function QuestionWrapper({
<>
{/* content */}
{/* mobile arrow bar */}
{/* button link wrapping solve! */}
<div className="k1-absolute k1-top-0 k1-w-dvw k1-flex k1-justify-between sm:k1-hidden">

Check warning on line 33 in packages/design-system/src/ui/layout/questionWrapper.tsx

View workflow job for this annotation

GitHub Actions / Build & lint

Invalid Tailwind CSS classnames order
<Button
hasIcon
Expand All @@ -37,7 +39,11 @@ export function QuestionWrapper({
fitContent
onClick={prevQuestion}
>
{currentQuestion === 1 ? "Návod" : "Předchozí"}
{currentQuestion === 1 ? (
<Link href="/abc/navod">Návod</Link>
) : (
"Předchozí"
)}
</Button>
<Button
hasIcon
Expand All @@ -47,7 +53,11 @@ export function QuestionWrapper({
fitContent
onClick={skipQuestion}
>
{currentQuestion >= questionCount ? "Rekapitulace" : "Přeskočit"}
{currentQuestion >= questionCount ? (
<Link href="/abc/rekapitulace">Rekapitulace</Link>
) : (
"Přeskočit"
)}
</Button>
</div>

Expand All @@ -66,7 +76,9 @@ export function QuestionWrapper({
// fix k1 prefix issue!!!
>
{currentQuestion === 1 ? (
<span className="k1-hidden lg:k1-inline">Návod</span>
<span className="k1-hidden lg:k1-inline">
<Link href="/abc/navod">Návod</Link>
</span>
) : (
<span className="k1-hidden md:k1-block">
Předchozí{" "}
Expand Down Expand Up @@ -95,7 +107,9 @@ export function QuestionWrapper({
onClick={skipQuestion}
>
{currentQuestion >= questionCount ? (
<span className="k1-hidden lg:k1-inline">Rekapitulace</span>
<span className="k1-hidden lg:k1-inline">
<Link href="/abc/rekapitulace">Rekapitulace</Link>
</span>
) : (
<span className="k1-hidden md:k1-block">
Přeskočit{" "}
Expand Down

0 comments on commit 42a718d

Please sign in to comment.