|
@@ -23,6 +23,7 @@ import {
|
|
|
import { useGetDict } from '../apis/dicts';
|
|
import { useGetDict } from '../apis/dicts';
|
|
|
import type { WordResult } from '../apis/words';
|
|
import type { WordResult } from '../apis/words';
|
|
|
import { useUpdateWord } from '../apis/words';
|
|
import { useUpdateWord } from '../apis/words';
|
|
|
|
|
+import { useCreateMemo } from '../apis/memos';
|
|
|
import styles from './MemoPage.module.css';
|
|
import styles from './MemoPage.module.css';
|
|
|
|
|
|
|
|
const { Text } = Typography;
|
|
const { Text } = Typography;
|
|
@@ -38,6 +39,7 @@ const MemoPage: React.FC = () => {
|
|
|
const [index, setIndex] = useState(0);
|
|
const [index, setIndex] = useState(0);
|
|
|
const [showValueOrMeaning, setShowValueOrMeaning] = useState(false);
|
|
const [showValueOrMeaning, setShowValueOrMeaning] = useState(false);
|
|
|
const [showExtra, setShowExtra] = useState(false);
|
|
const [showExtra, setShowExtra] = useState(false);
|
|
|
|
|
+ const [memoIndex, setMemoIndex] = useState(0);
|
|
|
|
|
|
|
|
const { dictID = '' } = useParams();
|
|
const { dictID = '' } = useParams();
|
|
|
|
|
|
|
@@ -45,6 +47,7 @@ const MemoPage: React.FC = () => {
|
|
|
id: parseInt(dictID),
|
|
id: parseInt(dictID),
|
|
|
});
|
|
});
|
|
|
const updateWord = useUpdateWord();
|
|
const updateWord = useUpdateWord();
|
|
|
|
|
+ const createMemo = useCreateMemo();
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
if (words?.list) {
|
|
if (words?.list) {
|
|
@@ -52,22 +55,34 @@ const MemoPage: React.FC = () => {
|
|
|
}
|
|
}
|
|
|
}, [words?.list]);
|
|
}, [words?.list]);
|
|
|
|
|
|
|
|
- const mutateWordsList = (word: WordResult) => {
|
|
|
|
|
|
|
+ const mutateWordsList = (newWord: WordResult) => {
|
|
|
if (shuffledWords) {
|
|
if (shuffledWords) {
|
|
|
setShuffledWords([
|
|
setShuffledWords([
|
|
|
...shuffledWords.slice(0, index),
|
|
...shuffledWords.slice(0, index),
|
|
|
- word,
|
|
|
|
|
|
|
+ newWord,
|
|
|
...shuffledWords.slice(index + 1),
|
|
...shuffledWords.slice(index + 1),
|
|
|
]);
|
|
]);
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- const mutateIndex = (index: number) => {
|
|
|
|
|
- setIndex(index);
|
|
|
|
|
|
|
+ const mutateIndex = (newIndex: number) => {
|
|
|
|
|
+ setIndex(newIndex);
|
|
|
setShowValueOrMeaning(false);
|
|
setShowValueOrMeaning(false);
|
|
|
setShowExtra(false);
|
|
setShowExtra(false);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+ const mutateMemoIndex = (newIndex: number) => {
|
|
|
|
|
+ if (shuffledWords && index === memoIndex) {
|
|
|
|
|
+ setMemoIndex(newIndex);
|
|
|
|
|
+ const newWord = {
|
|
|
|
|
+ ...shuffledWords[index],
|
|
|
|
|
+ memosCount: shuffledWords[index].memosCount + 1,
|
|
|
|
|
+ };
|
|
|
|
|
+ mutateWordsList(newWord);
|
|
|
|
|
+ void createMemo({ wordID: shuffledWords[index].id });
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
return (
|
|
return (
|
|
|
<div className={styles.wrapper}>
|
|
<div className={styles.wrapper}>
|
|
|
<Space className={styles.space} size="large" direction="vertical">
|
|
<Space className={styles.space} size="large" direction="vertical">
|
|
@@ -178,6 +193,13 @@ const MemoPage: React.FC = () => {
|
|
|
</Button>
|
|
</Button>
|
|
|
</Col>
|
|
</Col>
|
|
|
</Row>
|
|
</Row>
|
|
|
|
|
+ <Row justify="center">
|
|
|
|
|
+ <Col>
|
|
|
|
|
+ <Text type="secondary">
|
|
|
|
|
+ 该单词已复习 {shuffledWords[index].memosCount} 次
|
|
|
|
|
+ </Text>
|
|
|
|
|
+ </Col>
|
|
|
|
|
+ </Row>
|
|
|
<Row align="middle">
|
|
<Row align="middle">
|
|
|
<Col flex="1">
|
|
<Col flex="1">
|
|
|
<Button
|
|
<Button
|
|
@@ -200,12 +222,19 @@ const MemoPage: React.FC = () => {
|
|
|
onClick={() => {
|
|
onClick={() => {
|
|
|
setShuffledWords(_.shuffle(shuffledWords));
|
|
setShuffledWords(_.shuffle(shuffledWords));
|
|
|
mutateIndex(0);
|
|
mutateIndex(0);
|
|
|
|
|
+ mutateMemoIndex(0);
|
|
|
}}
|
|
}}
|
|
|
>
|
|
>
|
|
|
再来一次 <ReloadOutlined />
|
|
再来一次 <ReloadOutlined />
|
|
|
</Button>
|
|
</Button>
|
|
|
) : (
|
|
) : (
|
|
|
- <Button type="link" onClick={() => mutateIndex(index + 1)}>
|
|
|
|
|
|
|
+ <Button
|
|
|
|
|
+ type="link"
|
|
|
|
|
+ onClick={() => {
|
|
|
|
|
+ mutateIndex(index + 1);
|
|
|
|
|
+ mutateMemoIndex(index + 1);
|
|
|
|
|
+ }}
|
|
|
|
|
+ >
|
|
|
下一个 <ArrowRightOutlined />
|
|
下一个 <ArrowRightOutlined />
|
|
|
</Button>
|
|
</Button>
|
|
|
)}
|
|
)}
|