Skip to content

Commit 98c8ee2

Browse files
authored
Merge pull request #10 from tonyito/mvp
Proper Typing for files
2 parents 1a40a57 + 2b6dae3 commit 98c8ee2

File tree

12 files changed

+280
-330
lines changed

12 files changed

+280
-330
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Created by https://www.gitignore.io/api/node,linux,macos,windows,visualstudio,yarn
2-
2+
yarn.lock
33
### Linux ###
44
*~
55

src/actionTypes/index.js

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/actionTypes/index.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
export const LOAD_INIT_DATA: string = 'LOAD_INIT_DATA';
2+
export const ADD_COMPONENT: string = 'ADD_COMPONENT';
3+
export const ADD_CHILD: string = 'ADD_CHILD';
4+
export const DELETE_CHILD: string = 'DELETE_CHILD';
5+
export const UPDATE_COMPONENT: string = 'UPDATE_COMPONENT';
6+
export const DELETE_COMPONENT: string = 'DELETE_COMPONENT';
7+
export const CHANGE_FOCUS_COMPONENT: string = 'CHANGE_FOCUS_COMPONENT';
8+
export const CHANGE_COMPONENT_FOCUS_CHILD: string = 'CHANGE_COMPONENT_FOCUS_CHILD';
9+
export const CHANGE_FOCUS_CHILD: string = 'CHANGE_FOCUS_CHILD';
10+
export const UPDATE_CHILDREN: string = 'UPDATE_CHILDREN';
11+
export const REASSIGN_PARENT: string = 'REASSIGN_PARENT';
12+
export const SET_SELECTABLE_PARENTS: string = 'SET_SELECTABLE_PARENTS';
13+
export const EXPORT_FILES: string = 'EXPORT_FILES';
14+
export const EXPORT_FILES_SUCCESS: string = 'EXPORT_FILES_SUCCESS';
15+
export const EXPORT_FILES_ERROR: string = 'EXPORT_FILES_ERROR';
16+
export const HANDLE_CLOSE: string = 'HANDLE_CLOSE';
17+
export const HANDLE_TRANSFORM: string = 'HANDLE_TRANSFORM';
18+
export const CREATE_APPLICATION: string = 'CREATE_APPLICATION';
19+
export const CREATE_APPLICATION_SUCCESS: string = 'CREATE_APPLICATION_SUCCESS';
20+
export const CREATE_APPLICATION_ERROR: string = 'CREATE_APPLICATION_ERROR';
21+
export const MOVE_TO_BOTTOM: string = 'MOVE_TO_BOTTOM';
22+
export const MOVE_TO_TOP: string = 'MOVE_TO_TOP';
23+
export const OPEN_EXPANSION_PANEL: string = 'OPEN_EXPANSION_PANEL';
24+
export const DELETE_PROP: string = 'DELETE_PROP';
25+
export const ADD_PROP: string = 'ADD_PROP';
26+
export const DELETE_ALL_DATA: string = 'DELETE_ALL_DATA';
27+
export const CHANGE_IMAGE_PATH: string = 'CHANGE_IMAGE_PATH';
28+
export const UPDATE_HTML_ATTR: string = 'UPDATE_HTML_ATTR';
29+
export const UPDATE_CHILDREN_SORT: string = 'UPDATE_CHILDREN_SORT';
30+
export const CHANGE_IMAGE_SOURCE: string = 'CHANGE_IMAGE_SOURCE';
31+
export const DELETE_IMAGE: string = 'DELETE_IMAGE';
32+
export const TOGGLE_STATE: string = 'TOGGLE_STATE';

src/actions/components.ts

Lines changed: 52 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import {
2-
ComponentInt,
3-
ComponentsInt,
4-
PropInt,
5-
ChildInt
2+
ComponentInt, ComponentsInt, PropInt, ChildInt, Action, ApplicationStateInt
63
} from '../utils/Interfaces.ts';
74

