Skip to content

Commit

Permalink
wip: implement dynamic question fetching and update URL handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mewdev committed Jan 9, 2025
1 parent 0f3bcea commit 7829734
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
6 changes: 4 additions & 2 deletions apps/web/app/abc/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ import "@repo/design-system/styles";
import "@repo/design-system/themes/theme-default";
import { StoreProvider } from "./providers/storeProvider";
import UrlUpdater from "./utils/urlUpdater";
import getQuestions from "./utils/getQuestions";

const collection = ["Collection 1", "Collection 2", "Collection 3"];
const baseUrl = "https://dummyjson.com/c/7ee4-a7f4-4977-bb54";

const collection = await getQuestions(baseUrl);

export default async function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
console.log(collection);
return (
<html lang="en">
<StoreProvider collection={collection}>
Expand Down
5 changes: 5 additions & 0 deletions apps/web/app/abc/utils/getQuestions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default async function getQuestions(baseUrl: string) {
const res = await fetch(baseUrl);
const data = await res.json();
return data;
}
3 changes: 3 additions & 0 deletions apps/web/app/abc/utils/urlUpdater.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ export default function UrlUpdater({ children }: Props) {
const currentQuestion = useQuestionsStore((state) => state.currentQuestion);

useEffect(() => {
// cleanups ?
// change url
function changeUrl() {
// insert conditionals here for edge cases?
history.replaceState({}, "", `/abc/${currentQuestion}`);
}
// change title
function changeTitle() {
// insert conditionals here for edge cases?
document.title = `Otázka ${currentQuestion}`;
}
changeTitle();
Expand Down

0 comments on commit 7829734

Please sign in to comment.