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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
import { applyMiddleware, compose, combineReducers, createStore } from 'redux'
import { connectRouter, routerMiddleware } from 'connected-react-router'
import { createBrowserHistory } from 'history'
import thunk from 'redux-thunk'
import * as types from './types'
const initialState = () => ({
query: {
image: null,
blob: null,
url: "",
threshold: types.SIMILAR_THRESHOLD,
searchType: 'file',
thresholdChanged: false,
saveIfNotFound: false,
},
api: {
similar: {}
},
})
export default function apiReducer(state = initialState(), action) {
// console.log(action.type, action)
switch (action.type) {
case types.api.loading:
return {
...state,
[action.tag]: { loading: true },
}
case types.api.loaded:
return {
...state,
[action.tag]: action.data,
}
case types.api.error:
return {
...state,
[action.tag]: { error: action.error },
}
case types.api.updateQuery:
return {
...state,
query: {
...state.query,
...action.state,
},
}
default:
return state
}
}
const rootReducer = combineReducers({
api: apiReducer,
})
function configureStore(initialState = {}, history) {
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose
const store = createStore(
connectRouter(history)(rootReducer), // new root reducer with router state
initialState,
composeEnhancers(
applyMiddleware(
thunk,
routerMiddleware(history)
),
),
)
return store
}
const history = createBrowserHistory()
const store = configureStore({}, history)
export { store, history }
|