Skip to content

Commit

Permalink
wip: optimize URL and title update logic in UrlUpdater component
Browse files Browse the repository at this point in the history
  • Loading branch information
mewdev committed Jan 19, 2025
1 parent 2ecfdbd commit 93a58f6
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions apps/web/app/abc/utils/urlUpdater.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ export default function UrlUpdater({ children }: Props) {
const guideNumber = useQuestionsStore((state) => state.guideNumber);
const currentLocation = useQuestionsStore((state) => state.currentLocation);

console.log(path);

// location setter
// is slow, make a better approach?
useEffect(() => {
Expand All @@ -33,11 +31,9 @@ export default function UrlUpdater({ children }: Props) {
} else if (path.includes("navod")) {
setCurrentLocation("navod");
}
}, []);
}, [path]);

useEffect(() => {
// !!! implement cleanups!
// change url
function changeUrl() {
// insert conditionals here for edge cases?
if (currentLocation === "otazka") {
Expand All @@ -46,6 +42,10 @@ export default function UrlUpdater({ children }: Props) {
history.replaceState({}, "", `/abc/navod/${guideNumber}`);
}
}
changeUrl();
}, [currentQuestion, guideNumber]);

useEffect(() => {
// change title
function changeTitle() {
if (currentLocation === "otazka") {
Expand All @@ -55,8 +55,7 @@ export default function UrlUpdater({ children }: Props) {
}
}
changeTitle();
changeUrl();
}, [currentQuestion, guideNumber]);
}, [currentLocation]);

return children;
}

0 comments on commit 93a58f6

Please sign in to comment.