85
import {
@@ -32,32 +29,30 @@ import {
3229
UPDATE_CHILDREN_SORT,
3330
CHANGE_IMAGE_SOURCE,
3431
DELETE_IMAGE
35-
36-
} from '../actionTypes/index.js';
32+
} from '../actionTypes/index.ts';
3733

3834
import { loadState } from '../localStorage';
3935
import createFiles from '../utils/createFiles.util.ts';
4036
import createApplicationUtil from '../utils/createApplication.util.ts';
4137

38+
4239
export const changeImagePath = (imageSource: string) => ({
4340
type: CHANGE_IMAGE_SOURCE,
44-
payload: imageSource,
41+
payload: { imageSource },
4542
})
4643

47-
export const loadInitData = () => (dispatch: any) => {
48-
loadState().then((data: any) =>
44+
export const loadInitData = () => (dispatch: (arg: Action) => void) => {
45+
loadState().then((data: ApplicationStateInt) => {
4946
dispatch({
50-
type: LOAD_INIT_DATA,
51-
payload: {
52-
data: data ? data.workspace : {}
53-
}
54-
})
55-
);
47+
type: LOAD_INIT_DATA,
48+
payload: {
49+
data: data ? data.workspace : {},
50+
},
51+
});
52+
});
5653
};
5754

58-
export const addComponent = ({ title }: { title: string }) => (
59-
dispatch: any
60-
) => {
55+
export const addComponent = ({ title }: { title: string }) => (dispatch: (arg: Action) => void) => {
6156
dispatch({ type: ADD_COMPONENT, payload: { title } });
6257
};
6358

@@ -66,14 +61,14 @@ export const addChild = ({
6661
childType,
6762
HTMLInfo
6863
}: {
69-
title: string;
70-
childType: string;
71-
HTMLInfo: object;
72-
}) => (dispatch: any) => {
64+
title: string;
65+
childType: string;
66+
HTMLInfo: object;
67+
}) => (dispatch: (arg: Action) => void) => {
7368
dispatch({ type: ADD_CHILD, payload: { title, childType, HTMLInfo } });
7469
};
7570

