summaryrefslogtreecommitdiff
path: root/src/pages
diff options
context:
space:
mode:
authorpolwex <polwex@sortug.com>2025-05-21 15:28:03 +0700
committerpolwex <polwex@sortug.com>2025-05-21 15:28:03 +0700
commit9192e6c7747fd2d3f6a6c5c07d886a0982b53f11 (patch)
treec94a60a26732b697fa6734bff0fe898d690d2fd4 /src/pages
parente839a5f61f0faa21ca8b4bd5767f7575d5e576ee (diff)
good tandem good tandem of ideas and implementation
Diffstat (limited to 'src/pages')
-rw-r--r--src/pages/api/nlp.ts38
-rw-r--r--src/pages/lesson/[slug].tsx9
2 files changed, 46 insertions, 1 deletions
diff --git a/src/pages/api/nlp.ts b/src/pages/api/nlp.ts
index 0e5eacb..27c330d 100644
--- a/src/pages/api/nlp.ts
+++ b/src/pages/api/nlp.ts
@@ -30,3 +30,41 @@ export const POST = async (request: Request): Promise<Response> => {
return Response.json({ message: "Failure" }, { status: 500 });
}
};
+
+type AnalyzeRes = {
+ word: string;
+ syllables: string[];
+ ipa: string;
+ pos: string;
+};
+
+export async function thaiData(word: string): Promise<AnalyzeRes[]> {
+ const [head, tail] = await Promise.all([
+ analyzeTHWord(word),
+ segmentateThai(word),
+ ]);
+ return [head, ...tail];
+}
+
+export async function analyzeTHWord(word: string): Promise<AnalyzeRes> {
+ const opts = {
+ method: "POST",
+ headers: { "Content-type": "application/json" },
+ body: JSON.stringify({ word }),
+ };
+ const r1 = await fetch("http://localhost:8001" + "/analyze", opts);
+ // const r2 = await fetch(`http://192.168.1.110:8000/analyze`, opts);
+ const jj = await r1.json();
+ return jj;
+}
+export async function segmentateThai(sentence: string): Promise<AnalyzeRes[]> {
+ const opts = {
+ method: "POST",
+ headers: { "Content-type": "application/json" },
+ body: JSON.stringify({ word: sentence }),
+ };
+ // const r1 = await fetch(`http://localhost:8000/segmentate`, opts);
+ const r2 = await fetch("http://localhost:8001" + `/segmentate`, opts);
+ const jj = await r2.json();
+ return jj;
+}
diff --git a/src/pages/lesson/[slug].tsx b/src/pages/lesson/[slug].tsx
index 6632838..9e6e6cc 100644
--- a/src/pages/lesson/[slug].tsx
+++ b/src/pages/lesson/[slug].tsx
@@ -8,6 +8,8 @@ import type { PageProps } from "waku/router";
import db from "@/lib/db";
import { useCookies } from "@/lib/server/cookiebridge";
import Deck from "@/components/Flashcard/Deck";
+import Deck2 from "@/components/Flashcard/Deck2";
+import { CardFront, CardBack } from "@/components/Flashcard/ServerCard";
const flags: Record<string, string> = {
th: "🇹🇭",
@@ -34,12 +36,17 @@ export default async function HomePage(props: PageProps<"/lesson/[slug]">) {
const data = await getData(Number(props.slug), user.id);
if ("error" in data) return <p>Error</p>;
// console.log({ data });
+ const cardComponents = data.ok.cards.map((card) => ({
+ id: card.id,
+ front: <CardFront data={card} />,
+ back: <CardBack data={card} />,
+ }));
return (
<>
<section>
<h2 className="text-lg">Thai!</h2>
- <Deck data={data.ok} />
+ <Deck2 data={data.ok} cards={cardComponents} />
</section>
</>
);