Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Design system/question layout #73

Open
wants to merge 52 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
49962aa
wip: questionPage and its layout components folder structure cleanup,…
mewdev Dec 4, 2024
2ddf85c
wip: clientWrapper workaround component, data test
mewdev Dec 5, 2024
c705746
wip: data binded to the questionCard component
mewdev Dec 5, 2024
5525981
wip: adding simple interactivity
mewdev Dec 6, 2024
40812fa
wip: added simple interactivity for steps, needs fix with questionCount
mewdev Dec 9, 2024
e780729
wip: steps with currentQuestion count fixed
mewdev Dec 9, 2024
5ed3045
wip: styling status bar working, active status bar needs fix
mewdev Dec 10, 2024
29b03da
wip: guide and results subpages with mockup content introduec
mewdev Dec 10, 2024
617efab
wip: some errors fixed, debugging active step glitch
mewdev Dec 10, 2024
139cf22
wip: statusbar interactivity fixed with all buttons, rekapitulace co…
mewdev Dec 11, 2024
41b064e
wip: important added to answers and state change works, fix needed: u…
mewdev Dec 11, 2024
5b9a9b2
wip: toggleStarIcon state pressed and preserved, fix needed: rerender…
mewdev Dec 12, 2024
b9f973c
wip: fixed rerender of starToggleIcon, needs refactoring then
mewdev Dec 12, 2024
01869f8
fix: vscode syntax errors fixed
mewdev Dec 13, 2024
93aad31
wip: testing next dynamic router with questions data
mewdev Dec 16, 2024
f4b4d3a
wip: dynamic route updated to have a index number of the question
mewdev Dec 16, 2024
9b24f1a
wip: implementing layouts to the new improved routing
mewdev Dec 18, 2024
46a869b
wip: questions pages architecture test
mewdev Dec 18, 2024
79dba0c
wip: questions pages architecture test continuation
mewdev Dec 19, 2024
2c82878
wip: rework with zustand, testing zustand
mewdev Dec 21, 2024
487ed25
wip: skip/previous and toggle working
mewdev Dec 21, 2024
b85c307
wip: answer yes/no working
mewdev Dec 21, 2024
1aca9fb
wip: components integration (bottomBar)
mewdev Dec 23, 2024
137c2d3
wip: component integration and refactor (questionWrapper)
mewdev Dec 23, 2024
4407d4f
wip: initializer, fetching data and updating the store
mewdev Dec 23, 2024
b52c9c1
wip: bottom bar toggle button state bug fixed
mewdev Dec 25, 2024
2895c55
wip: type errors fixed
mewdev Dec 25, 2024
cbfb930
wip: dynamic url test
mewdev Dec 25, 2024
d7f0a47
wip: mockup url update works
mewdev Dec 28, 2024
ffc8546
wip: guide interactivity sketch
mewdev Dec 28, 2024
2a33d8d
wip: rekapitulace page sketch
mewdev Dec 29, 2024
4965550
wip: recapitulation components
mewdev Dec 30, 2024
5623155
wip: toggleStarComponent children optimization, recapitulationCard co…
mewdev Dec 30, 2024
5e6b20f
wip: recapitulation card component interactivity
mewdev Dec 30, 2024
addfa8c
wip: recapitulation card interactivity working
mewdev Dec 31, 2024
e7b46be
wip: recapitulation cad small fixes
mewdev Dec 31, 2024
3734b99
wip: toggleImportant (recapitulation)
mewdev Jan 1, 2025
f21b125
wip: toggleImportant (recapitulation card) working, updated toggleSta…
mewdev Jan 1, 2025
5a8ac1a
wip: toggleImportant starPressed fix
mewdev Jan 2, 2025
bba3281
wip: fixing flow redirections and components visibility
mewdev Jan 3, 2025
54d1ded
wip: fixing flow redirections and components visibility
mewdev Jan 3, 2025
5a180e2
refactor: rename testQuestions to questions for clarity and consisten…
mewdev Jan 6, 2025
d82d4b1
wip: questionsPage (/xyz) refactor within /abc route, context test, b…
mewdev Jan 9, 2025
c37dc88
wip: implement question navigation and URL updates using Zustand stor…
mewdev Jan 9, 2025
0f3bcea
wip: migrated from mockup counter store to questions store, update co…
mewdev Jan 9, 2025
7829734
wip: implement dynamic question fetching and update URL handling
mewdev Jan 9, 2025
4162d12
wip: remove unused components and restructure question handling in th…
mewdev Jan 9, 2025
5b8d657
wip: updated question and guide handling in store, enhance data struc…
mewdev Jan 10, 2025
e9130cd
wip: enhance question handling with extended types, update layout
mewdev Jan 10, 2025
36662dd
wip: enhance question handling with new answer types and toggle funct…
mewdev Jan 10, 2025
c3d3800
wip: guide css refactor
mewdev Jan 11, 2025
7f50eb9
refactor: update layout and styling for guide page
mewdev Jan 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions apps/design-system/stories/bottomBar.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { Meta, StoryObj } from "@storybook/react";

