diff --git a/components/Header.tsx b/components/Header.tsx
index 835ba08..02a08a1 100644
--- a/components/Header.tsx
+++ b/components/Header.tsx
@@ -1,5 +1,5 @@
import React from 'react';
-import { Text, View, StyleSheet } from 'react-native';
+import { Text, StyleSheet } from 'react-native';
import { learnihonColors } from '../assets/colors';
import { SafeAreaView } from 'react-native-safe-area-context';
diff --git a/components/KanjiCard.tsx b/components/KanjiCard.tsx
index 0122c88..7f1f6a9 100644
--- a/components/KanjiCard.tsx
+++ b/components/KanjiCard.tsx
@@ -1,17 +1,14 @@
import React, { useEffect, useState } from 'react';
-import { Button, KeyboardAvoidingView, Platform, ScrollView, StyleSheet, Text, useColorScheme } from 'react-native';
+import { Button, KeyboardAvoidingView, Platform, ScrollView, StyleSheet, Text, useColorScheme, View } from 'react-native';
import { SvgXml } from 'react-native-svg';
import { useSelector } from 'react-redux';
import { learnihonColors } from '../assets/colors';
import { Kanji } from '../model/kanji';
import { KanjiListByGrade } from '../model/kanjiListByGrades';
+import GradeChipList from './GradeChipList';
import KanjiAnswerField from './KanjiAnswerField';
-type KanjiProps = {
- kanji: string;
-}
-
-const KanjiCard = (props: KanjiProps) => {
+const KanjiCard = () => {
var kanjiCardStyle = useColorScheme() == 'light' ? kanjiCardStyle_light : kanjiCardStyle_dark;
const [answerTextColor, setAnswerTextColor] = useState(kanjiCardStyle.text.color);
@@ -23,7 +20,25 @@ const KanjiCard = (props: KanjiProps) => {
}
})
- const nextKanji = () => allKanjis[Math.floor(Math.random() * allKanjis.length)];
+ const [selectedItems, setSelectedItems] = useState<{ title: string, data: Kanji[] }[]>([]);
+ const updateSelectedItems = (item: string, isSelected: Boolean) => {
+ if (!isSelected) {
+ setSelectedItems([...selectedItems, {
+ title: item,
+ data: kanjis[item]
+ }]);
+ } else {
+ setSelectedItems(selectedItems.filter((selectedItem) => selectedItem.title !== item));
+ }
+ };
+
+ const nextKanji = () => {
+ if (selectedItems.length) {
+ var items= [].concat(...Object.values(selectedItems.map(it => it.data)))
+ return items[Math.floor(Math.random() * items.length)]
+ }
+ return allKanjis[Math.floor(Math.random() * allKanjis.length)]
+ };
const [kanji, setKanji] = useState((): Kanji | null => { return null });
const [imgXml, setImgXml] = useState('');
@@ -32,8 +47,7 @@ const KanjiCard = (props: KanjiProps) => {
var kanjis: KanjiListByGrade = useSelector(state => state.kanjiReducer.kanjis);
- const allKanjis: Kanji[] = [].concat(...Object.values(kanjis))
-
+ const allKanjis = [].concat(...Object.values(kanjis))
const fetchXml = async () => {
if (kanji) {
@@ -68,36 +82,41 @@ const KanjiCard = (props: KanjiProps) => {
}
return (
-
-
-
- {kanji?.onyomi}
- {kanji?.kunyomi}
-
-
-
- {!hasAnswered && (
- <>
-
+
+
+
+
+
+
+
+
+ {kanji?.onyomi}
+ {kanji?.kunyomi}
+
+
+ {!hasAnswered && (
+ <>
+
- >
- ) || (
- <>
- {kanji?.meaning}
- {answer}
+ >
+ ) || (
+ <>
+ {kanji?.meaning}
+ {answer}
-
+ >
+ )}
+
+
+
);
};
diff --git a/components/KanjiList.tsx b/components/KanjiList.tsx
index 4636f4b..12e39fa 100644
--- a/components/KanjiList.tsx
+++ b/components/KanjiList.tsx
@@ -11,12 +11,7 @@ import KanjiListCell from './KanjiListCell';
const KanjiList = () => {
const kanjiListStyle = useColorScheme() == 'light' ? kanjiListStyle_light : kanjiListStyle_dark;
- const dispatch = useDispatch();
-
-
- const [res, setData] = useState(null);
- const [loading, setLoading] = useState(true);
var kanjis: KanjiListByGrade = useSelector(state => state.kanjiReducer.kanjis);
const [selectedItems, setSelectedItems] = useState<{title: string, data: Kanji[]}[]>([]);
@@ -31,12 +26,6 @@ const KanjiList = () => {
}
};
- useEffect(() => {
-
-
-
- }, [dispatch]);
-
return (
diff --git a/pages/Learn.tsx b/pages/Learn.tsx
index bfd54fe..96f86f5 100644
--- a/pages/Learn.tsx
+++ b/pages/Learn.tsx
@@ -10,7 +10,7 @@ const Learn = () => {
return (
-
+
);
};