76-
export const deleteChild = ({}) => (dispatch: any) => {
71+
export const deleteChild = ({}) => (dispatch: (arg: Action) => void) => {
7772
// with no payload, it will delete focusd child
7873
dispatch({ type: DELETE_CHILD, payload: {} });
7974
};
@@ -82,9 +77,9 @@ export const deleteComponent = ({
8277
componentId,
8378
stateComponents
8479
}: {
85-
componentId: number;
86-
stateComponents: ComponentsInt;
87-
}) => (dispatch: any) => {
80+
componentId: number;
81+
stateComponents: ComponentsInt;
82+
}) => (dispatch: (arg: Action) => void) => {
8883
// find all places where the "to be deleted" is a child and do what u gotta do
8984
stateComponents.forEach((parent: ComponentInt) => {
9085
parent.childrenArray
@@ -107,35 +102,30 @@ export const deleteComponent = ({
107102
dispatch({ type: DELETE_COMPONENT, payload: { componentId } });
108103
};
109104

110-
export const changeFocusComponent = ({ title }: { title: string }) => (
111-
dispatch: any
112-
) => {
105+
export const changeFocusComponent = ({ title }: { title: string }) => (dispatch: (arg: Action) => void) => {
113106
dispatch({ type: CHANGE_FOCUS_COMPONENT, payload: { title } });
114107
};
115108

116109
// make sure childId is being sent in
117-
export const changeFocusChild = ({ childId }: { childId: number }) => (
118-
dispatch: any
119-
) => {
110+
export const changeFocusChild = ({ childId }: { childId: number }) => (dispatch: (arg: Action) => void) => {
120111
dispatch({ type: CHANGE_FOCUS_CHILD, payload: { childId } });
121112
};
122113

123114
export const changeComponentFocusChild = ({
124115
componentId,
125116
childId
126117
}: {
127-
componentId: number;
128-
childId: number;
129-
}) => (dispatch: any) => {
118+
componentId: number;
119+
childId: number;
120+
}) => (dispatch: (arg: Action) => void) => {
130121
dispatch({
131122
type: CHANGE_COMPONENT_FOCUS_CHILD,
132123
payload: { componentId, childId }
133124
});
134125
};
135126

136127
export const deleteImage = () => ({
137-
type: DELETE_IMAGE,
138-
payload: ''
128+
type: DELETE_IMAGE
139129
})
140130

141131

@@ -145,11 +135,11 @@ export const exportFiles = ({
145135
appName,
146136
exportAppBool
147137
}: {
148-
components: ComponentsInt;
149-
path: string;
150-
appName: string;
151-
exportAppBool: boolean;
152-
}) => (dispatch: any) => {
138+
components: ComponentsInt;
139+
path: string;
140+
appName: string;
141+
exportAppBool: boolean;
142+
}) => (dispatch: (arg: Action) => void) => {
153143
// this dispatch sets the global state property 'loading' to true until the createFiles call resolves below
154144
dispatch({
155145
type: EXPORT_FILES
@@ -203,12 +193,12 @@ export const createApplication = ({
203193
appName = 'reactype_app',
204194
exportAppBool
205195
}: {
206-
path: string;
207-
components: ComponentsInt;
208-
genOption: number;
209-
appName: string;
210-
exportAppBool: boolean;
211-
}) => (dispatch: any) => {
196+
path: string;
197+
components: ComponentsInt;
198+
genOption: number;
199+
appName: string;
200+
exportAppBool: boolean;
201+
}) => (dispatch: (arg: Action) => void) => {
212202
if (genOption === 0) {
213203
exportAppBool = false;
214204
dispatch(
@@ -227,8 +217,7 @@ export const createApplication = ({
227217
createApplicationUtil({
228218
path,
229219
appName,
230-
genOption
231-
// exportAppBool
220+
genOption,
232221
})
233222
.then(() => {
234223
dispatch({
@@ -261,7 +250,7 @@ export const deleteAllData = () => ({
261250
type: DELETE_ALL_DATA
262251
});
263252

264-
export const deleteProp = (propId: number) => (dispatch: any) => {
253+
export const deleteProp = (propId: number) => (dispatch: (arg: Action) => void) => {
265254
dispatch({ type: DELETE_PROP, payload: propId });
266255
};
267256

@@ -274,26 +263,21 @@ export const addProp = (prop: PropInt) => ({
274263
payload: { ...prop }
275264
});
276265

277-
export const updateHtmlAttr = ({
278-
attr,
279-
value
280-
}: {
281-
attr: string;
282-
value: string;
283-
}) => (dispatch: any) => {
266+
export const updateHtmlAttr = ({ attr, value }: { attr: string; value: string }) => (
267+
dispatch: (arg: Action) => void,
268+
) => {
284269
dispatch({
285270
type: UPDATE_HTML_ATTR,
286271
payload: { attr, value }
287272
});
288273
};
289274

290-
export const updateChildrenSort = ({
291-
newSortValues
292-
}: {
293-
newSortValues: any;
294-
}) => (dispatch: any) => {
295-
dispatch({
296-
type: UPDATE_CHILDREN_SORT,
297-
payload: { newSortValues }
298-
});
299-
};
275+
//Action reserved for SortChildren component not written yet
276+
// export const updateChildrenSort = ({ newSortValues }: { newSortValues: any }) => (
277+
// dispatch: (arg: Action) => void,
278+
// ) => {
279+
// dispatch({
280+
// type: UPDATE_CHILDREN_SORT,
281+
// payload: { newSortValues },
282+
// });
283+
// };

src/components/CodePreview.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { format } from 'prettier';
33
import componentRender from '../utils/componentRender.util';
44
import { ComponentInt, ComponentsInt } from '../utils/Interfaces';
55
/** ** SortCHildren will be fixed , dont XXX the file *** */
6-
// import SortChildren from './SortChildren.jsx';
6+
// import SortChildren from './SortChildren.tsx';
77
import SyntaxHighlighter from 'react-syntax-highlighter';
88
import { hybrid } from 'react-syntax-highlighter/dist/styles/hljs/';
99

0 commit comments

Comments
 (0)