Commit 417899a7 authored by norhalimah's avatar norhalimah

.......

parent ca5914ae
...@@ -23,19 +23,19 @@ class LogBook extends React.PureComponent { ...@@ -23,19 +23,19 @@ class LogBook extends React.PureComponent {
}; };
} }
displayData = async () => { displayData = async () => {
try { try {
const value = await AsyncStorage.getItem('@storage_key'); const value = await AsyncStorage.getItem('@storage_key');
// console.log(JSON.parse(value));
if (value !== null) { if (value !== null) {
// We have data!! // We have data!!
// console.log(JSON.parse(value)); // console.log(JSON.parse(value));
this.setState({ logbook: JSON.parse(value) }); this.setState({ logbook: JSON.parse(value)});
console.log(this.state.logbook.length); console.log(this.state.logbook);
} }
} catch (error) { } catch (error) {
// Error retrieving data // Error retrieving data
} }
console.log(this.state.logbook);
}; };
componentDidMount() { componentDidMount() {
...@@ -58,30 +58,33 @@ console.log(this.state.logbook); ...@@ -58,30 +58,33 @@ console.log(this.state.logbook);
style={{ style={{
marginTop: 50, marginTop: 50,
}}> }}>
{this.state.logbook && this.state.logbook.map((item, id) => (
<View <View
key ={id}
style={{ style={{
flexDirection: 'row', flexDirection: 'row',
padding: 10, padding: 10,
backgroundColor: 'white', backgroundColor: 'white',
borderBottomWidth:1, borderBottomWidth:1,
}}> }}>
<View style={{alignItems: 'center', paddingLeft:15, paddingRight:15}}> <View style={{alignItems: 'center'}}>
<View style={{marginRight:5, marginBottom:5}}> <View style={{marginRight:10, marginBottom:10}}>
<Text style={{color:'black', fontSize: 40}}>{(this.state.logbook.date !== undefined) ? this.state.logbook.date.split(' ')[0].trim() : ''}</Text> <Text style={{color:'black', fontSize: 40}}>{(item.date !== undefined) ? item.date.split(' ')[0].trim() : ''}</Text>
<Text style={{color:'black', fontSize: 15}}>{(this.state.logbook.date !== undefined) ? this.state.logbook.date.split(' ')[1].trim() : ''}</Text> <Text style={{color:'black', fontSize: 15, marginLeft:11}}>{(item.date !== undefined) ? item.date.split(' ')[1].trim() : ''}</Text>
</View> </View>
<View style={{marginRight:5}}> <View style={{marginRight:5}}>
<Text style={{color:'black', fontSize: 15}}>{this.state.logbook.day}</Text> <Text style={{color:'black', fontSize: 15}}>{item.day}</Text>
</View> </View>
</View> </View>
<View style={{borderWidth:1, borderColor : 'blue'}}/> <View style={{borderWidth:1, borderColor : 'blue'}}/>
<View style={{flexDirection: 'column',marginLeft:5,marginTop:5}}> <View style={{flexDirection: 'column',marginLeft:5,marginTop:5}}>
<Text style={{color:'green', fontSize: 15}}>Correct : {this.state.logbook.correct}</Text> <Text style={{color:'green', fontSize: 15}}>Correct : {item.correct}</Text>
<Text style={{color:'red', fontSize: 15}}>Wrong : {this.state.logbook.wrong}</Text> <Text style={{color:'red', fontSize: 15}}>Wrong : {item.wrong}</Text>
<Text style={{color:'black', fontSize: 15}}>Timer : {this.state.logbook.timer}</Text> <Text style={{color:'black', fontSize: 15}}>Timer : {item.timer}</Text>
<Text style={{color:'black', fontSize: 15}}>Time : {this.state.logbook.time}</Text> <Text style={{color:'black', fontSize: 15}}>Time : {item.time}</Text>
</View> </View>
</View> </View>
)).reverse()}
</ScrollView> </ScrollView>
</SafeAreaView> </SafeAreaView>
</ImageBackground> </ImageBackground>
......
...@@ -21,10 +21,15 @@ import Orientation from 'react-native-orientation'; ...@@ -21,10 +21,15 @@ import Orientation from 'react-native-orientation';
import * as RNFS from 'react-native-fs'; import * as RNFS from 'react-native-fs';
import Notes from './data'; import Notes from './data';
import styles from '../style/style'; import styles from '../style/style';
import OtherClass from './saveRecords'; //import OtherClass from './saveRecords';
import Sound from 'react-native-sound'; import Sound from 'react-native-sound';
import moment from 'moment';
import AsyncStorage from '@react-native-async-storage/async-storage';
const date = moment().utcOffset('+08:00').format('D MMM');
const time = moment().utcOffset('+08:00').format('h:mm a');
const day = moment().utcOffset('+08:00').format('ddd');
const path = RNFS.DocumentDirectoryPath + '/settings.txt'; //const path = RNFS.DocumentDirectoryPath + '/settings.txt';
const path1 = RNFS.DocumentDirectoryPath + '/counter.txt'; const path1 = RNFS.DocumentDirectoryPath + '/counter.txt';
const NOTESWHITE = [ const NOTESWHITE = [
{name: 'C1', url: require('../sound/c.mp3')}, {name: 'C1', url: require('../sound/c.mp3')},
...@@ -54,10 +59,10 @@ const NOTESGG1 = [{name: 'G#2', url: require('../sound/g_gg.mp3')}]; ...@@ -54,10 +59,10 @@ const NOTESGG1 = [{name: 'G#2', url: require('../sound/g_gg.mp3')}];
const NOTESAA1 = [{name: 'A#2', url: require('../sound/a_aa.mp3')}]; const NOTESAA1 = [{name: 'A#2', url: require('../sound/a_aa.mp3')}];
const keywordsList = []; const keywordsList = [];
var maxCount = 5;
var imageN = ''; var imageN = '';
var indexN = 0; var indexN = 0;
var stime = 0; var stime = 0;
//var records = [];
class Quiz extends React.Component { class Quiz extends React.Component {
...@@ -76,6 +81,8 @@ class Quiz extends React.Component { ...@@ -76,6 +81,8 @@ class Quiz extends React.Component {
showC : false, showC : false,
showW : false, showW : false,
showDone : false, showDone : false,
maxCount : 5,
records: [],
}; };
} }
...@@ -159,7 +166,7 @@ class Quiz extends React.Component { ...@@ -159,7 +166,7 @@ class Quiz extends React.Component {
ansCMajor = ()=> { ansCMajor = ()=> {
if (keywordsList.toString() === 'C1,D1,E1,F1,G1,A1,B1,C2'){ if (keywordsList.toString() === 'C1,D1,E1,F1,G1,A1,B1,C2'){
if ( (this.state.count + 1) > maxCount) { if ( (this.state.count + 1) > this.state.maxCount) {
this.setState({correct : this.state.correct + 1}); this.setState({correct : this.state.correct + 1});
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime); this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime);
...@@ -173,7 +180,7 @@ class Quiz extends React.Component { ...@@ -173,7 +180,7 @@ class Quiz extends React.Component {
this.displayData(); this.displayData();
} }
} else { } else {
if ( (this.state.count + 1) > maxCount) { if ( (this.state.count + 1) > this.state.maxCount) {
this.setState({wrong : this.state.wrong + 1}); this.setState({wrong : this.state.wrong + 1});
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime); this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime);
...@@ -192,7 +199,7 @@ class Quiz extends React.Component { ...@@ -192,7 +199,7 @@ class Quiz extends React.Component {
ansDMajor = () => { ansDMajor = () => {
if (keywordsList.toString() === 'D1,E1,F#1,G1,A1,B1,C#2,D2') { if (keywordsList.toString() === 'D1,E1,F#1,G1,A1,B1,C#2,D2') {
if ( (this.state.count + 1) > maxCount) { if ( (this.state.count + 1) > this.state.maxCount) {
this.setState({correct : this.state.correct + 1}); this.setState({correct : this.state.correct + 1});
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime); this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime);
...@@ -206,7 +213,7 @@ class Quiz extends React.Component { ...@@ -206,7 +213,7 @@ class Quiz extends React.Component {
this.displayData(); this.displayData();
} }
} else { } else {
if ( (this.state.count + 1) > maxCount) { if ( (this.state.count + 1) > this.state.maxCount) {
this.setState({wrong : this.state.wrong + 1}); this.setState({wrong : this.state.wrong + 1});
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime); this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime);
...@@ -225,7 +232,7 @@ class Quiz extends React.Component { ...@@ -225,7 +232,7 @@ class Quiz extends React.Component {
ansEMajor = () => { ansEMajor = () => {
if (keywordsList.toString() === 'E1,F#1,G#1,A1,B1,C#2,D#2,E2') { if (keywordsList.toString() === 'E1,F#1,G#1,A1,B1,C#2,D#2,E2') {
if ( (this.state.count + 1) > maxCount) { if ( (this.state.count + 1) > this.state.maxCount) {
this.setState({correct : this.state.correct + 1}); this.setState({correct : this.state.correct + 1});
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime); this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime);
...@@ -239,7 +246,7 @@ class Quiz extends React.Component { ...@@ -239,7 +246,7 @@ class Quiz extends React.Component {
this.displayData(); this.displayData();
} }
} else { } else {
if ( (this.state.count + 1) > maxCount) { if ( (this.state.count + 1) > this.state.maxCount) {
this.setState({wrong : this.state.wrong + 1}); this.setState({wrong : this.state.wrong + 1});
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime); this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime);
...@@ -258,7 +265,7 @@ class Quiz extends React.Component { ...@@ -258,7 +265,7 @@ class Quiz extends React.Component {
ansFsMajor = () => { ansFsMajor = () => {
if (keywordsList.toString() === 'F#1,G#1,A#1,B1,C#2,D#2,F2,F#2') { if (keywordsList.toString() === 'F#1,G#1,A#1,B1,C#2,D#2,F2,F#2') {
if ( (this.state.count + 1) > maxCount) { if ( (this.state.count + 1) > this.state.maxCount) {
this.setState({correct : this.state.correct + 1}); this.setState({correct : this.state.correct + 1});
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime); this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime);
...@@ -272,7 +279,7 @@ class Quiz extends React.Component { ...@@ -272,7 +279,7 @@ class Quiz extends React.Component {
this.displayData(); this.displayData();
} }
} else { } else {
if ( (this.state.count + 1) > maxCount) { if ( (this.state.count + 1) > this.state.maxCount) {
this.setState({wrong : this.state.wrong + 1}); this.setState({wrong : this.state.wrong + 1});
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime); this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime);
...@@ -291,7 +298,7 @@ class Quiz extends React.Component { ...@@ -291,7 +298,7 @@ class Quiz extends React.Component {
ansFMajor = () => { ansFMajor = () => {
if (keywordsList.toString() === 'F1,G1,A1,A#1,C2,D2,E2,F2') { if (keywordsList.toString() === 'F1,G1,A1,A#1,C2,D2,E2,F2') {
if ( (this.state.count + 1) > maxCount) { if ( (this.state.count + 1) > this.state.maxCount) {
this.setState({correct : this.state.correct + 1}); this.setState({correct : this.state.correct + 1});
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime); this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime);
...@@ -305,7 +312,7 @@ class Quiz extends React.Component { ...@@ -305,7 +312,7 @@ class Quiz extends React.Component {
this.displayData(); this.displayData();
} }
} else { } else {
if ( (this.state.count + 1) > maxCount) { if ( (this.state.count + 1) > this.state.maxCount) {
this.setState({wrong : this.state.wrong + 1}); this.setState({wrong : this.state.wrong + 1});
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime); this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime);
...@@ -324,7 +331,7 @@ class Quiz extends React.Component { ...@@ -324,7 +331,7 @@ class Quiz extends React.Component {
ansEbMajor = () => { ansEbMajor = () => {
if (keywordsList.toString() === 'D#1,F1,G1,G#1,A#1,C2,D2,D#2') { if (keywordsList.toString() === 'D#1,F1,G1,G#1,A#1,C2,D2,D#2') {
if ( (this.state.count + 1) > maxCount) { if ( (this.state.count + 1) > this.state.maxCount) {
this.setState({correct : this.state.correct + 1}); this.setState({correct : this.state.correct + 1});
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime); this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime);
...@@ -338,7 +345,7 @@ class Quiz extends React.Component { ...@@ -338,7 +345,7 @@ class Quiz extends React.Component {
this.displayData(); this.displayData();
} }
} else { } else {
if ( (this.state.count + 1) > maxCount) { if ( (this.state.count + 1) > this.state.maxCount) {
this.setState({wrong : this.state.wrong + 1}); this.setState({wrong : this.state.wrong + 1});
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime); this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime);
...@@ -357,7 +364,7 @@ class Quiz extends React.Component { ...@@ -357,7 +364,7 @@ class Quiz extends React.Component {
ansDbMajor = () => { ansDbMajor = () => {
if (keywordsList.toString() === 'C#1,D#1,F1,F#1,G#1,A#1,C2,C#2') { if (keywordsList.toString() === 'C#1,D#1,F1,F#1,G#1,A#1,C2,C#2') {
if ( (this.state.count + 1) > maxCount) { if ( (this.state.count + 1) > this.state.maxCount) {
this.setState({correct : this.state.correct + 1}); this.setState({correct : this.state.correct + 1});
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime); this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime);
...@@ -371,7 +378,7 @@ class Quiz extends React.Component { ...@@ -371,7 +378,7 @@ class Quiz extends React.Component {
this.displayData(); this.displayData();
} }
} else { } else {
if ( (this.state.count + 1) > maxCount) { if ( (this.state.count + 1) > this.state.maxCount) {
this.setState({wrong : this.state.wrong + 1}); this.setState({wrong : this.state.wrong + 1});
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime); this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime);
...@@ -390,7 +397,7 @@ class Quiz extends React.Component { ...@@ -390,7 +397,7 @@ class Quiz extends React.Component {
ansGMajor = () => { ansGMajor = () => {
if (keywordsList.toString() === 'G1,A1,B1,C2,D2,E2,F#2,G2') { if (keywordsList.toString() === 'G1,A1,B1,C2,D2,E2,F#2,G2') {
if ( (this.state.count + 1) > maxCount) { if ( (this.state.count + 1) > this.state.maxCount) {
this.setState({correct : this.state.correct + 1}); this.setState({correct : this.state.correct + 1});
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime); this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime);
...@@ -404,7 +411,7 @@ class Quiz extends React.Component { ...@@ -404,7 +411,7 @@ class Quiz extends React.Component {
this.displayData(); this.displayData();
} }
} else { } else {
if ( (this.state.count + 1) > maxCount) { if ( (this.state.count + 1) > this.state.maxCount) {
this.setState({wrong : this.state.wrong + 1}); this.setState({wrong : this.state.wrong + 1});
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime); this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime);
...@@ -423,7 +430,7 @@ class Quiz extends React.Component { ...@@ -423,7 +430,7 @@ class Quiz extends React.Component {
ansAMajor = () => { ansAMajor = () => {
if (keywordsList.toString() === 'A1,B1,C#2,D2,E2,F#2,G#2,A2') { if (keywordsList.toString() === 'A1,B1,C#2,D2,E2,F#2,G#2,A2') {
if ( (this.state.count + 1) > maxCount) { if ( (this.state.count + 1) > this.state.maxCount) {
this.setState({correct : this.state.correct + 1}); this.setState({correct : this.state.correct + 1});
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime); this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime);
...@@ -437,7 +444,7 @@ class Quiz extends React.Component { ...@@ -437,7 +444,7 @@ class Quiz extends React.Component {
this.displayData(); this.displayData();
} }
} else { } else {
if ( (this.state.count + 1) > maxCount) { if ( (this.state.count + 1) > this.state.maxCount) {
this.setState({wrong : this.state.wrong + 1}); this.setState({wrong : this.state.wrong + 1});
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime); this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime);
...@@ -456,7 +463,7 @@ class Quiz extends React.Component { ...@@ -456,7 +463,7 @@ class Quiz extends React.Component {
ansBMajor = () => { ansBMajor = () => {
if (keywordsList.toString() === 'B1,C#2,D#2,E2,F#2,G#2,A#2,B2') { if (keywordsList.toString() === 'B1,C#2,D#2,E2,F#2,G#2,A#2,B2') {
if ( (this.state.count + 1) > maxCount) { if ( (this.state.count + 1) > this.state.maxCount) {
this.setState({correct : this.state.correct + 1}); this.setState({correct : this.state.correct + 1});
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime); this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime);
...@@ -470,7 +477,7 @@ class Quiz extends React.Component { ...@@ -470,7 +477,7 @@ class Quiz extends React.Component {
this.displayData(); this.displayData();
} }
} else { } else {
if ( (this.state.count + 1) > maxCount) { if ( (this.state.count + 1) > this.state.maxCount) {
this.setState({wrong : this.state.wrong + 1}); this.setState({wrong : this.state.wrong + 1});
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime); this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime);
...@@ -489,7 +496,7 @@ class Quiz extends React.Component { ...@@ -489,7 +496,7 @@ class Quiz extends React.Component {
ansCsMajor = () => { ansCsMajor = () => {
if (keywordsList.toString() === 'C#1,D#1,F1,F#1,G#1,A#1,C2,C#2') { if (keywordsList.toString() === 'C#1,D#1,F1,F#1,G#1,A#1,C2,C#2') {
if ( (this.state.count + 1) > maxCount) { if ( (this.state.count + 1) > this.state.maxCount) {
this.setState({correct : this.state.correct + 1}); this.setState({correct : this.state.correct + 1});
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime); this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime);
...@@ -503,7 +510,7 @@ class Quiz extends React.Component { ...@@ -503,7 +510,7 @@ class Quiz extends React.Component {
this.displayData(); this.displayData();
} }
} else { } else {
if ( (this.state.count + 1) > maxCount) { if ( (this.state.count + 1) > this.state.maxCount) {
this.setState({wrong : this.state.wrong + 1}); this.setState({wrong : this.state.wrong + 1});
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime); this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime);
...@@ -522,7 +529,7 @@ class Quiz extends React.Component { ...@@ -522,7 +529,7 @@ class Quiz extends React.Component {
ansBbMajor = () => { ansBbMajor = () => {
if (keywordsList.toString() === 'A#1,C2,D2,D#2,F2,G2,A2,A#2') { if (keywordsList.toString() === 'A#1,C2,D2,D#2,F2,G2,A2,A#2') {
if ( (this.state.count + 1) > maxCount) { if ( (this.state.count + 1) > this.state.maxCount) {
this.setState({correct : this.state.correct + 1}); this.setState({correct : this.state.correct + 1});
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime); this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime);
...@@ -536,7 +543,7 @@ class Quiz extends React.Component { ...@@ -536,7 +543,7 @@ class Quiz extends React.Component {
this.displayData(); this.displayData();
} }
} else { } else {
if ( (this.state.count + 1) > maxCount) { if ( (this.state.count + 1) > this.state.maxCount) {
this.setState({wrong : this.state.wrong + 1}); this.setState({wrong : this.state.wrong + 1});
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime); this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime);
...@@ -555,7 +562,7 @@ class Quiz extends React.Component { ...@@ -555,7 +562,7 @@ class Quiz extends React.Component {
ansAbMajor = () => { ansAbMajor = () => {
if (keywordsList.toString() === 'G#1,A#1,C2,C#2,D#2,F2,G2,G#2') { if (keywordsList.toString() === 'G#1,A#1,C2,C#2,D#2,F2,G2,G#2') {
if ( (this.state.count + 1) > maxCount) { if ( (this.state.count + 1) > this.state.maxCount) {
this.setState({correct : this.state.correct + 1}); this.setState({correct : this.state.correct + 1});
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime); this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime);
...@@ -569,7 +576,7 @@ class Quiz extends React.Component { ...@@ -569,7 +576,7 @@ class Quiz extends React.Component {
this.displayData(); this.displayData();
} }
} else { } else {
if ( (this.state.count + 1) > maxCount) { if ( (this.state.count + 1) > this.state.maxCount) {
this.setState({wrong : this.state.wrong + 1}); this.setState({wrong : this.state.wrong + 1});
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime); this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime);
...@@ -588,7 +595,7 @@ class Quiz extends React.Component { ...@@ -588,7 +595,7 @@ class Quiz extends React.Component {
ansGbMajor = () => { ansGbMajor = () => {
if (keywordsList.toString() === 'F#1,G#1,A#1,B1,C#2,D#2,F2,F#2') { if (keywordsList.toString() === 'F#1,G#1,A#1,B1,C#2,D#2,F2,F#2') {
if ( (this.state.count + 1) > maxCount) { if ( (this.state.count + 1) > this.state.maxCount) {
this.setState({correct : this.state.correct + 1}); this.setState({correct : this.state.correct + 1});
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime); this.handlerArgCall((this.state.correct + 1), this.state.wrong, stime);
...@@ -602,7 +609,7 @@ class Quiz extends React.Component { ...@@ -602,7 +609,7 @@ class Quiz extends React.Component {
this.displayData(); this.displayData();
} }
} else { } else {
if ( (this.state.count + 1) > maxCount) { if ( (this.state.count + 1) > this.state.maxCount) {
this.setState({wrong : this.state.wrong + 1}); this.setState({wrong : this.state.wrong + 1});
this.setState({showDone: true}); this.setState({showDone: true});
this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime); this.handlerArgCall(this.state.correct, (this.state.wrong + 1), stime);
...@@ -633,10 +640,14 @@ class Quiz extends React.Component { ...@@ -633,10 +640,14 @@ class Quiz extends React.Component {
';'; ';';
displayData = async () => { displayData = async () => {
RNFS.readFile(path, 'ascii') this.setState({records: []});
.then((res) => { try {
const value = await AsyncStorage.getItem('@notes_key');
console.log(JSON.parse(value));
if (value !== null) {
// We have data!!
this.setState({ this.setState({
logbook: res.split(','), logbook: JSON.parse(value),
}); });
console.log(this.state.logbook); console.log(this.state.logbook);
RNFS.readFile(path1, 'ascii') RNFS.readFile(path1, 'ascii')
...@@ -646,10 +657,10 @@ class Quiz extends React.Component { ...@@ -646,10 +657,10 @@ class Quiz extends React.Component {
imageN = Math.floor(Math.random() * this.state.logbook.length); imageN = Math.floor(Math.random() * this.state.logbook.length);
this.setState({ this.setState({
name : this.state.logbook[imageN], name : this.state.logbook[imageN],
maxCount : ccc,
}); });
indexN = Notes.findIndex(item=> '"' + item.name + '"' === this.state.name || '["' + item.name + '"]' === this.state.name || '["' + item.name + '"' === this.state.name || '"' + item.name + '"]' === this.state.name); indexN = Notes.findIndex(item=> item.name === this.state.name);
console.log(this.state.name); console.log(this.state.name);
maxCount = ccc;
}) })
.catch((err) => { .catch((err) => {
console.log(err.message, err.code); console.log(err.message, err.code);
...@@ -657,13 +668,14 @@ class Quiz extends React.Component { ...@@ -657,13 +668,14 @@ class Quiz extends React.Component {
imageN = Math.floor(Math.random() * this.state.logbook.length); imageN = Math.floor(Math.random() * this.state.logbook.length);
this.setState({ this.setState({
name : this.state.logbook[imageN], name : this.state.logbook[imageN],
maxCount : 10,
}); });
indexN = Notes.findIndex(item=> '"' + item.name + '"' === this.state.name || '["' + item.name + '"]' === this.state.name || '["' + item.name + '"' === this.state.name || '"' + item.name + '"]' === this.state.name); console.log(this.state.name);
indexN = Notes.findIndex(item=> item.name === this.state.name);
console.log(indexN);
}); });
maxCount = this.state.logbook.length; }
}) else {
.catch((err) => {
console.log(err.message, err.code);
RNFS.readFile(path1, 'ascii') RNFS.readFile(path1, 'ascii')
.then((res) => { .then((res) => {
console.log('no notes has counter'); console.log('no notes has counter');
...@@ -671,8 +683,8 @@ class Quiz extends React.Component { ...@@ -671,8 +683,8 @@ class Quiz extends React.Component {
indexN = imageN; indexN = imageN;
this.setState({ this.setState({
name : Notes[indexN].name, name : Notes[indexN].name,
maxCount : res,
}); });
maxCount = res;
//console.log(res); //console.log(res);
}) })
.catch(() => { .catch(() => {
...@@ -682,14 +694,58 @@ class Quiz extends React.Component { ...@@ -682,14 +694,58 @@ class Quiz extends React.Component {
indexN = imageN; indexN = imageN;
this.setState({ this.setState({
name : Notes[indexN].name, name : Notes[indexN].name,
maxCount : 5,
}); });
maxCount = 5;
}); });
}); }
}; } catch (error) {
// Error retrieving data
}
};
handlerArgCall = (correct, wrong, timer) => { handlerArgCall = async(correct, wrong, timer) => {
new OtherClass().saveRecord(correct, wrong, timer); var listR = [];
let obj = {
correct: correct,
wrong: wrong,
timer: timer,
date: date,
time: time,
day : day,
};
this.setState({records : obj});
try {
var value = await AsyncStorage.getItem('@storage_key');
if (value !== null) {
value = JSON.parse(value);
value.push(obj);
// console.log(value);
console.log('We have data!!');
AsyncStorage.setItem('@storage_key', JSON.stringify(value), (err)=> {
if (err){
console.log('an error');
throw err;
}
console.log('success');
}).catch((err)=> {
console.log('error is: ' + err);
});
}
else {
listR.push(obj);
AsyncStorage.setItem('@storage_key', JSON.stringify(listR), (err)=> {
if (err){
console.log('an error');
throw err;
}
console.log('success'); //console.log(JSON.stringify(this.state.listN));
}).catch((err)=> {
console.log('error is: ' + err);
});
}
} catch (error) {
// Error retrieving data
}
}; };
//reset //reset
...@@ -822,7 +878,7 @@ class Quiz extends React.Component { ...@@ -822,7 +878,7 @@ class Quiz extends React.Component {
<View style={styles.c1}> <View style={styles.c1}>
<View style={styles.cc1}> <View style={styles.cc1}>
<Text style={styles.wrong}>{this.state.wrong}</Text> <Text style={styles.wrong}>{this.state.wrong}</Text>
<Text style={styles.correct}>{this.state.correct} / {maxCount}</Text> <Text style={styles.correct}>{this.state.correct} / {this.state.maxCount}</Text>
<Stopwatch <Stopwatch
secs secs
start={this.state.start} start={this.state.start}
......
/* eslint-disable prettier/prettier */ /* eslint-disable prettier/prettier */
/*This is an Example of Calling Other Class Function in React Native*/
import { Component } from 'react'; import { Component } from 'react';
import moment from 'moment'; import moment from 'moment';
import AsyncStorage from '@react-native-async-storage/async-storage'; import AsyncStorage from '@react-native-async-storage/async-storage';
const date = moment().utcOffset('+08:00').format('D MMM'); const date = moment().utcOffset('+08:00').format('D MMM');
const time = moment().utcOffset('+08:00').format('h:mm a'); const time = moment().utcOffset('+08:00').format('h:mm a');
const day = moment().utcOffset('+08:00').format('ddd'); const day = moment().utcOffset('+08:00').format('ddd');
var records = []; //var records = [];
class OtherClass extends Component { class OtherClass extends Component {
saveRecord = async (correct, wrong, stime) => { saveRecord = async (correct, wrong, stime) => {
...@@ -23,34 +22,15 @@ class OtherClass extends Component { ...@@ -23,34 +22,15 @@ class OtherClass extends Component {
const value = await AsyncStorage.getItem('@storage_key'); const value = await AsyncStorage.getItem('@storage_key');
if (value !== null) { if (value !== null) {
// We have data!! // We have data!!
console.log(JSON.parse(value)); // console.log(JSON.parse(value));
records.push(JSON.parse(value)); this.setState({ logbook: JSON.parse(value) });
records.push(JSON.parse(obj)); console.log(this.state.logbook.length);
//console.log(records);
AsyncStorage.setItem('@storage_key', JSON.stringify(records), (err)=> {
if (err){
console.log('an error');
throw err;
}
// console.log('success');
}).catch((err)=> {
console.log('error is: ' + err);
});
}
else {
AsyncStorage.setItem('@storage_key', JSON.stringify(obj), (err)=> {
if (err){
console.log('an error');
throw err;
}
// console.log('success');
}).catch((err)=> {
console.log('error is: ' + err);
});
} }
} catch (error) { } catch (error) {
// Error retrieving data // Error retrieving data
} }
}; };
} }
......
...@@ -17,8 +17,9 @@ import Orientation from 'react-native-orientation'; ...@@ -17,8 +17,9 @@ import Orientation from 'react-native-orientation';
import Notes from './data'; import Notes from './data';
import * as RNFS from 'react-native-fs'; import * as RNFS from 'react-native-fs';
import NumericInput from 'react-native-numeric-input'; import NumericInput from 'react-native-numeric-input';
import AsyncStorage from '@react-native-async-storage/async-storage';
var path = RNFS.DocumentDirectoryPath + '/settings.txt'; //var path = RNFS.DocumentDirectoryPath + '/settings.txt';
var path1 = RNFS.DocumentDirectoryPath + '/counter.txt'; var path1 = RNFS.DocumentDirectoryPath + '/counter.txt';
...@@ -76,31 +77,56 @@ export default class Settings extends React.Component { ...@@ -76,31 +77,56 @@ export default class Settings extends React.Component {
list.push(keyword); list.push(keyword);
} }
this.setState({listN: list}); this.setState({listN: list});
if (this.state.listN !== null){
this.setState({listN: list});
this.saveData(this.state.listN); this.saveData(this.state.listN);
this.displayData(); }
else {
this.setState({listN: notes});
this.saveData2(this.state.listN);
}
this._retrieveData();
// console.log(notes); // console.log(notes);
}; };
saveData = async () => { saveData = async () => {
RNFS.writeFile(path,JSON.stringify(this.state.listN),'utf8',) AsyncStorage.setItem('@notes_key', JSON.stringify(this.state.listN), (err)=> {
.then((success) => { if (err){
console.log(JSON.stringify(this.state.listN)); console.log('an error');
}) throw err;
.catch((err) => { }
console.log(err.message); console.log('success'); //console.log(JSON.stringify(this.state.listN));
}).catch((err)=> {
console.log('error is: ' + err);
}); });
}; };
displayData = async () => { saveData = async () => {
RNFS.readFile(path, 'ascii') AsyncStorage.setItem('@notes_key', JSON.stringify(this.state.listN), (err)=> {
.then((res) => { if (err){
// console.log(JSON.stringify(res)); console.log('an error');
}) throw err;
.catch((err) => { }
console.log(err.message, err.code); console.log('success'); //console.log(JSON.stringify(this.state.listN));
}).catch((err)=> {
console.log('error is: ' + err);
}); });
}; };
_retrieveData = async () => {
try {
const value = await AsyncStorage.getItem('@notes_key');
if (value !== null) {
// We have data!!
console.log(value);
}
} catch (error) {
// Error retrieving data
}
};
saveData1 = async () => { saveData1 = async () => {
RNFS.writeFile(path1,JSON.stringify(counter),'utf8',) RNFS.writeFile(path1,JSON.stringify(counter),'utf8',)
.then((success) => { .then((success) => {
...@@ -127,13 +153,6 @@ export default class Settings extends React.Component { ...@@ -127,13 +153,6 @@ export default class Settings extends React.Component {
Orientation.lockToPortrait(); Orientation.lockToPortrait();
// console.log(notes.length); // console.log(notes.length);
counter = 0; counter = 0;
RNFS.unlink(path).then(res => {
console.log('delete');
RNFS.scanFile(path);
})
.catch(err => {
console.log(err.message, err.code);
});
RNFS.unlink(path1).then(res => { RNFS.unlink(path1).then(res => {
console.log('delete'); console.log('delete');
RNFS.scanFile(path1); RNFS.scanFile(path1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment