Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(mcq): add switch for answer in back #53

Merged
merged 1 commit into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tricky-queens-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'anki-templates': patch
---

feat(mcq): add switch for answer in back (添加背面答案开关)
63 changes: 34 additions & 29 deletions src/entries/mcq.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useField } from '../hooks/use-field';
import {
biggerTextAtom,
blurOptionsAtom,
hideMcqAnswerAtom,
hideQuestionTypeAtom,
randomOptionsAtom,
} from '@/store/settings';
Expand Down Expand Up @@ -113,6 +114,8 @@ export default () => {
useAtomValue(blurOptionsAtom),
);

const hideMcqAnswer = useAtomValue(hideMcqAnswerAtom);

return (
<CardShell
title={
Expand Down Expand Up @@ -197,35 +200,37 @@ export default () => {
answer={
<>
{options.length ? (
<div className="text-center text-3xl font-bold italic text-opacity-50">
<span className="align-super">
{selected.length ? (
originOptions.map((name) => {
const selectResult = getSelectResult(name);
if (!['wrong', 'correct'].includes(selectResult)) {
return null;
}
return (
<span
key={name}
className={clsx({
'text-red-400': selectResult === 'wrong',
'text-green-400': selectResult === 'correct',
})}
>
{fieldToAlpha(name)}
</span>
);
})
) : (
<span className="text-amber-400">-</span>
)}
</span>
<span className="text-5xl text-gray-200">/</span>
<span className="align-sub text-green-400">
{answers.map((name) => fieldToAlpha(name))}
</span>
</div>
hideMcqAnswer ? null : (
<div className="text-center text-3xl font-bold italic text-opacity-50">
<span className="align-super">
{selected.length ? (
originOptions.map((name) => {
const selectResult = getSelectResult(name);
if (!['wrong', 'correct'].includes(selectResult)) {
return null;
}
return (
<span
key={name}
className={clsx({
'text-red-400': selectResult === 'wrong',
'text-green-400': selectResult === 'correct',
})}
>
{fieldToAlpha(name)}
</span>
);
})
) : (
<span className="text-amber-400">-</span>
)}
</span>
<span className="text-5xl text-gray-200">/</span>
<span className="align-sub text-green-400">
{answers.map((name) => fieldToAlpha(name))}
</span>
</div>
)
) : (
<>
<AnkiField name="answer" />
Expand Down
7 changes: 7 additions & 0 deletions src/pages/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
biggerTextAtom,
blurOptionsAtom,
hideAboutAtom,
hideMcqAnswerAtom,
hideQuestionTypeAtom,
hideTimerAtom,
noScorllAtom,
Expand Down Expand Up @@ -73,6 +74,7 @@ if (id === 'mcq') {
const [hideQuestionType, setHideQuestionType] =
useAtom(hideQuestionTypeAtom);
const [blurOptions, setBlurOptions] = useAtom(blurOptionsAtom);
const [hideMcqAnswer, setHideMcqAnswer] = useAtom(hideMcqAnswerAtom);

return (
<>
Expand All @@ -94,6 +96,11 @@ if (id === 'mcq') {
checked={blurOptions}
onChange={setBlurOptions}
/>
<Checkbox
title={t.hideMcqAnswer}
checked={hideMcqAnswer}
onChange={setHideMcqAnswer}
/>
<CommonOptions />
</>
);
Expand Down
4 changes: 4 additions & 0 deletions src/store/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ export const blurOptionsAtom = atomWithScopedStorage<boolean>(
'blurOptions',
false,
);
export const hideMcqAnswerAtom = atomWithScopedStorage<boolean>(
'hideMcqAnswer',
false,
);
1 change: 1 addition & 0 deletions translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"noScroll": "Don't auto scroll when flipping",
"blurOptions": "Blur options",
"blurOptionsDetail": "When enabled, options will be blurred and will become clear after clicking on the option area.",
"hideMcqAnswer": "Hide the answers(AC/ABC) on the back",
"yourWrongAnswer": "Your wrong answer",
"help": "Help",
"tool": "Tool",
Expand Down
1 change: 1 addition & 0 deletions translations/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"noScroll": "翻转时不要自动滚动",
"blurOptions": "选项模糊",
"blurOptionsDetail": "开启后选项会被模糊,点击选项区域后恢复",
"hideMcqAnswer": "隐藏背面答案(AC/ABC)显示",
"yourWrongAnswer": "你的错误答案",
"help": "帮助",
"tool": "工具",
Expand Down
Loading