Skip to content

Commit 981d71c

Browse files
committed
merging with child sort panel
2 parents 6183be7 + 9d33400 commit 981d71c

File tree

8 files changed

+524
-61
lines changed

8 files changed

+524
-61
lines changed

src/actions/components.js

Lines changed: 262 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,262 @@
1+
import {
2+
LOAD_INIT_DATA,
3+
ADD_COMPONENT,
4+
ADD_CHILD,
5+
DELETE_CHILD,
6+
UPDATE_COMPONENT,
7+
DELETE_COMPONENT,
8+
CHANGE_FOCUS_COMPONENT,
9+
CHANGE_FOCUS_CHILD,
10+
CHANGE_COMPONENT_FOCUS_CHILD,
11+
UPDATE_CHILDREN,
12+
REASSIGN_PARENT,
13+
SET_SELECTABLE_PARENTS,
14+
EXPORT_FILES,
15+
EXPORT_FILES_SUCCESS,
16+
EXPORT_FILES_ERROR,
17+
HANDLE_CLOSE,
18+
HANDLE_TRANSFORM,
19+
CREATE_APPLICATION,
20+
CREATE_APPLICATION_SUCCESS,
21+
CREATE_APPLICATION_ERROR,
22+
MOVE_TO_BOTTOM,
23+
MOVE_TO_TOP,
24+
OPEN_EXPANSION_PANEL,
25+
DELETE_PROP,
26+
ADD_PROP,
27+
DELETE_ALL_DATA,
28+
CHANGE_IMAGE_PATH,
29+
UPDATE_HTML_ATTR,
30+
UPDATE_CHILDREN_SORT,
31+
} from '../actionTypes/index';
32+
33+
import { loadState } from '../localStorage';
34+
35+
import createFiles from '../utils/createFiles.util';
36+
import createApplicationUtil from '../utils/createApplication.util';
37+
38+
export const loadInitData = () => (dispatch) => {
39+
loadState().then(data => dispatch({
40+
type: LOAD_INIT_DATA,
41+
payload: {
42+
data: data ? data.workspace : {},
43+
},
44+
}));
45+
};
46+
47+
// export const updateChildren = ({ parentIds, childIndex, childId }) => ({
48+
// type: UPDATE_CHILDREN,
49+
// payload: {
50+
// parentIds,
51+
// childIndex,
52+
// childId,
53+
// },
54+
// });
55+
56+
// export const parentReassignment = ({ index, id, parentIds }) => ({
57+
// type: REASSIGN_PARENT,
58+
// payload: {
59+
// index,
60+
// id,
61+
// parentIds,
62+
// },
63+
// });
64+
65+
export const addComponent = ({ title }) => (dispatch) => {
66+
dispatch({ type: ADD_COMPONENT, payload: { title } });
67+
};
68+
69+
export const addChild = ({ title, childType, HTMLInfo }) => (dispatch) => {
70+
dispatch({ type: ADD_CHILD, payload: { title, childType, HTMLInfo } });
71+
};
72+
73+
export const deleteChild = ({}) => (dispatch) => {
74+
// with no payload, it will delete focusd child
75+
dispatch({ type: DELETE_CHILD, payload: {} });
76+
};
77+
78+
export const deleteComponent = ({ componentId, stateComponents }) => (dispatch) => {
79+
// find all places where the "to be delted" is a child and do what u gotta do
80+
stateComponents.forEach((parent) => {
81+
parent.childrenArray.filter(child => child.childComponentId === componentId).forEach((child) => {
82+
dispatch({
83+
type: DELETE_CHILD,
84+
payload: {
85+
parentId: parent.id,
86+
childId: child.childId,
87+
calledFromDeleteComponent: true,
88+
},
89+
});
90+
});
91+
});
92+
93+
// change focus to APp
94+
dispatch({ type: CHANGE_FOCUS_COMPONENT, payload: { title: 'App' } });
95+
// after taking care of the children delete the component
96+
dispatch({ type: DELETE_COMPONENT, payload: { componentId } });
97+
};
98+
99+
// export const updateComponent = ({
100+
// id,
101+
// index,
102+
// newParentId = null,
103+
// color = null,
104+
// stateful = null,
105+
// }) => (dispatch) => {
106+
// dispatch({
107+
// type: UPDATE_COMPONENT,
108+
// payload: {
109+
// id,
110+
// index,
111+
// newParentId,
112+
// color,
113+
// stateful,
114+
// },
115+
// });
116+
117+
// if (newParentId) {
118+
// dispatch(
119+
// updateChildren({
120+
// parentIds: [newParentId],
121+
// childId: id,
122+
// childIndex: index,
123+
// }),
124+
// );
125+
// }
126+
127+
// dispatch({ type: SET_SELECTABLE_PARENTS });
128+
// };
129+
130+
export const changeFocusComponent = ({ title }) => (dispatch) => {
131+
dispatch({ type: CHANGE_FOCUS_COMPONENT, payload: { title } });
132+
};
133+
134+
// make sure childId is being sent in
135+
export const changeFocusChild = ({ childId }) => (dispatch) => {
136+
dispatch({ type: CHANGE_FOCUS_CHILD, payload: { childId } });
137+
};
138+
139+
export const changeComponentFocusChild = ({ componentId, childId }) => (dispatch) => {
140+
dispatch({
141+
type: CHANGE_COMPONENT_FOCUS_CHILD,
142+
payload: { componentId, childId },
143+
});
144+
};
145+
146+
export const exportFiles = ({
147+
components, path, appName, exportAppBool,
148+
}) => (dispatch) => {
149+
// this dispatch sets the global state property 'loading' to true until the createFiles call resolves below
150+
dispatch({
151+
type: EXPORT_FILES,
152+
});
153+
154+
createFiles(components, path, appName, exportAppBool)
155+
.then(dir => dispatch({
156+
type: EXPORT_FILES_SUCCESS,
157+
payload: { status: true, dir: dir[0] },
158+
}))
159+
.catch(err => dispatch({
160+
type: EXPORT_FILES_ERROR,
161+
payload: { status: true, err },
162+
}));
163+
};
164+
165+
export const handleClose = () => ({
166+
type: HANDLE_CLOSE,
167+
payload: false,
168+
});
169+
170+
export const handleTransform = (componentId, childId, {
171+
x, y, width, height,
172+
}) => ({
173+
type: HANDLE_TRANSFORM,
174+
payload: {
175+
componentId,
176+
childId,
177+
x,
178+
y,
179+
width,
180+
height,
181+
},
182+
});
183+
184+
export const createApplication = ({
185+
path,
186+
components = [],
187+
genOption,
188+
appName = 'reactype_app',
189+
exportAppBool,
190+
}) => (dispatch) => {
191+
if (genOption === 0) {
192+
exportAppBool = false;
193+
dispatch(
194+
exportFiles({
195+
appName,
196+
path,
197+
components,
198+
exportAppBool,
199+
}),
200+
);
201+
} else if (genOption) {
202+
exportAppBool = true;
203+
dispatch({
204+
type: CREATE_APPLICATION,
205+
});
206+
createApplicationUtil({
207+
path,
208+
appName,
209+
genOption,
210+
exportAppBool,
211+
})
212+
.then(() => {
213+
dispatch({
214+
type: CREATE_APPLICATION_SUCCESS,
215+
});
216+
dispatch(
217+
exportFiles({
218+
appName,
219+
path,
220+
components,
221+
exportAppBool,
222+
}),
223+
);
224+
})
225+
.catch(err => dispatch({
226+
type: CREATE_APPLICATION_ERROR,
227+
payload: { status: true, err },
228+
}));
229+
}
230+
};
231+
232+
export const openExpansionPanel = component => ({
233+
type: OPEN_EXPANSION_PANEL,
234+
payload: { component },
235+
});
236+
237+
export const deleteAllData = () => ({
238+
type: DELETE_ALL_DATA,
239+
});
240+
241+
export const deleteProp = propId => (dispatch) => {
242+
dispatch({ type: DELETE_PROP, payload: propId });
243+
};
244+
245+
export const addProp = prop => ({
246+
type: ADD_PROP,
247+
payload: { ...prop },
248+
});
249+
250+
export const updateHtmlAttr = ({ attr, value }) => (dispatch) => {
251+
dispatch({
252+
type: UPDATE_HTML_ATTR,
253+
payload: { attr, value },
254+
});
255+
};
256+
257+
export const updateChildrenSort = ({ newSortValues }) => (dispatch) => {
258+
dispatch({
259+
type: UPDATE_CHILDREN_SORT,
260+
payload: { newSortValues },
261+
});
262+
};

src/actions/components.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,9 @@ export const updateHtmlAttr = ({ attr, value }) => dispatch => {
232232
});
233233
};
234234

235-
export const updateChildrenSort = ({ newChildrenArray }) => dispatch => {
235+
export const updateChildrenSort = ({ newSortValues }) => dispatch => {
236236
dispatch({
237237
type: UPDATE_CHILDREN_SORT,
238-
payload: { newChildrenArray }
238+
payload: { newSortValues }
239239
});
240240
};

0 commit comments

Comments
 (0)