-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: fixing flow redirections and components visibility
- Loading branch information
Showing
5 changed files
with
149 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// use middleware for redirection | ||
"use client"; | ||
import { usePathname, useRouter } from "next/navigation"; | ||
import { useEffect } from "react"; | ||
export default function Page() { | ||
const path = usePathname(); | ||
const router = useRouter(); | ||
console.log(typeof path); | ||
useEffect(() => { | ||
console.log("Use effect"); | ||
if (path === "/xyz/navod") { | ||
router.push("/xyz/navod/1"); | ||
} | ||
}, []); | ||
|
||
return <h1>Redirect to guide</h1>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
"use client"; | ||
import { useQuestionsStore } from "./store"; | ||
import { QuestionWrapper, BottomBar } from "@repo/design-system/ui"; | ||
import type { ExtendedQuestions } from "./store"; | ||
import { useRouter } from "next/navigation"; | ||
import { useEffect } from "react"; | ||
|
||
export default function Page() { | ||
// cleanup and better naming | ||
// const testQuestions = useQuestionsStore((state) => state.testQuestions); | ||
const questions = useQuestionsStore((state) => state.questions); | ||
const currentQuestion = useQuestionsStore((state) => state.currentQuestion); | ||
const questionTotal = useQuestionsStore((state) => state.questionTotal); | ||
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); | ||
const router = useRouter(); | ||
|
||
// understand this approach more! | ||
// useEffect(() => { | ||
// if (currentQuestion) { | ||
// const slug = `/xyz/${currentQuestion}`; | ||
// if (window.location.pathname !== slug) { | ||
// window.history.replaceState(null, "", slug); | ||
// } | ||
// } | ||
// }, [currentQuestion]); | ||
|
||
const prevClick = () => { | ||
if (currentQuestion === 1) { | ||
router.push("/xyz/navod"); | ||
} else { | ||
prevQuestion(); | ||
} | ||
}; | ||
|
||
const skipClick = () => { | ||
if (currentQuestion === questions.length) { | ||
router.push("/xyz/rekapitulace"); | ||
} else { | ||
skipQuestion(); | ||
} | ||
}; | ||
|
||
const yesClick = () => { | ||
answerYes(); | ||
skipQuestion(); | ||
}; | ||
|
||
const noClick = () => { | ||
answerNo(); | ||
skipQuestion(); | ||
}; | ||
|
||
return ( | ||
<div> | ||
{/* questions wrapper */} | ||
{questions.map((question: ExtendedQuestions, index) => { | ||
const currentStep = index + 1; | ||
if (currentStep === currentQuestion) { | ||
return ( | ||
<QuestionWrapper | ||
key={`Question card id:${question.id}`} | ||
question={question} | ||
currentQuestion={currentQuestion} | ||
questionCount={questions.length} | ||
skipQuestion={skipClick} | ||
prevQuestion={prevClick} | ||
/> | ||
); | ||
} | ||
})} | ||
{/* Bottom bar wrapper */} | ||
{questions.map((question: ExtendedQuestions, index) => { | ||
const currentStep = index + 1; | ||
if (currentStep === currentQuestion) { | ||
return ( | ||
<BottomBar | ||
key={`Bottom bar id:${question.id}`} | ||
questions={questions} | ||
currentQuestion={currentQuestion} | ||
questionTotal={questionTotal} | ||
toggleImportant={toggleImportant} | ||
yesClick={yesClick} | ||
noClick={noClick} | ||
starPressed={question.isImportant ? true : undefined} | ||
/> | ||
); | ||
} | ||
})} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,95 +1,17 @@ | ||
// use middleware for redirection | ||
"use client"; | ||
import { useQuestionsStore } from "./store"; | ||
import { QuestionWrapper, BottomBar } from "@repo/design-system/ui"; | ||
import type { ExtendedQuestions } from "./store"; | ||
import { useRouter } from "next/navigation"; | ||
import { usePathname, useRouter } from "next/navigation"; | ||
import { useEffect } from "react"; | ||
|
||
export default function Page() { | ||
// cleanup and better naming | ||
// const testQuestions = useQuestionsStore((state) => state.testQuestions); | ||
const questions = useQuestionsStore((state) => state.questions); | ||
const currentQuestion = useQuestionsStore((state) => state.currentQuestion); | ||
const questionTotal = useQuestionsStore((state) => state.questionTotal); | ||
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); | ||
const path = usePathname(); | ||
const router = useRouter(); | ||
|
||
// understand this approach more! | ||
// useEffect(() => { | ||
// if (currentQuestion) { | ||
// const slug = `/xyz/${currentQuestion}`; | ||
// if (window.location.pathname !== slug) { | ||
// window.history.replaceState(null, "", slug); | ||
// } | ||
// } | ||
// }, [currentQuestion]); | ||
|
||
const prevClick = () => { | ||
if (currentQuestion === 1) { | ||
router.push("/xyz/navod"); | ||
} else { | ||
prevQuestion(); | ||
console.log(typeof path); | ||
useEffect(() => { | ||
console.log("Use effect"); | ||
if (path === "/xyz") { | ||
router.push("/xyz/1"); | ||
} | ||
}; | ||
|
||
const skipClick = () => { | ||
if (currentQuestion === questions.length) { | ||
router.push("/xyz/rekapitulace"); | ||
} else { | ||
skipQuestion(); | ||
} | ||
}; | ||
|
||
const yesClick = () => { | ||
answerYes(); | ||
skipQuestion(); | ||
}; | ||
|
||
const noClick = () => { | ||
answerNo(); | ||
skipQuestion(); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<div> | ||
{/* questions wrapper */} | ||
{questions.map((question: ExtendedQuestions, index) => { | ||
const currentStep = index + 1; | ||
if (currentStep === currentQuestion) { | ||
return ( | ||
<QuestionWrapper | ||
key={`Question card id:${question.id}`} | ||
question={question} | ||
currentQuestion={currentQuestion} | ||
questionCount={questions.length} | ||
skipQuestion={skipClick} | ||
prevQuestion={prevClick} | ||
/> | ||
); | ||
} | ||
})} | ||
{/* Bottom bar wrapper */} | ||
{questions.map((question: ExtendedQuestions, index) => { | ||
const currentStep = index + 1; | ||
if (currentStep === currentQuestion) { | ||
return ( | ||
<BottomBar | ||
key={`Bottom bar id:${question.id}`} | ||
questions={questions} | ||
currentQuestion={currentQuestion} | ||
questionTotal={questionTotal} | ||
toggleImportant={toggleImportant} | ||
yesClick={yesClick} | ||
noClick={noClick} | ||
starPressed={question.isImportant ? true : undefined} | ||
/> | ||
); | ||
} | ||
})} | ||
</div> | ||
); | ||
return <h1>Redirect to first question</h1>; | ||
} |