-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstate.jsx
More file actions
65 lines (47 loc) · 1.67 KB
/
Copy pathstate.jsx
File metadata and controls
65 lines (47 loc) · 1.67 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
const initState = {
projects: [],
};
export const reducer = (state = initState, action) => {
switch (action.type) {
case 'PROJECTS_OPEN_POPUP':
return { ...state, popupOpen: true };
case 'PROJECTS_CLOSE_POPUP':
return { ...state, popupOpen: false };
case 'SET_PROJECTS':
return { ...state, projects: action.payload };
default:
return state;
}
};
import http from 'utils/http';
const setProjects = (projects) => ({ type: 'SET_PROJECTS', payload: projects });
const loadProjects = () => (dispatch) =>
http.get('/api/projects').then(json => dispatch(setProjects(json)));
// Publick
export const showPage = () => (dispatch) => dispatch(loadProjects());
export const removeProject = ({ id }) => (dispatch) =>
http.del(`/api/projects/${id}`).then(() => dispatch(loadProjects()));
import * as popup from 'reduxApp/modules/popup';
import { wrapDispatch as wd } from 'multireducer';
function getActions(actions, name) {
const wdActions = {};
for (const key in actions) {
if (actions[key]) {
wdActions[key] = (...arg) =>
(dispatch) => wd(dispatch, 'addProject')(actions[key](arg));
}
}
return wdActions;
}
const _addProject = getActions(popup, 'addProject');
export const openPopup = _addProject.open;
export const closePopup = _addProject.close;
export const addProject = (title, userIds) => (dispatch) =>
http.post('/api/projects', { title })
.then(payload => {
dispatch({
type: 'ADD_PROJECT',
payload,
});
dispatch(closePopup());
});