-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
79 lines (73 loc) · 1.97 KB
/
index.js
File metadata and controls
79 lines (73 loc) · 1.97 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
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
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import { Provider } from 'react-redux';
import { createStore } from 'redux';
import { FilterOptions } from './search/filters';
const initialState = {
filteredListings: [],
listings: [],
isSearching: false,
filter: 0,
q: ''
};
const resultsReducer = (state, action) => {
switch(action.type) {
case 'search-results':
case 'filter':
const { filter } = state;
return {
...state,
filteredListings: state.listings
.filter(l => filter === FilterOptions.SOLD ? l.sold : (filter === FilterOptions.LIVE ? !l.sold : true))
};
case 'clear-listings':
return {
...state,
filteredListings: []
};
default:
return state;
}
};
const reducer = (state = initialState, action) => {
switch (action.type) {
case 'search-input':
return {
...state,
q: action.value
};
case 'search-start':
return {
...state,
isSearching: true
};
case 'filter':
return resultsReducer({
...state,
filter: action.value
}, action);
case 'search-results':
return resultsReducer({
...state,
listings: action.value,
isSearching: false
}, action);
case 'clear-listings':
return resultsReducer({
...state,
listings: [],
q: ''
}, action);
default:
return state;
}
};
const store = createStore(reducer);
const Root = () => (
<Provider store={store}>
<App />
</Provider>
);
ReactDOM.render(<Root />, document.getElementById('root'));