import { BottomBar } from "@repo/design-system/ui";

const meta: Meta<typeof BottomBar> = {
title: "Layout/BottomBar",
component: BottomBar,
};

type BottomBarStory = StoryObj<typeof meta>;

export const Default: BottomBarStory = {};

export default meta;
4 changes: 2 additions & 2 deletions apps/design-system/stories/iconButton.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IconButton } from "@repo/design-system/iconButton";
import { StarIcon } from "@repo/design-system/starIcon";
import { IconButton } from "@repo/design-system/ui";
import { StarIcon } from "@repo/design-system/icons";
import { Meta, StoryObj } from "@storybook/react";

export default {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { Meta, StoryObj } from "@storybook/react";

import { Question } from "@repo/design-system/ui";
import { QuestionCard } from "@repo/design-system/ui";

const meta: Meta<typeof Question> = {
title: "Layouts/Question",
component: Question,
const meta: Meta<typeof QuestionCard> = {
title: "Layout/Question",
component: QuestionCard,
};

type QuestionStory = StoryObj<typeof meta>;
Expand Down
2 changes: 1 addition & 1 deletion apps/design-system/stories/starIconButton.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StarIconButton } from "@repo/design-system/starIconButton";
import { StarIconButton } from "../../../packages/design-system/src/ui/iconButton/starIconButton";
import { Meta, StoryObj } from "@storybook/react";

export default {
Expand Down
2 changes: 1 addition & 1 deletion apps/design-system/stories/toggleButton.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { YesIcon } from "@repo/design-system/demo";
import { ToggleButton } from "@repo/design-system/toggleButton";
import { ToggleButton } from "@repo/design-system/ui";
import { Meta, StoryObj } from "@storybook/react";

export default {
Expand Down
2 changes: 1 addition & 1 deletion apps/design-system/stories/toggleIconButton.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Meta, StoryObj } from "@storybook/react";
import { ToggleIconButton } from "@repo/design-system/toggleIconButton";
import { ToggleIconButton } from "@repo/design-system/ui";

export default {
title: "Components/ToggleIconButton",
Expand Down
217 changes: 217 additions & 0 deletions apps/web/app/[lang]/otazka/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
"use client";
import { useEffect, useState } from "react";
import {
ClientBottomBar,
ClientQuestionWrapper,
} from "../../temp/ClientWrapper";

import {
Spinner,
QuestionGuide,
QuestionResults,
} from "@repo/design-system/ui";

import type { Question } from "@repo/schema/dist";

type Questions = {
id: string;
status: null;
important: boolean;
};

type Steps = {
answers: any[];
totalQuestion: number;
currentQuestion: number;
};

export default function Page() {
const [questions, setQuestions] = useState([]);
const [isLoading, setIsLoading] = useState(true);
const [guideDisplay, setGuideDisplay] = useState(true);
const [currentQuestion, setCurrentQuestion] = useState(0);
// steps for progress bar
const [steps, setSteps] = useState<Steps>({
answers: [],
totalQuestion: questions.length,
currentQuestion: 0,
});

const questionsArray = steps.answers;

function handleClick(button: string) {
switch (button) {
case "inFavour":
setSteps((prevSteps) => {
const updatedAnswer = prevSteps.answers.map((answer, index) => {
if (index === currentQuestion - 1) {
return { ...answer, status: true };
}
return answer;
});

return {
...prevSteps,
answers: updatedAnswer,
currentQuestion: prevSteps.currentQuestion + 1,
};
});
setCurrentQuestion((prevState) => prevState + 1);
break;
case "against":
setSteps((prevSteps) => {
const updatedAnswer = prevSteps.answers.map((answer, index) => {
if (index === currentQuestion - 1) {
return { ...answer, status: false };
}
return answer;
});

return {
...prevSteps,
answers: updatedAnswer,
currentQuestion: prevSteps.currentQuestion + 1,
};
});
setCurrentQuestion((prevState) => prevState + 1);
break;
case "prev":
setCurrentQuestion((prevState) => prevState - 1);
setSteps((prevState) => {
return {
...prevState,
currentQuestion: prevState.currentQuestion - 1,
};
});
break;
// fix button naming and args to "skip" and null set
case "next":
setCurrentQuestion((prevState) => prevState + 1);
setSteps((prevState) => {
return {
...prevState,
currentQuestion: prevState.currentQuestion + 1,
};
});
break;
case "guide":
setGuideDisplay(false);
setCurrentQuestion((prevState) => prevState + 1);
setSteps((prevSteps) => {
return {
...prevSteps,
currentQuestion: prevSteps.currentQuestion + 1,
};
});
break;
case "star":
setSteps((prevSteps) => {
const updatedAnswer = prevSteps.answers.map((answer, index) => {
if (index === currentQuestion - 1) {
return { ...answer, important: !answer.important };
}
return answer;
});

return {
...prevSteps,
answers: updatedAnswer,
// currentQuestion: prevSteps.currentQuestion + 1,
};
});
break;
}
}

useEffect(() => {
// 1. Data call and data questions state update
const fetchData = async () => {
const res = await fetch(
"https://www.volebnikalkulacka.cz/data/instance/volebnikalkulacka.cz/krajske-2024/10-jihomoravsky/questions.json",
);
const data = await res.json();
setIsLoading(false);
setQuestions(data);

// populating steps state
const answersArray = data.map((data: Questions) => {
return { answerId: data.id, status: null, important: false };
});
const answers = {
answers: answersArray.flat(),
totalQuestion: questions.length,
currentQuestion: currentQuestion,
};

setSteps(answers);
};
fetchData();
}, []);

// cleanup useEffects then
useEffect(() => {
// console.log("Component rendered")
}, [steps]);

const questionCount = questions.length;

return (
<div className="flex flex-col justify-center self-end">
{guideDisplay || currentQuestion === 0 ? (
<QuestionGuide onClick={handleClick} />
) : null}
{/* // fix glitch beginning */}
{currentQuestion > questions.length && currentQuestion !== 0 ? (
<QuestionResults />
) : null}
{/* loader needed? */}
{isLoading && <Spinner />}
{/* find better approach than map */}
{questions.map((question: Question, index) => {
const questionNumber = index + 1;
if (questionNumber === currentQuestion) {
// cleanup api and get rif of wrapper
return (
<ClientQuestionWrapper
// fix needed: better key naming ?
key={`Question: ${question.id}`}
currentQuestion={currentQuestion}
questionCount={questionCount}
question={question}
onClick={handleClick}
guideDisplay={guideDisplay}
/>
);
}
})}
{/* Bottom bar */}
{/* write more elegantly */}
{questionsArray.map((question, index) => {
const questionNumber = index + 1;
if (question.important === true && questionNumber === currentQuestion) {
return (
// fix needed: better key naming ?
<ClientBottomBar
key={`Bottom bar (starPressed): ${question.id}`}
starPressed
onClick={handleClick}
steps={steps}
/>
);
} else if (
question.important === false &&
questionNumber === currentQuestion
) {
// fix needed: better key naming ?
return (
<ClientBottomBar
key={`Bottom bar (default): ${question.id}`}
onClick={handleClick}
steps={steps}
/>
);
}
})}
</div>
);
}
49 changes: 49 additions & 0 deletions apps/web/app/[lang]/otazky/[index]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// import OtazkaComponent from "../../../temp/OtazkaComponent";
import QuestionPageWrapper from "../../../temp/QuestionPageWrapper";

export async function generateStaticParams() {
const res = await fetch(
"https://www.volebnikalkulacka.cz/data/instance/volebnikalkulacka.cz/krajske-2024/10-jihomoravsky/questions.json",
);
const data = await res.json();

return data.map((_, index) => ({
index: index.toString(),
}));
}

async function getQuestion(index) {
const res = await fetch(
"https://www.volebnikalkulacka.cz/data/instance/volebnikalkulacka.cz/krajske-2024/10-jihomoravsky/questions.json",
);
const data = await res.json();
return data[index];
}

async function getQuestionsLength() {
const res = await fetch(
"https://www.volebnikalkulacka.cz/data/instance/volebnikalkulacka.cz/krajske-2024/10-jihomoravsky/questions.json",
);
const data = await res.json();
return data.length;
}

export default async function Page({ params }) {
const question = await getQuestion(params.index);
const questionLength = await getQuestionsLength();
console.log(questionLength);
return (
<div>
{/* <OtazkaComponent
key={question.id}
statement={question.statement}
detail={question.detail}
/> */}
<QuestionPageWrapper
questions={question}
currentQuestion={params.index}
questionCount={questionLength}
/>
</div>
);
}
42 changes: 42 additions & 0 deletions apps/web/app/[lang]/otazky/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import type { Question } from "@repo/schema/dist";
import OtazkaComponent from "../../temp/OtazkaComponent";
import QuestionPageWrapper from "../../temp/QuestionPageWrapper";
import {
ClientBottomBar,
ClientQuestionWrapper,
} from "../../temp/ClientWrapper";

type Props = {
params: { otazkaId: string };
};

async function getData() {
const res = await fetch(
"https://www.volebnikalkulacka.cz/data/instance/volebnikalkulacka.cz/krajske-2024/10-jihomoravsky/questions.json",
);
const data = await res.json();
return data;
}
export default async function Page({ params }: Props) {
const questions = await getData();
return (
<>
<span>Next redirect here</span>
{/* <span>Questions length: {questions.length}</span>
{questions.length > 0 &&
questions.map((question: Question, index: number) => {
const currentQuestion = index + 1;
return (
<ClientQuestionWrapper
key={`Question: ${question.id}`}
currentQuestion={currentQuestion}
questionCount={questions.length}
question={question}
/>
);
})}
<ClientBottomBar steps={steps} /> */}
{/* <QuestionPageWrapper questions={questions} /> */}
</>
);
}
Loading
Loading