From 4cbeea59437978dbfbe2d56067a583b36761842d Mon Sep 17 00:00:00 2001 From: ikkz Date: Mon, 25 Nov 2024 21:30:51 +0800 Subject: [PATCH] feat(basic): hide answer area when there are not answer and note --- .changeset/calm-rocks-jump.md | 5 +++++ src/components/card-shell.tsx | 2 +- src/entries/basic.tsx | 25 +++++++++++++++---------- 3 files changed, 21 insertions(+), 11 deletions(-) create mode 100644 .changeset/calm-rocks-jump.md diff --git a/.changeset/calm-rocks-jump.md b/.changeset/calm-rocks-jump.md new file mode 100644 index 0000000..6ef88c7 --- /dev/null +++ b/.changeset/calm-rocks-jump.md @@ -0,0 +1,5 @@ +--- +'anki-templates': patch +--- + +feat(basic): hide answer area when there are not answer and note (没有答案和备注时隐藏答案区域) diff --git a/src/components/card-shell.tsx b/src/components/card-shell.tsx index fd2331a..e987643 100644 --- a/src/components/card-shell.tsx +++ b/src/components/card-shell.tsx @@ -103,7 +103,7 @@ export const CardShell: FC = ({ /> {questionExtra} - {back ? ( + {back && answer ? ( {answer} diff --git a/src/entries/basic.tsx b/src/entries/basic.tsx index 2f862c6..49ff3aa 100644 --- a/src/entries/basic.tsx +++ b/src/entries/basic.tsx @@ -1,27 +1,32 @@ import { AnkiField } from '@/components/field'; import { CardShell } from '../components/card-shell'; import { t } from '@/utils/locale'; -import { useField } from '@/hooks/use-field'; import clsx from 'clsx'; +import { isFieldEmpty } from '@/utils/field'; +import { FIELD_ID } from '@/utils/const'; export default () => { - const note = useField('note'); + const hasNote = !isFieldEmpty(FIELD_ID('note')); + const hasAnswer = !isFieldEmpty(FIELD_ID('answer')); + return ( - - {note ? ( - <> -
+ hasAnswer || hasNote ? ( + <> + {hasAnswer ? ( + + ) : null} + {hasAnswer && hasNote ?
: null} + {hasNote ? ( - - ) : null} - + ) : null} + + ) : null } /> );