bluejoyq

add date db for record

......@@ -6,7 +6,7 @@ import {load } from '../../reducers/search';
import PromptSearchRate from '../PromptSearch/PromptSearchRate';
const RateLine = ({load,pastScore }) => {
const RateLine = ({load,pastRecords }) => {
useEffect(()=>{
const get = async () => {
await load();
......@@ -16,16 +16,18 @@ const RateLine = ({load,pastScore }) => {
return (
<Surface style={styles.surface}>
{pastScore.length ?
{pastRecords.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: 15
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,pastScore } ) => (
<RateLine load={load} pastScore={pastScore} />
const RateLineContainer = ( {load,pastRecords } ) => (
<RateLine load={load} pastRecords={pastRecords} />
);
export default connect(
({search})=>({
pastScore:search.pastScore
pastRecords:search.pastRecords
}),
{
load
......
......@@ -3,14 +3,14 @@ import { openDatabase,transaction,executeSql } from 'expo-sqlite';
let sqlite = {};
let db = openDatabase("score.db");
let db = openDatabase("database.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);
......
......@@ -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, pastRecords: pastRecords, score:tempScore})
clearTimeout(timer);
}
......@@ -73,7 +71,7 @@ const initialState = {
},
score : {},
isLoading: false,
pastScore: [0,0,0,0,0,0],
pastRecords: [],
};
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, pastScore: action.past};
result: action.result, pastRecords: action.pastRecords};
case FAILURE:
return {...state, isLoading:false};
case START:
return {...state, query:'',isLoading:true}
case LOAD:
return {...state,pastScore: action.past}
return {...state,pastRecords: action.pastRecords}
default:
return state;
}
......