From ba2dbc660c229d3e86662d35513dfa7c904d9870 Mon Sep 17 00:00:00 2001 From: polwex Date: Sun, 23 Nov 2025 13:29:28 +0700 Subject: wew --- packages/prosody-ui/src/LangText.tsx | 80 ++++++++++++++++++++++++++++++++---- 1 file changed, 72 insertions(+), 8 deletions(-) (limited to 'packages/prosody-ui/src/LangText.tsx') diff --git a/packages/prosody-ui/src/LangText.tsx b/packages/prosody-ui/src/LangText.tsx index 790c499..ab9d4f4 100644 --- a/packages/prosody-ui/src/LangText.tsx +++ b/packages/prosody-ui/src/LangText.tsx @@ -2,27 +2,31 @@ import { franc } from "franc-all"; import React, { useEffect, useState } from "react"; import ThaiText from "./thai/ThaiText"; import { ColoredText } from "./components/Sentence"; -import type { AnalyzeRes, WordData } from "./logic/types"; +import type { AnalyzeRes, ColorTheme, WordData } from "./logic/types"; import { detectScript, scriptFromLang } from "./logic/utils"; import LatinText from "./latin/LatinText"; import { buildWiktionaryURL, parseWiktionary } from "./logic/wiki"; -import type { Result } from "sortug"; +import FullWord from "./components/word/FullWordData"; +import type { AsyncRes, Result } from "@sortug/lib"; +import type { FullWordData } from "@sortug/langlib"; export default function LangText({ text, lang, theme, - fetchWiki, handleWord, + handleError, }: { text: string; + theme?: ColorTheme; lang?: string; - theme?: string; - fetchWiki?: (url: string) => Promise; - handleWord?: (wd: Result) => any; + handleWord?: (word: AnalyzeRes) => any; + handleError?: (error: string) => any; }) { + const background: ColorTheme = theme ? theme : "light"; const [llang, setLang] = useState(""); const [script, setScript] = useState(scriptFromLang(lang || "", text)); + const [modal, setWordModal] = useState(null); useEffect(() => { if (!lang) { const res = franc(text); @@ -31,7 +35,27 @@ export default function LangText({ }, [text]); console.log("langtext", { text, llang, script }); - async function openWord(word: string) { + async function openWord(word: AnalyzeRes) { + if (handleWord) handleWord(word); + else { + const body = JSON.stringify({ + getWordFull: { spelling: word.word, lang: llang }, + }); + const opts = { + method: "POST", + body, + headers: { "Content-type": "application/json" }, + }; + const res = await fetch("/api/db", opts); + const j = (await res.json()) as Result; + console.log({ j }); + if ("error" in j) { + if (handleError) handleError(j.error); + else console.error("error opening word", j.error); + } else { + setWordModal(j.ok); + } + } // console.log("looking up", word); // const url = buildWiktionaryURL(word); // const html = await fetchWiki(url); @@ -56,12 +80,20 @@ export default function LangText({ return (
{script === "Thai" ? ( - + ) : script === "Latin" ? ( ) : ( )} + {modal && ( + setWordModal(null)} + /> + )}
); } @@ -76,3 +108,35 @@ function Generic({ text, lang }: { text: string; lang: string }) { // {data && } return
; } + +function WordModal({ + word, + lang, + theme, + onClose, +}: { + word: FullWordData; + lang: string; + theme: ColorTheme; + onClose: () => void; +}) { + return ( + + ); +} -- cgit v1.2.3