From 9192e6c7747fd2d3f6a6c5c07d886a0982b53f11 Mon Sep 17 00:00:00 2001 From: polwex Date: Wed, 21 May 2025 15:28:03 +0700 Subject: good tandem good tandem of ideas and implementation --- src/components/Flashcard/ServerCard.tsx | 345 ++++++++++++++++++++++++++++++++ 1 file changed, 345 insertions(+) create mode 100644 src/components/Flashcard/ServerCard.tsx (limited to 'src/components/Flashcard/ServerCard.tsx') diff --git a/src/components/Flashcard/ServerCard.tsx b/src/components/Flashcard/ServerCard.tsx new file mode 100644 index 0000000..75442b4 --- /dev/null +++ b/src/components/Flashcard/ServerCard.tsx @@ -0,0 +1,345 @@ +// This is a Server Component +import React, { Suspense, useTransition } from "react"; +import { NLP } from "sortug-ai"; +import { + BookOpen, + Volume2, + Link as LinkIcon, + ChevronDown, + ChevronUp, + Search, + Info, + MessageSquareQuote, + Tags, + ListTree, + Lightbulb, + BookmarkIcon, +} from "lucide-react"; +import { + Example, + SubSense, + RelatedEntry, + Sense, + WordData, +} from "@/zoom/logic/types"; +import { CardResponse } from "@/lib/types/cards"; +import { thaiData } from "@/pages/api/nlp"; +import { getRandomHexColor } from "@/lib/utils"; + +export async function CardFront({ data }: { data: CardResponse }) { + // const extraData = data.expression.lang + const extraData = await thaiData(data.expression.spelling); + console.log({ extraData }); + + return ( +
+ + {data.expression.spelling} +

+ } + > +

+ {extraData[0]?.syllables.map((syl) => ( + + {syl} + + ))} +

+
+ +
+ ); +} + +// Helper component for IPA display +export const IpaDisplay = ({ + ipaEntries, +}: { + ipaEntries: Array<{ ipa: string; tags?: string[] }>; +}) => { + if (!ipaEntries || ipaEntries.length === 0) return null; + return ( +
+ {ipaEntries.map((entry, index) => { + const tags = entry.tags ? entry.tags : []; + return ( + + {entry.ipa}{" "} + {tags.length > 0 && ( + ({tags.join(", ")}) + )} + + ); + })} + +
+ ); +}; + +export async function CardBack({ data }: { data: CardResponse }) { + // + return ( +
+ + + {data.expression.senses.map((ss, i) => ( +
+ {ss.senses.map((sss, i) => ( +
+ {sss.glosses.map((ssss, i) => ( +

{ssss}

+ ))} +
+ ))} +
+ ))} +
+

+ {data.note} +

+
+ ); +} + +// Component for displaying examples +const ExampleDisplay = ({ examples }: { examples: Example[] }) => { + if (!examples || examples.length === 0) return null; + return ( +
+
+ + Examples: +
+
    + {examples.map((ex, idx) => ( +
  • + "{ex.text}" + {ex.ref && ( + ({ex.ref}) + )} + {ex.type !== "quote" && ( + + {ex.type} + + )} +
  • + ))} +
+
+ ); +}; + +// Component for displaying related terms (synonyms, antonyms, etc.) +const RelatedTermsDisplay = ({ + terms, + type, +}: { + terms: RelatedEntry[] | undefined; + type: string; +}) => { + if (!terms || terms.length === 0) return null; + return ( +
+ + {type}:{" "} + + {terms.map((term, idx) => ( + + + {term.word} + + {/*term.source && ( + ({term.source}) + )*/} + {idx < terms.length - 1 && ", "} + + ))} +
+ ); +}; + +// Component for displaying a SubSense +const SubSenseDisplay = ({ + subSense, + subSenseNumber, +}: { + subSense: SubSense; + subSenseNumber: number; +}) => { + return ( +
+ {subSense.glosses.map((gloss, glossIdx) => ( +

+ + {subSenseNumber}.{glossIdx + 1} + {" "} + {gloss} +

+ ))} + {subSense.raw_glosses && + subSense.raw_glosses.length > 0 && + subSense.raw_glosses.join("") !== subSense.glosses.join("") && ( +

+ (Raw: {subSense.raw_glosses.join("; ")}) +

+ )} + + {subSense.categories && subSense.categories.length > 0 && ( +
+
+ + Categories: +
+
+ {subSense.categories.map((cat, idx) => ( + + {cat} + + ))} +
+
+ )} + + + + + {subSense.tags && subSense.tags.length > 0 && ( +
+
+ + Tags: +
+
+ {subSense.tags.map((tag, idx) => ( + + {tag} + + ))} +
+
+ )} + + {subSense.links && subSense.links.length > 0 && ( +
+ {subSense.links.map(([type, target], linkIdx) => ( + + {type} + + ))} +
+ )} +
+ ); +}; + +// Component for individual sense +const SenseCard = ({ + senseData, + senseNumber, +}: { + senseData: Sense; + senseNumber: number; +}) => { + return ( +
+
+

+ {senseNumber}. {NLP.unpackPos(senseData.pos)} +

+
+ + {senseData.etymology && ( +
+ + Etymology + + + +

+ {senseData.etymology} +

+
+ )} + + {senseData.forms && senseData.forms.length > 0 && ( +
+

Forms:

+
+ {senseData.forms.map((form, idx) => ( + + {form.form}{" "} + {form.tags.length > 0 && `(${form.tags.join(", ")})`} + + ))} +
+
+ )} + + {senseData.senses.map((subSense, idx) => ( + + ))} + + {senseData.related && ( +
+

+ + Related Terms: +

+ + + + +
+ )} +
+ ); +}; -- cgit v1.2.3