search.js
1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import {sendSearch} from '../lib/api'
import {readTest} from '../lib/readTest';
const CHANGE = 'search/CHANGE';
const SUCCESS = 'search/SUCCESS';
const FAILURE = 'search/FAILURE';
const START = 'search/START';
export const change = (text) => ({
type: CHANGE,
text,
})
export const submit = (text) => async (dispatch) => {
dispatch( {type:START});
try{
/*const response = await sendSearch(text);*/
const response = await readTest(); // 테스트용입니당~
//dispatch( { type:SUCCESS, result:response }
setTimeout(()=>dispatch( { type:SUCCESS, result:response }),500); // 셋타임아웃도 테스트용
}
catch(err){
dispatch({ type:FAILURE, result:response })
}
}
const initialState = {
query: '',
result: {
return_data: {
searchResults: []
}
},
isLoading: false,
};
export default ToggleLoading = (state = initialState, action) => {
switch (action.type) {
case CHANGE:
return {...state, query: action.text};
case SUCCESS:
return {...state, isLoading:false,result: action.result};
case FAILURE:
return {...state, isLoading:false};
case START:
return {...state, query:'',isLoading:true}
default:
return state;
}
}