Skip to content

Commit

Permalink
refactor: simplify URL and state management logic in UrlUpdater compo…
Browse files Browse the repository at this point in the history
…nent
  • Loading branch information
mewdev committed Jan 20, 2025
1 parent a73c498 commit ad03d2a
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions apps/web/app/abc/utils/urlUpdater.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ type Props = {

export default function UrlUpdater({ children }: Props) {
const path = usePathname();
const router = useRouter();
const currentQuestion = useQuestionsStore((state) => state.currentQuestion);
const rekapitulace = useQuestionsStore((state) => state.isRekapitulace);
const setIsRekapitulace = useQuestionsStore(
Expand All @@ -23,21 +22,13 @@ export default function UrlUpdater({ children }: Props) {

// Location setter
useEffect(() => {
if (
path.includes("rekapitulace") &&
rekapitulace !== true &&
currentLocation !== "rekapitulace"
) {
if (path.includes("rekapitulace")) {
setIsRekapitulace(true);
setCurrentLocation("rekapitulace");
} else if (
path.includes("otazka") &&
rekapitulace !== false &&
currentLocation !== "otazka"
) {
} else if (path.includes("otazka")) {
setIsRekapitulace(false);
setCurrentLocation("otazka");
} else if (path.includes("navod") && currentLocation !== "navod") {
} else if (path.includes("navod")) {
setCurrentLocation("navod");
}
}, [path]);
Expand All @@ -52,9 +43,6 @@ export default function UrlUpdater({ children }: Props) {
} else if (currentLocation === "navod") {
// refactor url structure
history.replaceState({}, "", `/abc/navod/${guideNumber}`);
// edge case if currentLocation null or undefined
} else if (currentLocation === undefined || currentLocation === null) {
router.push("/");
}
}
function changeTitle() {
Expand All @@ -64,9 +52,6 @@ export default function UrlUpdater({ children }: Props) {
} else if (currentLocation === "navod") {
// refactor title structure
document.title = `Návod ${guideNumber}`;
} else {
// default title
document.title;
}
}
changeTitle();
Expand Down

0 comments on commit ad03d2a

Please sign in to comment.