Skip to content

Commit

Permalink
feat(basic): hide answer area when there are not answer and note
Browse files Browse the repository at this point in the history
  • Loading branch information
ikkz committed Nov 25, 2024
1 parent 16f59c0 commit 4cbeea5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/calm-rocks-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'anki-templates': patch
---

feat(basic): hide answer area when there are not answer and note (没有答案和备注时隐藏答案区域)
2 changes: 1 addition & 1 deletion src/components/card-shell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export const CardShell: FC<Props> = ({
/>
{questionExtra}
</Block>
{back ? (
{back && answer ? (
<Block name={t('answer')} id={prefNoScroll ? undefined : 'answer'}>
{answer}
</Block>
Expand Down
25 changes: 15 additions & 10 deletions src/entries/basic.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<CardShell
title={t('question')}
answer={
<>
<AnkiField name="answer" className="prose dark:prose-invert" />
{note ? (
<>
<hr className="my-4" />
hasAnswer || hasNote ? (
<>
{hasAnswer ? (
<AnkiField name="answer" className="prose dark:prose-invert" />
) : null}
{hasAnswer && hasNote ? <hr className="my-4" /> : null}
{hasNote ? (
<AnkiField
name="note"
className={clsx('prose prose-sm mt-3', 'dark:prose-invert')}
/>
</>
) : null}
</>
) : null}
</>
) : null
}
/>
);
Expand Down

0 comments on commit 4cbeea5

Please sign in to comment.