Toggle navigation
Toggle navigation
This project
Loading...
Sign in
김서영
/
searchGuide
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
bluejoyq
2019-12-07 15:34:46 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
d4924fb6f70cadca981464489098cb15d7cffbcd
d4924fb6
1 parent
3431812d
add date db for record
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
34 deletions
searchGuide/components/RateLine/RateLine.js
searchGuide/lib/sqlite.js
searchGuide/reducers/search.js
searchGuide/components/RateLine/RateLine.js
View file @
d4924fb
...
...
@@ -6,7 +6,7 @@ import {load } from '../../reducers/search';
import
PromptSearchRate
from
'../PromptSearch/PromptSearchRate'
;
const
RateLine
=
({
load
,
past
Score
})
=>
{
const
RateLine
=
({
load
,
past
Records
})
=>
{
useEffect
(()
=>
{
const
get
=
async
()
=>
{
await
load
();
...
...
@@ -16,16 +16,18 @@ const RateLine = ({load,pastScore }) => {
return
(
<
Surface
style
=
{
styles
.
surface
}
>
{
past
Score
.
length
?
{
past
Records
.
length
?
<>
<
Text
style
=
{
styles
.
info
}
>
최근
점수
<
/Text
>
<
Text
style
=
{
styles
.
info
}
>
점수
변화
<
/Text
>
<
View
style
=
{
styles
.
scoreContainer
}
>
{
pastScore
.
map
((
elem
,
index
)
=>
(
<
Text
key
=
{
index
}
style
=
{
styles
.
score
}
>
{
elem
}
<
/Text
>
{
pastRecords
.
map
((
past
,
index
)
=>
(
<
View
key
=
{
index
}
style
=
{
styles
.
past
}
>
<
Text
style
=
{
styles
.
score
}
>
{
past
.
score
}
<
/Text
>
<
Text
style
=
{
styles
.
date
}
>
{
past
.
date
.
substring
(
5
,
7
)
+
'월 '
+
past
.
date
.
substring
(
8
,
10
)
+
'일'
}
<
/Text
>
<
/View
>
))}
<
/View
>
<
View
style
=
{
styles
.
detail
}
><
Text
style
=
{
styles
.
new
}
>
최근
<
/Text><Text></
Text
><
/View
>
<
Text
>
당신의
최근
점수
트렌드입니다
<
/Text
>
<
Text
>
최근
점수
추세
<
/Text
>
<
/
>
:
<
PromptSearchRate
/>
}
...
...
@@ -49,7 +51,7 @@ const styles = StyleSheet.create({
info
:{
fontSize
:
25
,
fontWeight
:
'bold'
,
marginBottom
:
1
5
marginBottom
:
5
},
score
:{
fontSize
:
20
...
...
@@ -59,25 +61,23 @@ const styles = StyleSheet.create({
justifyContent
:
'space-around'
,
width
:
'100%'
},
detail
:{
width
:
'100%'
,
justifyContent
:
'space-around'
,
data
:{
fontSize
:
13
,
textAlign
:
'center'
,
},
new
:{
fontSize
:
18
,
marginLeft
:
20
,
color
:
'#995432'
past
:{
alignItems
:
'center'
,
marginBottom
:
5
}
});
const
RateLineContainer
=
(
{
load
,
past
Score
}
)
=>
(
<
RateLine
load
=
{
load
}
past
Score
=
{
pastScore
}
/
>
const
RateLineContainer
=
(
{
load
,
past
Records
}
)
=>
(
<
RateLine
load
=
{
load
}
past
Records
=
{
pastRecords
}
/
>
);
export
default
connect
(
({
search
})
=>
({
past
Score
:
search
.
pastScore
past
Records
:
search
.
pastRecords
}),
{
load
...
...
searchGuide/lib/sqlite.js
View file @
d4924fb
...
...
@@ -3,14 +3,14 @@ import { openDatabase,transaction,executeSql } from 'expo-sqlite';
let
sqlite
=
{};
let
db
=
openDatabase
(
"
scor
e.db"
);
let
db
=
openDatabase
(
"
databas
e.db"
);
db
.
transaction
(
(
tx
)
=>
{
tx
.
executeSql
(
`CREATE TABLE IF NOT EXISTS district (id int AUTO_INCREMENT,score int, PRIMARY KEY (id));`
);
tx
.
executeSql
(
`CREATE TABLE IF NOT EXISTS district (id int AUTO_INCREMENT,score int,
date text,
PRIMARY KEY (id));`
);
});
sqlite
.
insert
=
(
score
)
=>
{
db
.
transaction
(
(
tx
)
=>
{
tx
.
executeSql
(
`INSERT INTO district (score
) VALUES (
${
score
}
);`
);
tx
.
executeSql
(
`INSERT INTO district (score
, date) VALUES (
${
score
}
, date('now')
);`
);
});
}
...
...
@@ -18,7 +18,7 @@ sqlite.insert = ( score ) => {
sqlite
.
select
=
(
)
=>
{
return
new
Promise
(
(
resolve
,
rejects
)
=>
{
db
.
transaction
(
(
tx
)
=>
{
tx
.
executeSql
(
`SELECT score FROM district WHERE 1 ORDER BY id DESC LIMIT 5;`
,
[],
(
tx
,
result
)
=>
{
tx
.
executeSql
(
`SELECT score
, date
FROM district WHERE 1 ORDER BY id DESC LIMIT 5;`
,
[],
(
tx
,
result
)
=>
{
resolve
(
result
.
rows
.
_array
);
},
(
err
)
=>
{
console
.
log
(
"err -> "
,
err
);
...
...
searchGuide/reducers/search.js
View file @
d4924fb
...
...
@@ -16,9 +16,8 @@ export const change = (text) => ({
})
export
const
load
=
()
=>
async
(
dispatch
)
=>
{
let
past
=
await
sqlite
.
select
();
past
=
await
past
.
map
(
elem
=>
elem
.
score
);
dispatch
({
type
:
LOAD
,
past
:
past
})
let
pastRecords
=
await
sqlite
.
select
();
dispatch
({
type
:
LOAD
,
pastRecords
:
pastRecords
})
}
export
const
submit
=
(
text
)
=>
async
(
dispatch
)
=>
{
...
...
@@ -36,18 +35,17 @@ export const submit = (text) => async (dispatch) => {
},
10000
);
try
{
//
const response = await readTest()
const
response
=
await
sendSearch
(
text
.
nativeEvent
.
text
);
const
response
=
await
readTest
()
//
const response = await sendSearch(text.nativeEvent.text);
// 에러시 error throw
if
(
response
.
return_code
==
-
1
){
throw
new
Error
(
response
.
error_code
)};
let
tempScore
=
scoring
(
response
.
return_data
);
await
sqlite
.
insert
(
tempScore
.
full
);
let
past
=
await
sqlite
.
select
();
past
=
past
.
map
(
elem
=>
elem
.
score
);
let
pastRecords
=
await
sqlite
.
select
();
dispatch
(
{
type
:
SUCCESS
,
result
:
response
,
past
:
past
,
score
:
tempScore
})
dispatch
(
{
type
:
SUCCESS
,
result
:
response
,
past
Records
:
pastRecords
,
score
:
tempScore
})
clearTimeout
(
timer
);
}
...
...
@@ -73,7 +71,7 @@ const initialState = {
},
score
:
{},
isLoading
:
false
,
past
Score
:
[
0
,
0
,
0
,
0
,
0
,
0
],
past
Records
:
[
],
};
export
default
ToggleLoading
=
(
state
=
initialState
,
action
)
=>
{
...
...
@@ -82,13 +80,13 @@ export default ToggleLoading = (state = initialState, action) => {
return
{...
state
,
query
:
action
.
text
};
case
SUCCESS
:
return
{...
state
,
isLoading
:
false
,
score
:
action
.
score
,
result
:
action
.
result
,
past
Score
:
action
.
past
};
result
:
action
.
result
,
past
Records
:
action
.
pastRecords
};
case
FAILURE
:
return
{...
state
,
isLoading
:
false
};
case
START
:
return
{...
state
,
query
:
''
,
isLoading
:
true
}
case
LOAD
:
return
{...
state
,
past
Score
:
action
.
past
}
return
{...
state
,
past
Records
:
action
.
pastRecords
}
default
:
return
state
;
}
...
...
Please
register
or
login
to post a comment