|
@@ -0,0 +1,173 @@
|
|
|
|
|
+import React, { useState, useEffect } from 'react';
|
|
|
|
|
+import _ from 'lodash';
|
|
|
|
|
+import { Space, Row, Col, Button, Typography, Empty } from 'antd';
|
|
|
|
|
+import {
|
|
|
|
|
+ EyeOutlined,
|
|
|
|
|
+ StarFilled,
|
|
|
|
|
+ StarOutlined,
|
|
|
|
|
+ ArrowLeftOutlined,
|
|
|
|
|
+ PlusOutlined,
|
|
|
|
|
+ ReloadOutlined,
|
|
|
|
|
+ ArrowRightOutlined,
|
|
|
|
|
+} from '@ant-design/icons';
|
|
|
|
|
+import type { Dict } from '../types/dicts';
|
|
|
|
|
+import styles from './MemoPage.module.css';
|
|
|
|
|
+
|
|
|
|
|
+const { Text } = Typography;
|
|
|
|
|
+
|
|
|
|
|
+const dict: Dict = {
|
|
|
|
|
+ valueTitle: '日文',
|
|
|
|
|
+ meaningTitle: '中文',
|
|
|
|
|
+ extraTitle: '假名',
|
|
|
|
|
+ words: [
|
|
|
|
|
+ { value: 'test', meaning: '测试', extra: '附加?', star: true },
|
|
|
|
|
+ { value: 'good', meaning: '好', extra: 'no!', star: false },
|
|
|
|
|
+ ],
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+enum Mode {
|
|
|
|
|
+ ValueToMeaning,
|
|
|
|
|
+ MeaningToValue,
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+const MemoPage: React.FC = () => {
|
|
|
|
|
+ const [mode, setMode] = useState<Mode>(Mode.ValueToMeaning);
|
|
|
|
|
+ const [words, setWords] = useState<Dict['words']>([]);
|
|
|
|
|
+ const [index, setIndex] = useState(0);
|
|
|
|
|
+ const [showValueOrMeaning, setShowValueOrMeaning] = useState(false);
|
|
|
|
|
+ const [showExtra, setShowExtra] = useState(false);
|
|
|
|
|
+
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
|
+ setWords(_.shuffle(dict.words));
|
|
|
|
|
+ }, []);
|
|
|
|
|
+
|
|
|
|
|
+ const updateIndex = (index: number) => {
|
|
|
|
|
+ setIndex(index);
|
|
|
|
|
+ setShowValueOrMeaning(false);
|
|
|
|
|
+ setShowExtra(false);
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ return (
|
|
|
|
|
+ <div className={styles.wrapper}>
|
|
|
|
|
+ <Space className={styles.space} size="large" direction="vertical">
|
|
|
|
|
+ <Row justify="space-around">
|
|
|
|
|
+ <Col>
|
|
|
|
|
+ <Button
|
|
|
|
|
+ type={mode === Mode.ValueToMeaning ? 'primary' : 'default'}
|
|
|
|
|
+ onClick={() => setMode(Mode.ValueToMeaning)}
|
|
|
|
|
+ >
|
|
|
|
|
+ {dict.valueTitle} → {dict.meaningTitle}
|
|
|
|
|
+ </Button>
|
|
|
|
|
+ </Col>
|
|
|
|
|
+ <Col>
|
|
|
|
|
+ <Button
|
|
|
|
|
+ type={mode === Mode.MeaningToValue ? 'primary' : 'default'}
|
|
|
|
|
+ onClick={() => setMode(Mode.MeaningToValue)}
|
|
|
|
|
+ >
|
|
|
|
|
+ {dict.meaningTitle} → {dict.valueTitle}
|
|
|
|
|
+ </Button>
|
|
|
|
|
+ </Col>
|
|
|
|
|
+ </Row>
|
|
|
|
|
+ {words.length ? (
|
|
|
|
|
+ <>
|
|
|
|
|
+ <Row justify="center">
|
|
|
|
|
+ <Col className={styles.primaryText}>
|
|
|
|
|
+ <Text strong>
|
|
|
|
|
+ {mode === Mode.ValueToMeaning
|
|
|
|
|
+ ? words[index].value
|
|
|
|
|
+ : words[index].meaning}
|
|
|
|
|
+ </Text>
|
|
|
|
|
+ </Col>
|
|
|
|
|
+ </Row>
|
|
|
|
|
+ <Row>
|
|
|
|
|
+ <Col className={styles.secondaryText} flex="1">
|
|
|
|
|
+ {showValueOrMeaning ? (
|
|
|
|
|
+ <Text>
|
|
|
|
|
+ {mode === Mode.MeaningToValue
|
|
|
|
|
+ ? words[index].value
|
|
|
|
|
+ : words[index].meaning}
|
|
|
|
|
+ </Text>
|
|
|
|
|
+ ) : (
|
|
|
|
|
+ <Button
|
|
|
|
|
+ type="text"
|
|
|
|
|
+ block
|
|
|
|
|
+ icon={<EyeOutlined />}
|
|
|
|
|
+ onClick={() => setShowValueOrMeaning(true)}
|
|
|
|
|
+ >
|
|
|
|
|
+ {mode === Mode.MeaningToValue
|
|
|
|
|
+ ? dict.valueTitle
|
|
|
|
|
+ : dict.meaningTitle}
|
|
|
|
|
+ </Button>
|
|
|
|
|
+ )}
|
|
|
|
|
+ </Col>
|
|
|
|
|
+ <Col className={styles.secondaryText} flex="1">
|
|
|
|
|
+ {showExtra ? (
|
|
|
|
|
+ <Text>{words[index].extra}</Text>
|
|
|
|
|
+ ) : (
|
|
|
|
|
+ <Button
|
|
|
|
|
+ type="text"
|
|
|
|
|
+ block
|
|
|
|
|
+ icon={<EyeOutlined />}
|
|
|
|
|
+ onClick={() => setShowExtra(true)}
|
|
|
|
|
+ >
|
|
|
|
|
+ {dict.extraTitle}
|
|
|
|
|
+ </Button>
|
|
|
|
|
+ )}
|
|
|
|
|
+ </Col>
|
|
|
|
|
+ </Row>
|
|
|
|
|
+ <Row justify="center">
|
|
|
|
|
+ {words[index].star ? (
|
|
|
|
|
+ <Button type="primary" danger icon={<StarFilled />}>
|
|
|
|
|
+ 取消易错词
|
|
|
|
|
+ </Button>
|
|
|
|
|
+ ) : (
|
|
|
|
|
+ <Button danger icon={<StarOutlined />}>
|
|
|
|
|
+ 标记易错词
|
|
|
|
|
+ </Button>
|
|
|
|
|
+ )}
|
|
|
|
|
+ </Row>
|
|
|
|
|
+ </>
|
|
|
|
|
+ ) : (
|
|
|
|
|
+ <Empty />
|
|
|
|
|
+ )}
|
|
|
|
|
+ <Row>
|
|
|
|
|
+ <Col flex="1">
|
|
|
|
|
+ <Button
|
|
|
|
|
+ type="link"
|
|
|
|
|
+ block
|
|
|
|
|
+ disabled={index <= 0}
|
|
|
|
|
+ onClick={() => updateIndex(index - 1)}
|
|
|
|
|
+ >
|
|
|
|
|
+ <ArrowLeftOutlined /> 上一个
|
|
|
|
|
+ </Button>
|
|
|
|
|
+ </Col>
|
|
|
|
|
+ <Col>
|
|
|
|
|
+ <Button type="dashed" icon={<PlusOutlined />}>
|
|
|
|
|
+ 输入新单词
|
|
|
|
|
+ </Button>
|
|
|
|
|
+ </Col>
|
|
|
|
|
+ <Col flex="1">
|
|
|
|
|
+ {index >= words.length - 1 ? (
|
|
|
|
|
+ <Button
|
|
|
|
|
+ type="link"
|
|
|
|
|
+ block
|
|
|
|
|
+ onClick={() => {
|
|
|
|
|
+ setWords(_.shuffle(dict.words));
|
|
|
|
|
+ updateIndex(0);
|
|
|
|
|
+ }}
|
|
|
|
|
+ >
|
|
|
|
|
+ 再来一次 <ReloadOutlined />
|
|
|
|
|
+ </Button>
|
|
|
|
|
+ ) : (
|
|
|
|
|
+ <Button type="link" block onClick={() => updateIndex(index + 1)}>
|
|
|
|
|
+ 下一个 <ArrowRightOutlined />
|
|
|
|
|
+ </Button>
|
|
|
|
|
+ )}
|
|
|
|
|
+ </Col>
|
|
|
|
|
+ </Row>
|
|
|
|
|
+ </Space>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ );
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+export default MemoPage;
|