diff options
author | polwex <polwex@sortug.com> | 2025-08-16 15:50:10 +0700 |
---|---|---|
committer | polwex <polwex@sortug.com> | 2025-08-16 15:50:10 +0700 |
commit | 7f2cdbe5da583010466d725197137f503e1fb771 (patch) | |
tree | 09e10e50aed0fe3fc11139163fbca165fb9fe814 /src/pages | |
parent | 274a7bbb1f82e99cdc9876f6d0de430585282797 (diff) |
damn good
Diffstat (limited to 'src/pages')
-rw-r--r-- | src/pages/tones.tsx | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/pages/tones.tsx b/src/pages/tones.tsx index 8658401..20c1237 100644 --- a/src/pages/tones.tsx +++ b/src/pages/tones.tsx @@ -3,18 +3,30 @@ import { Suspense } from "react"; import { fetchWordsByToneAndSyllables } from "@/actions/tones"; import ToneSelectorClient from "@/components/tones/ToneSelectorClient"; import { Skeleton } from "@/components/ui/skeleton"; // For Suspense fallback +import { thaiTones } from "@/lib/types/phonetics"; +import { randomFromArray } from "@/lib/utils"; export const getConfig = async () => { return { render: "static", // Or 'dynamic' if you prefer SSR for every request }; }; +async function randomTones(tries = 0) { + const syllables = Math.floor(Math.random() * 5); + const toneStrings = Object.values(thaiTones); + const tones = Array.from(Array(syllables)).map((_) => + randomFromArray(toneStrings), + ); + console.log({ tones, toneStrings }); + const initialWords = await fetchWordsByToneAndSyllables(tones); + if (!initialWords || initialWords.length === 0) return randomTones(tries + 1); + else return {initialWords, tones}; +} // Function to fetch the initial word on the server async function InitialWordLoader() { // Fetch a random 1-syllable Thai word with any tone initially - const tones = ["falling", "falling"]; - const initialWords = await fetchWordsByToneAndSyllables(tones); + const {initialWords, tones]} = await randomTones(); return <ToneSelectorClient initialData={initialWords} initialTones={tones} />; } |