Skip to content

Commit

Permalink
fix: meaning/reading hints (closes #22)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lemmmy committed May 5, 2024
1 parent 0018e99 commit 29ab85f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 10 additions & 2 deletions src/pages/subject/SubjectInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,11 @@ export function SubjectInfo(props: SubjectInfoProps): JSX.Element {
</SubjectMarkup>

{/* Kanji meaning hint */}
{objectType === "kanji" && <SubjectInfoHint data={kanjiSubjectData} header="Meaning hint" />}
{objectType === "kanji" && <SubjectInfoHint header="Reading hint">
{kanjiSubjectData.meaning_hint && <SubjectMarkup>
{kanjiSubjectData.meaning_hint}
</SubjectMarkup>}
</SubjectInfoHint>}

{/* Study material meaning notes */}
<StudyMaterialNote
Expand All @@ -202,7 +206,11 @@ export function SubjectInfo(props: SubjectInfoProps): JSX.Element {
</SubjectMarkup>

{/* Kanji reading hint */}
{objectType === "kanji" && <SubjectInfoHint data={kanjiSubjectData} header="Reading hint" />}
{objectType === "kanji" && <SubjectInfoHint header="Reading hint">
{kanjiSubjectData.reading_hint && <SubjectMarkup>
{kanjiSubjectData.reading_hint}
</SubjectMarkup>}
</SubjectInfoHint>}

{/* Study material reading notes */}
<StudyMaterialNote
Expand Down
12 changes: 2 additions & 10 deletions src/pages/subject/SubjectInfoHint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,24 @@
import { ReactNode } from "react";
import classNames from "classnames";

import { ApiSubjectKanjiInner } from "@api";
import { SubjectMarkup } from "@comp/subjects/SubjectMarkup.tsx";

interface Props {
header: ReactNode;
data?: ApiSubjectKanjiInner;
children?: ReactNode;
className?: string;
}

export function SubjectInfoHint({
header,
data,
children,
className
}: Props): JSX.Element | null {
const hasData = data?.meaning_hint || children;
if (!hasData) return null;
if (!children) return null;

return <div className={classNames("mt-lg p-md bg-container rounded", className)}>
<h4 className="mt-0 mb-xs text-desc text-sm font-bold uppercase">
{header}
</h4>

{children || (data?.meaning_hint && <SubjectMarkup>
{data.meaning_hint}
</SubjectMarkup>)}
{children}
</div>;
}

0 comments on commit 29ab85f

Please sign in to comment.