-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
72 lines (68 loc) · 1.62 KB
/
App.js
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
import React from "react";
import { Container } from "semantic-ui-react";
import { StateProvider } from "./store";
import ResultTable from "./ResultTable";
import SearchBar from "./SearchBar";
import styles from "./Styles";
const { StyledGrid } = styles;
function App() {
const initialState = {
data: {
searchResults: []
},
ui: {
hasError: false,
isDetails: false,
isLoading: false,
selectedId: null,
query: ""
}
};
const reducer = (state, action) => {
switch (action.type) {
case "newSearchStart":
return {
data: {
searchResults: action.newQuery ? state.data.searchResults : []
},
ui: action.newUi
};
case "newSearchSuccess":
return {
data: { searchResults: action.searchResults },
ui: {
...state.ui,
hasError: action.hasError,
isLoading: action.isLoading
}
};
case "newSearchError":
return {
ui: {
...state.ui,
errorMsg: action.errorMsg,
isLoading: action.isLoading
},
data: { ...state.data }
};
case "updateId":
return {
ui: { ...state.ui, selectedId: action.id, isDetails: true },
data: { ...state.data }
};
default:
return state;
}
};
return (
<StateProvider initialState={initialState} reducer={reducer}>
<Container>
<StyledGrid>
<SearchBar />
<ResultTable />
</StyledGrid>
</Container>
</StateProvider>
);
}
export default App;