From 461de12f548c553115ba1d2c616fd05bb4eff3b4 Mon Sep 17 00:00:00 2001 From: Louis Mollick Date: Wed, 16 Oct 2024 23:59:02 -0400 Subject: [PATCH] fix: update compound word display --- src/app/_components/mangaPageView.tsx | 4 +- src/app/_components/wordReadingCard.tsx | 120 +++++++++++++++++++++ src/app/_components/wordReadingContent.tsx | 84 --------------- src/types/ichiran.ts | 5 +- 4 files changed, 125 insertions(+), 88 deletions(-) create mode 100644 src/app/_components/wordReadingCard.tsx delete mode 100644 src/app/_components/wordReadingContent.tsx diff --git a/src/app/_components/mangaPageView.tsx b/src/app/_components/mangaPageView.tsx index ce898e5..ad59402 100644 --- a/src/app/_components/mangaPageView.tsx +++ b/src/app/_components/mangaPageView.tsx @@ -18,7 +18,7 @@ import { DrawerTitle, } from "@/app/_components/ui/drawer"; import { Tabs, TabsList, TabsTrigger } from "@/app/_components/ui/tabs"; -import WordReadingContent from "@/app/_components/wordReadingContent"; +import WordReadingCard from "@/app/_components/wordReadingCard"; import useKeyPress from "@/app/_hooks/useKeyPress"; import { cn } from "@/lib/ui/utils"; import { getPageImagePath, getPageNextJsImagePath } from "@/lib/filepath/utils"; @@ -269,7 +269,7 @@ const MangaPageView = ({ {wordReadings ?.filter(({ isPunctuation }) => !isPunctuation) .map((wordReading, idx) => ( - { diff --git a/src/app/_components/wordReadingCard.tsx b/src/app/_components/wordReadingCard.tsx new file mode 100644 index 0000000..901fd42 --- /dev/null +++ b/src/app/_components/wordReadingCard.tsx @@ -0,0 +1,120 @@ +import React, { forwardRef } from "react"; +import type { + WordReadingForRender, + Conj, + Gloss, + WordReading, +} from "@/types/ichiran"; +import { + Card, + CardContent, + CardDescription, + CardHeader, + CardTitle, +} from "@/app/_components/ui/card"; +import { cn } from "@/lib/ui/utils"; + +function WordGloss({ + gloss, + className, + ...props +}: { gloss?: Gloss[] } & React.HTMLAttributes) { + if (!gloss?.length) return; + + return ( +
    + {gloss.map((gloss, glossIdx) => ( +
  1. + {gloss.pos} + {gloss.gloss} +
  2. + ))} +
+ ); +} + +function WordConj({ conj }: { conj?: Conj[] }) { + if (!conj?.length) return; + + return ( +
    + {conj.map((conj, conjIdx) => ( +
  1. + {!!conj.prop?.length && + conj.prop.map((prop, propIdx) => ( +

    + [{prop.pos}] + {prop.type} +

    + ))} + {conj.reading &&

    {conj.reading}

    } + + {conj.via?.length && ( +
    + via + +
    + )} +
  2. + ))} +
+ ); +} + +function WordReadingContent({ + wordReading, + showReading = true, +}: { + wordReading: WordReading; + showReading?: boolean; +}) { + return ( + <> + {showReading &&

{wordReading.reading}

} + {wordReading.compound?.length && ( +

+ Compound word: {wordReading.compound.join(" + ")} +

+ )} + {wordReading.components?.length && ( +
    + {wordReading.components.map((comp, compIdx) => ( + + ))} +
+ )} + {wordReading.suffix && ( +

Suffix: {wordReading.suffix}

+ )} + + + + ); +} + +type Props = { + wordReading: WordReadingForRender; +} & React.HTMLAttributes; + +export default forwardRef(function WordReadingCard( + { wordReading, className, ...props }, + ref, +) { + return ( + + + {wordReading.reading} + {wordReading.romaji && ( + {wordReading.romaji} + )} + + + + + + ); +}); diff --git a/src/app/_components/wordReadingContent.tsx b/src/app/_components/wordReadingContent.tsx deleted file mode 100644 index d9cb2ee..0000000 --- a/src/app/_components/wordReadingContent.tsx +++ /dev/null @@ -1,84 +0,0 @@ -import React, { forwardRef } from "react"; -import type { WordReadingForRender } from "@/types/ichiran"; -import { - Card, - CardContent, - CardDescription, - CardHeader, - CardTitle, -} from "@/app/_components/ui/card"; -import { cn } from "@/lib/ui/utils"; - -type Props = { - wordReading: WordReadingForRender; -} & React.HTMLAttributes; - -export default forwardRef(function WordReadingContent( - { wordReading, className, ...props }, - ref, -) { - return ( - - - {wordReading.reading} - {wordReading.romaji && ( - {wordReading.romaji} - )} - - - {wordReading.components?.length && ( -
    - {wordReading.components.map( - (comp, compIdx) => - !!comp.conj?.length && ( -
      - {comp.conj.map((conj, conjIdx) => ( -
    1. - {conj.reading} - {!!conj.gloss?.length && ( -
        - {conj.gloss.map((gloss, glossIdx) => ( -
      1. {`${ - glossIdx + 1 - }. ${gloss.pos} ${gloss.gloss}`}
      2. - ))} -
      - )} -
    2. - ))} -
    - ), - )} -
- )} - {!!wordReading.conj?.length && ( -
    - {wordReading.conj.map((conj, conjIdx) => ( -
  1. -
    {conj.reading}
    - {!!conj.gloss?.length && ( -
      - {conj.gloss.map((gloss, glossIdx) => ( -
    1. {`${ - glossIdx + 1 - }. ${gloss.pos} ${gloss.gloss}`}
    2. - ))} -
    - )} -
  2. - ))} -
- )} - {!!wordReading.gloss?.length && ( -
    - {wordReading.gloss.map((gloss, idx) => ( -
  1. {`${idx + 1}. ${gloss.pos} ${ - gloss.gloss - }`}
  2. - ))} -
- )} -
-
- ); -}); diff --git a/src/types/ichiran.ts b/src/types/ichiran.ts index 19569de..b4d87e1 100644 --- a/src/types/ichiran.ts +++ b/src/types/ichiran.ts @@ -13,8 +13,8 @@ export type Word = [ export type WordAlternatives = | { - alternative: WordReading[]; - } + alternative: WordReading[]; + } | WordReading; // Raw format we receive fromt Ichiran @@ -49,6 +49,7 @@ export type Conj = { prop: Prop[]; reading: string; gloss?: Gloss[]; + via?: Conj[]; readok: boolean; };