Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pianoApp
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
norhalimah
pianoApp
Commits
417899a7
Commit
417899a7
authored
Jan 12, 2021
by
norhalimah
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.......
parent
ca5914ae
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
180 additions
and
122 deletions
+180
-122
logbook.js
screens/logbook.js
+18
-15
quiz.js
screens/quiz.js
+112
-56
saveRecords.js
screens/saveRecords.js
+7
-27
settings.js
screens/settings.js
+43
-24
No files found.
screens/logbook.js
View file @
417899a7
...
...
@@ -23,19 +23,19 @@ class LogBook extends React.PureComponent {
};
}
displayData
=
async
()
=>
{
try
{
const
value
=
await
AsyncStorage
.
getItem
(
'@storage_key'
);
// console.log(JSON.parse(value));
if
(
value
!==
null
)
{
// We have data!!
// console.log(JSON.parse(value));
this
.
setState
({
logbook
:
JSON
.
parse
(
value
)
});
console
.
log
(
this
.
state
.
logbook
.
length
);
// console.log(JSON.parse(value));
this
.
setState
({
logbook
:
JSON
.
parse
(
value
)});
console
.
log
(
this
.
state
.
logbook
);
}
}
catch
(
error
)
{
// Error retrieving data
}
console
.
log
(
this
.
state
.
logbook
);
}
};
componentDidMount
()
{
...
...
@@ -58,30 +58,33 @@ console.log(this.state.logbook);
style
=
{{
marginTop
:
50
,
}}
>
{
this
.
state
.
logbook
&&
this
.
state
.
logbook
.
map
((
item
,
id
)
=>
(
<
View
key
=
{
id
}
style
=
{{
flexDirection
:
'row'
,
padding
:
10
,
backgroundColor
:
'white'
,
borderBottomWidth
:
1
,
}}
>
<
View
style
=
{{
alignItems
:
'center'
,
paddingLeft
:
15
,
paddingRight
:
15
}}
>
<
View
style
=
{{
marginRight
:
5
,
marginBottom
:
5
}}
>
<
Text
style
=
{{
color
:
'black'
,
fontSize
:
40
}}
>
{(
this
.
state
.
logbook
.
date
!==
undefined
)
?
this
.
state
.
logbook
.
date
.
split
(
' '
)[
0
].
trim
()
:
''
}
<
/Text
>
<
Text
style
=
{{
color
:
'black'
,
fontSize
:
15
}}
>
{(
this
.
state
.
logbook
.
date
!==
undefined
)
?
this
.
state
.
logbook
.
date
.
split
(
' '
)[
1
].
trim
()
:
''
}
<
/Text
>
<
View
style
=
{{
alignItems
:
'center'
}}
>
<
View
style
=
{{
marginRight
:
10
,
marginBottom
:
10
}}
>
<
Text
style
=
{{
color
:
'black'
,
fontSize
:
40
}}
>
{(
item
.
date
!==
undefined
)
?
item
.
date
.
split
(
' '
)[
0
].
trim
()
:
''
}
<
/Text
>
<
Text
style
=
{{
color
:
'black'
,
fontSize
:
15
,
marginLeft
:
11
}}
>
{(
item
.
date
!==
undefined
)
?
item
.
date
.
split
(
' '
)[
1
].
trim
()
:
''
}
<
/Text
>
<
/View
>
<
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
style
=
{{
borderWidth
:
1
,
borderColor
:
'blue'
}}
/
>
<
View
style
=
{{
flexDirection
:
'column'
,
marginLeft
:
5
,
marginTop
:
5
}}
>
<
Text
style
=
{{
color
:
'green'
,
fontSize
:
15
}}
>
Correct
:
{
this
.
state
.
logbook
.
correct
}
<
/Text
>
<
Text
style
=
{{
color
:
'red'
,
fontSize
:
15
}}
>
Wrong
:
{
this
.
state
.
logbook
.
wrong
}
<
/Text
>
<
Text
style
=
{{
color
:
'black'
,
fontSize
:
15
}}
>
Timer
:
{
this
.
state
.
logbook
.
timer
}
<
/Text
>
<
Text
style
=
{{
color
:
'black'
,
fontSize
:
15
}}
>
Time
:
{
this
.
state
.
logbook
.
time
}
<
/Text
>
<
Text
style
=
{{
color
:
'green'
,
fontSize
:
15
}}
>
Correct
:
{
item
.
correct
}
<
/Text
>
<
Text
style
=
{{
color
:
'red'
,
fontSize
:
15
}}
>
Wrong
:
{
item
.
wrong
}
<
/Text
>
<
Text
style
=
{{
color
:
'black'
,
fontSize
:
15
}}
>
Timer
:
{
item
.
timer
}
<
/Text
>
<
Text
style
=
{{
color
:
'black'
,
fontSize
:
15
}}
>
Time
:
{
item
.
time
}
<
/Text
>
<
/View
>
<
/View
>
)).
reverse
()}
<
/ScrollView
>
<
/SafeAreaView
>
<
/ImageBackground
>
...
...
screens/quiz.js
View file @
417899a7
...
...
@@ -21,10 +21,15 @@ import Orientation from 'react-native-orientation';
import
*
as
RNFS
from
'react-native-fs'
;
import
Notes
from
'./data'
;
import
styles
from
'../style/style'
;
import
OtherClass
from
'./saveRecords'
;
//
import OtherClass from './saveRecords';
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
NOTESWHITE
=
[
{
name
:
'C1'
,
url
:
require
(
'../sound/c.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
keywordsList
=
[];
var
maxCount
=
5
;
var
imageN
=
''
;
var
indexN
=
0
;
var
stime
=
0
;
//var records = [];
class
Quiz
extends
React
.
Component
{
...
...
@@ -76,6 +81,8 @@ class Quiz extends React.Component {
showC
:
false
,
showW
:
false
,
showDone
:
false
,
maxCount
:
5
,
records
:
[],
};
}
...
...
@@ -108,7 +115,7 @@ class Quiz extends React.Component {
this
.
setState
({
keywordsList
:
list
});
};
onSubmit
=
()
=>
{
onSubmit
=
()
=>
{
if
(
this
.
state
.
name
.
includes
(
'C Major'
)
||
this
.
state
.
name
.
includes
(
'Bass Clef C Major'
))
{
this
.
ansCMajor
();
}
...
...
@@ -159,7 +166,7 @@ class Quiz extends React.Component {
ansCMajor
=
()
=>
{
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
({
showDone
:
true
});
this
.
handlerArgCall
((
this
.
state
.
correct
+
1
),
this
.
state
.
wrong
,
stime
);
...
...
@@ -173,7 +180,7 @@ class Quiz extends React.Component {
this
.
displayData
();
}
}
else
{
if
(
(
this
.
state
.
count
+
1
)
>
maxCount
)
{
if
(
(
this
.
state
.
count
+
1
)
>
this
.
state
.
maxCount
)
{
this
.
setState
({
wrong
:
this
.
state
.
wrong
+
1
});
this
.
setState
({
showDone
:
true
});
this
.
handlerArgCall
(
this
.
state
.
correct
,
(
this
.
state
.
wrong
+
1
),
stime
);
...
...
@@ -192,7 +199,7 @@ class Quiz extends React.Component {
ansDMajor
=
()
=>
{
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
({
showDone
:
true
});
this
.
handlerArgCall
((
this
.
state
.
correct
+
1
),
this
.
state
.
wrong
,
stime
);
...
...
@@ -206,7 +213,7 @@ class Quiz extends React.Component {
this
.
displayData
();
}
}
else
{
if
(
(
this
.
state
.
count
+
1
)
>
maxCount
)
{
if
(
(
this
.
state
.
count
+
1
)
>
this
.
state
.
maxCount
)
{
this
.
setState
({
wrong
:
this
.
state
.
wrong
+
1
});
this
.
setState
({
showDone
:
true
});
this
.
handlerArgCall
(
this
.
state
.
correct
,
(
this
.
state
.
wrong
+
1
),
stime
);
...
...
@@ -225,7 +232,7 @@ class Quiz extends React.Component {
ansEMajor
=
()
=>
{
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
({
showDone
:
true
});
this
.
handlerArgCall
((
this
.
state
.
correct
+
1
),
this
.
state
.
wrong
,
stime
);
...
...
@@ -239,7 +246,7 @@ class Quiz extends React.Component {
this
.
displayData
();
}
}
else
{
if
(
(
this
.
state
.
count
+
1
)
>
maxCount
)
{
if
(
(
this
.
state
.
count
+
1
)
>
this
.
state
.
maxCount
)
{
this
.
setState
({
wrong
:
this
.
state
.
wrong
+
1
});
this
.
setState
({
showDone
:
true
});
this
.
handlerArgCall
(
this
.
state
.
correct
,
(
this
.
state
.
wrong
+
1
),
stime
);
...
...
@@ -258,7 +265,7 @@ class Quiz extends React.Component {
ansFsMajor
=
()
=>
{
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
({
showDone
:
true
});
this
.
handlerArgCall
((
this
.
state
.
correct
+
1
),
this
.
state
.
wrong
,
stime
);
...
...
@@ -272,7 +279,7 @@ class Quiz extends React.Component {
this
.
displayData
();
}
}
else
{
if
(
(
this
.
state
.
count
+
1
)
>
maxCount
)
{
if
(
(
this
.
state
.
count
+
1
)
>
this
.
state
.
maxCount
)
{
this
.
setState
({
wrong
:
this
.
state
.
wrong
+
1
});
this
.
setState
({
showDone
:
true
});
this
.
handlerArgCall
(
this
.
state
.
correct
,
(
this
.
state
.
wrong
+
1
),
stime
);
...
...
@@ -289,9 +296,9 @@ class Quiz extends React.Component {
}
};
ansFMajor
=
()
=>
{
ansFMajor
=
()
=>
{
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
({
showDone
:
true
});
this
.
handlerArgCall
((
this
.
state
.
correct
+
1
),
this
.
state
.
wrong
,
stime
);
...
...
@@ -305,7 +312,7 @@ class Quiz extends React.Component {
this
.
displayData
();
}
}
else
{
if
(
(
this
.
state
.
count
+
1
)
>
maxCount
)
{
if
(
(
this
.
state
.
count
+
1
)
>
this
.
state
.
maxCount
)
{
this
.
setState
({
wrong
:
this
.
state
.
wrong
+
1
});
this
.
setState
({
showDone
:
true
});
this
.
handlerArgCall
(
this
.
state
.
correct
,
(
this
.
state
.
wrong
+
1
),
stime
);
...
...
@@ -324,7 +331,7 @@ class Quiz extends React.Component {
ansEbMajor
=
()
=>
{
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
({
showDone
:
true
});
this
.
handlerArgCall
((
this
.
state
.
correct
+
1
),
this
.
state
.
wrong
,
stime
);
...
...
@@ -338,7 +345,7 @@ class Quiz extends React.Component {
this
.
displayData
();
}
}
else
{
if
(
(
this
.
state
.
count
+
1
)
>
maxCount
)
{
if
(
(
this
.
state
.
count
+
1
)
>
this
.
state
.
maxCount
)
{
this
.
setState
({
wrong
:
this
.
state
.
wrong
+
1
});
this
.
setState
({
showDone
:
true
});
this
.
handlerArgCall
(
this
.
state
.
correct
,
(
this
.
state
.
wrong
+
1
),
stime
);
...
...
@@ -355,9 +362,9 @@ 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
(
(
this
.
state
.
count
+
1
)
>
maxCount
)
{
if
(
(
this
.
state
.
count
+
1
)
>
this
.
state
.
maxCount
)
{
this
.
setState
({
correct
:
this
.
state
.
correct
+
1
});
this
.
setState
({
showDone
:
true
});
this
.
handlerArgCall
((
this
.
state
.
correct
+
1
),
this
.
state
.
wrong
,
stime
);
...
...
@@ -371,7 +378,7 @@ class Quiz extends React.Component {
this
.
displayData
();
}
}
else
{
if
(
(
this
.
state
.
count
+
1
)
>
maxCount
)
{
if
(
(
this
.
state
.
count
+
1
)
>
this
.
state
.
maxCount
)
{
this
.
setState
({
wrong
:
this
.
state
.
wrong
+
1
});
this
.
setState
({
showDone
:
true
});
this
.
handlerArgCall
(
this
.
state
.
correct
,
(
this
.
state
.
wrong
+
1
),
stime
);
...
...
@@ -390,7 +397,7 @@ class Quiz extends React.Component {
ansGMajor
=
()
=>
{
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
({
showDone
:
true
});
this
.
handlerArgCall
((
this
.
state
.
correct
+
1
),
this
.
state
.
wrong
,
stime
);
...
...
@@ -404,7 +411,7 @@ class Quiz extends React.Component {
this
.
displayData
();
}
}
else
{
if
(
(
this
.
state
.
count
+
1
)
>
maxCount
)
{
if
(
(
this
.
state
.
count
+
1
)
>
this
.
state
.
maxCount
)
{
this
.
setState
({
wrong
:
this
.
state
.
wrong
+
1
});
this
.
setState
({
showDone
:
true
});
this
.
handlerArgCall
(
this
.
state
.
correct
,
(
this
.
state
.
wrong
+
1
),
stime
);
...
...
@@ -423,7 +430,7 @@ class Quiz extends React.Component {
ansAMajor
=
()
=>
{
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
({
showDone
:
true
});
this
.
handlerArgCall
((
this
.
state
.
correct
+
1
),
this
.
state
.
wrong
,
stime
);
...
...
@@ -437,7 +444,7 @@ class Quiz extends React.Component {
this
.
displayData
();
}
}
else
{
if
(
(
this
.
state
.
count
+
1
)
>
maxCount
)
{
if
(
(
this
.
state
.
count
+
1
)
>
this
.
state
.
maxCount
)
{
this
.
setState
({
wrong
:
this
.
state
.
wrong
+
1
});
this
.
setState
({
showDone
:
true
});
this
.
handlerArgCall
(
this
.
state
.
correct
,
(
this
.
state
.
wrong
+
1
),
stime
);
...
...
@@ -456,7 +463,7 @@ class Quiz extends React.Component {
ansBMajor
=
()
=>
{
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
({
showDone
:
true
});
this
.
handlerArgCall
((
this
.
state
.
correct
+
1
),
this
.
state
.
wrong
,
stime
);
...
...
@@ -470,7 +477,7 @@ class Quiz extends React.Component {
this
.
displayData
();
}
}
else
{
if
(
(
this
.
state
.
count
+
1
)
>
maxCount
)
{
if
(
(
this
.
state
.
count
+
1
)
>
this
.
state
.
maxCount
)
{
this
.
setState
({
wrong
:
this
.
state
.
wrong
+
1
});
this
.
setState
({
showDone
:
true
});
this
.
handlerArgCall
(
this
.
state
.
correct
,
(
this
.
state
.
wrong
+
1
),
stime
);
...
...
@@ -489,7 +496,7 @@ class Quiz extends React.Component {
ansCsMajor
=
()
=>
{
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
({
showDone
:
true
});
this
.
handlerArgCall
((
this
.
state
.
correct
+
1
),
this
.
state
.
wrong
,
stime
);
...
...
@@ -503,7 +510,7 @@ class Quiz extends React.Component {
this
.
displayData
();
}
}
else
{
if
(
(
this
.
state
.
count
+
1
)
>
maxCount
)
{
if
(
(
this
.
state
.
count
+
1
)
>
this
.
state
.
maxCount
)
{
this
.
setState
({
wrong
:
this
.
state
.
wrong
+
1
});
this
.
setState
({
showDone
:
true
});
this
.
handlerArgCall
(
this
.
state
.
correct
,
(
this
.
state
.
wrong
+
1
),
stime
);
...
...
@@ -522,7 +529,7 @@ class Quiz extends React.Component {
ansBbMajor
=
()
=>
{
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
({
showDone
:
true
});
this
.
handlerArgCall
((
this
.
state
.
correct
+
1
),
this
.
state
.
wrong
,
stime
);
...
...
@@ -536,7 +543,7 @@ class Quiz extends React.Component {
this
.
displayData
();
}
}
else
{
if
(
(
this
.
state
.
count
+
1
)
>
maxCount
)
{
if
(
(
this
.
state
.
count
+
1
)
>
this
.
state
.
maxCount
)
{
this
.
setState
({
wrong
:
this
.
state
.
wrong
+
1
});
this
.
setState
({
showDone
:
true
});
this
.
handlerArgCall
(
this
.
state
.
correct
,
(
this
.
state
.
wrong
+
1
),
stime
);
...
...
@@ -555,7 +562,7 @@ class Quiz extends React.Component {
ansAbMajor
=
()
=>
{
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
({
showDone
:
true
});
this
.
handlerArgCall
((
this
.
state
.
correct
+
1
),
this
.
state
.
wrong
,
stime
);
...
...
@@ -569,7 +576,7 @@ class Quiz extends React.Component {
this
.
displayData
();
}
}
else
{
if
(
(
this
.
state
.
count
+
1
)
>
maxCount
)
{
if
(
(
this
.
state
.
count
+
1
)
>
this
.
state
.
maxCount
)
{
this
.
setState
({
wrong
:
this
.
state
.
wrong
+
1
});
this
.
setState
({
showDone
:
true
});
this
.
handlerArgCall
(
this
.
state
.
correct
,
(
this
.
state
.
wrong
+
1
),
stime
);
...
...
@@ -588,7 +595,7 @@ class Quiz extends React.Component {
ansGbMajor
=
()
=>
{
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
({
showDone
:
true
});
this
.
handlerArgCall
((
this
.
state
.
correct
+
1
),
this
.
state
.
wrong
,
stime
);
...
...
@@ -602,7 +609,7 @@ class Quiz extends React.Component {
this
.
displayData
();
}
}
else
{
if
(
(
this
.
state
.
count
+
1
)
>
maxCount
)
{
if
(
(
this
.
state
.
count
+
1
)
>
this
.
state
.
maxCount
)
{
this
.
setState
({
wrong
:
this
.
state
.
wrong
+
1
});
this
.
setState
({
showDone
:
true
});
this
.
handlerArgCall
(
this
.
state
.
correct
,
(
this
.
state
.
wrong
+
1
),
stime
);
...
...
@@ -632,24 +639,28 @@ class Quiz extends React.Component {
}
';'
;
displayData
=
async
()
=>
{
RNFS
.
readFile
(
path
,
'ascii'
)
.
then
((
res
)
=>
{
this
.
setState
({
logbook
:
res
.
split
(
','
),
displayData
=
async
()
=>
{
this
.
setState
({
records
:
[]});
try
{
const
value
=
await
AsyncStorage
.
getItem
(
'@notes_key'
);
console
.
log
(
JSON
.
parse
(
value
));
if
(
value
!==
null
)
{
// We have data!!
this
.
setState
({
logbook
:
JSON
.
parse
(
value
),
});
console
.
log
(
this
.
state
.
logbook
);
RNFS
.
readFile
(
path1
,
'ascii'
)
console
.
log
(
this
.
state
.
logbook
);
RNFS
.
readFile
(
path1
,
'ascii'
)
.
then
((
ccc
)
=>
{
console
.
log
(
'has notes has counter'
);
console
.
log
(
ccc
);
imageN
=
Math
.
floor
(
Math
.
random
()
*
this
.
state
.
logbook
.
length
);
this
.
setState
({
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
);
maxCount
=
ccc
;
})
.
catch
((
err
)
=>
{
console
.
log
(
err
.
message
,
err
.
code
);
...
...
@@ -657,13 +668,14 @@ class Quiz extends React.Component {
imageN
=
Math
.
floor
(
Math
.
random
()
*
this
.
state
.
logbook
.
length
);
this
.
setState
({
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
;
})
.
catch
((
err
)
=>
{
console
.
log
(
err
.
message
,
err
.
code
);
}
else
{
RNFS
.
readFile
(
path1
,
'ascii'
)
.
then
((
res
)
=>
{
console
.
log
(
'no notes has counter'
);
...
...
@@ -671,8 +683,8 @@ class Quiz extends React.Component {
indexN
=
imageN
;
this
.
setState
({
name
:
Notes
[
indexN
].
name
,
maxCount
:
res
,
});
maxCount
=
res
;
//console.log(res);
})
.
catch
(()
=>
{
...
...
@@ -682,14 +694,58 @@ class Quiz extends React.Component {
indexN
=
imageN
;
this
.
setState
({
name
:
Notes
[
indexN
].
name
,
maxCount
:
5
,
});
maxCount
=
5
;
});
});
};
}
}
catch
(
error
)
{
// Error retrieving data
}
};
handlerArgCall
=
(
correct
,
wrong
,
timer
)
=>
{
new
OtherClass
().
saveRecord
(
correct
,
wrong
,
timer
);
handlerArgCall
=
async
(
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
...
...
@@ -822,7 +878,7 @@ class Quiz extends React.Component {
<
View
style
=
{
styles
.
c1
}
>
<
View
style
=
{
styles
.
cc1
}
>
<
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
secs
start
=
{
this
.
state
.
start
}
...
...
@@ -860,7 +916,7 @@ class Quiz extends React.Component {
<
Button
title
=
"SUBMIT"
color
=
"#E07EF9"
onPress
=
{
this
.
onSubmit
}
/
>
<
/View
>
<
/View
>
<
Image
style
=
{
styles
.
logo
}
source
=
{
Notes
[
indexN
].
image
}
/
>
<
Image
style
=
{
styles
.
logo
}
source
=
{
Notes
[
indexN
].
image
}
/
>
<
/View
>
<
View
style
=
{
styles
.
c2
}
>
{
NOTESWHITE
.
map
((
item
,
id
)
=>
(
...
...
screens/saveRecords.js
View file @
417899a7
/* eslint-disable prettier/prettier */
/*This is an Example of Calling Other Class Function in React Native*/
import
{
Component
}
from
'react'
;
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'
);
var
records
=
[];
//
var records = [];
class
OtherClass
extends
Component
{
saveRecord
=
async
(
correct
,
wrong
,
stime
)
=>
{
...
...
@@ -19,38 +18,19 @@ class OtherClass extends Component {
day
:
day
,
};
try
{
try
{
const
value
=
await
AsyncStorage
.
getItem
(
'@storage_key'
);
if
(
value
!==
null
)
{
// We have data!!
console
.
log
(
JSON
.
parse
(
value
));
records
.
push
(
JSON
.
parse
(
value
));
records
.
push
(
JSON
.
parse
(
obj
));
//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
);
});
// console.log(JSON.parse(value));
this
.
setState
({
logbook
:
JSON
.
parse
(
value
)
});
console
.
log
(
this
.
state
.
logbook
.
length
);
}
}
catch
(
error
)
{
// Error retrieving data
}
};
}
...
...
screens/settings.js
View file @
417899a7
...
...
@@ -17,8 +17,9 @@ import Orientation from 'react-native-orientation';
import
Notes
from
'./data'
;
import
*
as
RNFS
from
'react-native-fs'
;
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'
;
...
...
@@ -76,31 +77,56 @@ export default class Settings extends React.Component {
list
.
push
(
keyword
);
}
this
.
setState
({
listN
:
list
});
this
.
saveData
(
this
.
state
.
listN
);
this
.
displayData
();
if
(
this
.
state
.
listN
!==
null
){
this
.
setState
({
listN
:
list
});
this
.
saveData
(
this
.
state
.
listN
);
}
else
{
this
.
setState
({
listN
:
notes
});
this
.
saveData2
(
this
.
state
.
listN
);
}
this
.
_retrieveData
();
// console.log(notes);
};
saveData
=
async
()
=>
{
RNFS
.
writeFile
(
path
,
JSON
.
stringify
(
this
.
state
.
listN
),
'utf8'
,)
.
then
((
success
)
=>
{
console
.
log
(
JSON
.
stringify
(
this
.
state
.
listN
));
})
.
catch
((
err
)
=>
{
console
.
log
(
err
.
message
);
});
AsyncStorage
.
setItem
(
'@notes_key'
,
JSON
.
stringify
(
this
.
state
.
listN
),
(
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
);
});
};
displayData
=
async
()
=>
{
RNFS
.
readFile
(
path
,
'ascii'
)
.
then
((
res
)
=>
{
// console.log(JSON.stringify(res));
})
.
catch
((
err
)
=>
{
console
.
log
(
err
.
message
,
err
.
code
);
saveData
=
async
()
=>
{
AsyncStorage
.
setItem
(
'@notes_key'
,
JSON
.
stringify
(
this
.
state
.
listN
),
(
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
);
});
};
_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
()
=>
{
RNFS
.
writeFile
(
path1
,
JSON
.
stringify
(
counter
),
'utf8'
,)
.
then
((
success
)
=>
{
...
...
@@ -127,13 +153,6 @@ export default class Settings extends React.Component {
Orientation
.
lockToPortrait
();
// console.log(notes.length);
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
=>
{
console
.
log
(
'delete'
);
RNFS
.
scanFile
(
path1
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment