bluejoyq

add date db for record

...@@ -6,7 +6,7 @@ import {load } from '../../reducers/search'; ...@@ -6,7 +6,7 @@ import {load } from '../../reducers/search';
6 import PromptSearchRate from '../PromptSearch/PromptSearchRate'; 6 import PromptSearchRate from '../PromptSearch/PromptSearchRate';
7 7
8 8
9 -const RateLine = ({load,pastScore }) => { 9 +const RateLine = ({load,pastRecords }) => {
10 useEffect(()=>{ 10 useEffect(()=>{
11 const get = async () => { 11 const get = async () => {
12 await load(); 12 await load();
...@@ -16,16 +16,18 @@ const RateLine = ({load,pastScore }) => { ...@@ -16,16 +16,18 @@ const RateLine = ({load,pastScore }) => {
16 16
17 return ( 17 return (
18 <Surface style={styles.surface}> 18 <Surface style={styles.surface}>
19 - {pastScore.length ? 19 + {pastRecords.length ?
20 <> 20 <>
21 - <Text style={styles.info}>최근 점수</Text> 21 + <Text style={styles.info}>점수 변화</Text>
22 <View style={styles.scoreContainer}> 22 <View style={styles.scoreContainer}>
23 - {pastScore.map((elem,index)=> ( 23 + {pastRecords.map((past,index)=> (
24 - <Text key={index} style={styles.score}>{elem}</Text> 24 + <View key={index} style={styles.past}>
25 + <Text style={styles.score}>{past.score}</Text>
26 + <Text style={styles.date}>{past.date.substring(5,7)+'월 '+past.date.substring(8,10)+'일'}</Text>
27 + </View>
25 ))} 28 ))}
26 </View> 29 </View>
27 - <View style={styles.detail}><Text style={styles.new}>최근</Text><Text></Text></View> 30 + <Text>최근 점수 추세</Text>
28 - <Text>당신의 최근 점수 트렌드입니다</Text>
29 </> 31 </>
30 : <PromptSearchRate /> 32 : <PromptSearchRate />
31 } 33 }
...@@ -49,7 +51,7 @@ const styles = StyleSheet.create({ ...@@ -49,7 +51,7 @@ const styles = StyleSheet.create({
49 info:{ 51 info:{
50 fontSize:25, 52 fontSize:25,
51 fontWeight:'bold', 53 fontWeight:'bold',
52 - marginBottom: 15 54 + marginBottom: 5
53 }, 55 },
54 score:{ 56 score:{
55 fontSize:20 57 fontSize:20
...@@ -59,25 +61,23 @@ const styles = StyleSheet.create({ ...@@ -59,25 +61,23 @@ const styles = StyleSheet.create({
59 justifyContent: 'space-around', 61 justifyContent: 'space-around',
60 width:'100%' 62 width:'100%'
61 }, 63 },
62 - detail:{ 64 + data:{
63 - width:'100%', 65 + fontSize:13,
64 - justifyContent:'space-around', 66 + textAlign:'center',
65 -
66 }, 67 },
67 - new:{ 68 + past:{
68 - fontSize: 18, 69 + alignItems:'center',
69 - marginLeft: 20, 70 + marginBottom:5
70 - color:'#995432'
71 } 71 }
72 }); 72 });
73 73
74 -const RateLineContainer = ( {load,pastScore } ) => ( 74 +const RateLineContainer = ( {load,pastRecords } ) => (
75 - <RateLine load={load} pastScore={pastScore} /> 75 + <RateLine load={load} pastRecords={pastRecords} />
76 ); 76 );
77 77
78 export default connect( 78 export default connect(
79 ({search})=>({ 79 ({search})=>({
80 - pastScore:search.pastScore 80 + pastRecords:search.pastRecords
81 }), 81 }),
82 { 82 {
83 load 83 load
......
...@@ -3,14 +3,14 @@ import { openDatabase,transaction,executeSql } from 'expo-sqlite'; ...@@ -3,14 +3,14 @@ import { openDatabase,transaction,executeSql } from 'expo-sqlite';
3 3
4 4
5 let sqlite = {}; 5 let sqlite = {};
6 -let db = openDatabase("score.db"); 6 +let db = openDatabase("database.db");
7 db.transaction( ( tx ) => { 7 db.transaction( ( tx ) => {
8 - tx.executeSql(`CREATE TABLE IF NOT EXISTS district (id int AUTO_INCREMENT,score int, PRIMARY KEY (id));`); 8 + tx.executeSql(`CREATE TABLE IF NOT EXISTS district (id int AUTO_INCREMENT,score int,date text, PRIMARY KEY (id));`);
9 }); 9 });
10 10
11 sqlite.insert = ( score ) => { 11 sqlite.insert = ( score ) => {
12 db.transaction( ( tx ) => { 12 db.transaction( ( tx ) => {
13 - tx.executeSql( `INSERT INTO district (score) VALUES (${score});` ); 13 + tx.executeSql( `INSERT INTO district (score, date) VALUES (${score}, date('now'));` );
14 }); 14 });
15 } 15 }
16 16
...@@ -18,7 +18,7 @@ sqlite.insert = ( score ) => { ...@@ -18,7 +18,7 @@ sqlite.insert = ( score ) => {
18 sqlite.select = ( ) => { 18 sqlite.select = ( ) => {
19 return new Promise( (resolve ,rejects)=>{ 19 return new Promise( (resolve ,rejects)=>{
20 db.transaction( ( tx ) => { 20 db.transaction( ( tx ) => {
21 - tx.executeSql( `SELECT score FROM district WHERE 1 ORDER BY id DESC LIMIT 5;`, [], ( tx, result ) => { 21 + tx.executeSql( `SELECT score, date FROM district WHERE 1 ORDER BY id DESC LIMIT 5;`, [], ( tx, result ) => {
22 resolve(result.rows._array); 22 resolve(result.rows._array);
23 }, ( err )=>{ 23 }, ( err )=>{
24 console.log("err -> ",err); 24 console.log("err -> ",err);
......
...@@ -16,9 +16,8 @@ export const change = (text) => ({ ...@@ -16,9 +16,8 @@ export const change = (text) => ({
16 }) 16 })
17 17
18 export const load = () => async (dispatch) =>{ 18 export const load = () => async (dispatch) =>{
19 - let past = await sqlite.select(); 19 + let pastRecords = await sqlite.select();
20 - past = await past.map( elem => elem.score ); 20 + dispatch({type:LOAD, pastRecords: pastRecords})
21 - dispatch({type:LOAD, past: past})
22 } 21 }
23 22
24 export const submit = (text) => async (dispatch) => { 23 export const submit = (text) => async (dispatch) => {
...@@ -36,18 +35,17 @@ export const submit = (text) => async (dispatch) => { ...@@ -36,18 +35,17 @@ export const submit = (text) => async (dispatch) => {
36 },10000); 35 },10000);
37 36
38 try{ 37 try{
39 - //const response = await readTest() 38 + const response = await readTest()
40 - const response = await sendSearch(text.nativeEvent.text); 39 + //const response = await sendSearch(text.nativeEvent.text);
41 40
42 // 에러시 error throw 41 // 에러시 error throw
43 if(response.return_code == -1){throw new Error(response.error_code)}; 42 if(response.return_code == -1){throw new Error(response.error_code)};
44 43
45 let tempScore = scoring(response.return_data); 44 let tempScore = scoring(response.return_data);
46 await sqlite.insert(tempScore.full); 45 await sqlite.insert(tempScore.full);
47 - let past = await sqlite.select(); 46 + let pastRecords = await sqlite.select();
48 - past = past.map( elem => elem.score );
49 47
50 - dispatch( { type:SUCCESS, result:response, past: past, score:tempScore}) 48 + dispatch( { type:SUCCESS, result:response, pastRecords: pastRecords, score:tempScore})
51 49
52 clearTimeout(timer); 50 clearTimeout(timer);
53 } 51 }
...@@ -73,7 +71,7 @@ const initialState = { ...@@ -73,7 +71,7 @@ const initialState = {
73 }, 71 },
74 score : {}, 72 score : {},
75 isLoading: false, 73 isLoading: false,
76 - pastScore: [0,0,0,0,0,0], 74 + pastRecords: [],
77 }; 75 };
78 76
79 export default ToggleLoading = (state = initialState, action) => { 77 export default ToggleLoading = (state = initialState, action) => {
...@@ -82,13 +80,13 @@ export default ToggleLoading = (state = initialState, action) => { ...@@ -82,13 +80,13 @@ export default ToggleLoading = (state = initialState, action) => {
82 return {...state, query: action.text}; 80 return {...state, query: action.text};
83 case SUCCESS: 81 case SUCCESS:
84 return {...state, isLoading:false, score: action.score, 82 return {...state, isLoading:false, score: action.score,
85 - result: action.result, pastScore: action.past}; 83 + result: action.result, pastRecords: action.pastRecords};
86 case FAILURE: 84 case FAILURE:
87 return {...state, isLoading:false}; 85 return {...state, isLoading:false};
88 case START: 86 case START:
89 return {...state, query:'',isLoading:true} 87 return {...state, query:'',isLoading:true}
90 case LOAD: 88 case LOAD:
91 - return {...state,pastScore: action.past} 89 + return {...state,pastRecords: action.pastRecords}
92 default: 90 default:
93 return state; 91 return state;
94 } 92 }
......