Skip to content

Commit 057de75

Browse files
authored
Merge pull request #41 from tonyito/mvp
React Native mode Konva stage function implementation
2 parents 9fc8c1d + 98671c2 commit 057de75

25 files changed

+346
-163
lines changed

.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"printWidth": 80,
3+
"singleQuote": true,
4+
"trailingComma": "none"
5+
}

main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ const createWindow = () => {
8585
// eslint-disable-next-line
8686
const { width, height } = require('electron').screen.getPrimaryDisplay().size;
8787
mainWindow = new BrowserWindow({
88-
width,
89-
height,
88+
width: 1920,
89+
height: 1080,
9090
webPreferences: {
9191
zoomFactor: 0.7,
9292
'node-Integration': false

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
"d3": "^5.9.2",
111111
"electron-reload": "^1.4.0",
112112
"enzyme": "^3.4.1",
113-
"konva": "^4.1.6",
113+
"konva": "^4.2.0",
114114
"localforage": "^1.7.2",
115115
"lodash.throttle": "^4.1.1",
116116
"material-table": "^1.25.2",

prettierrc.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"printWidth": 80,
3+
"singleQuote": true,
4+
"trailingComma": "none"
5+
}

src/actionTypes/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export const REASSIGN_PARENT: string = 'REASSIGN_PARENT';
3232
export const REDO: string = 'REDO';
3333
export const SET_SELECTABLE_PARENTS: string = 'SET_SELECTABLE_PARENTS';
3434
export const TOGGLE_CLASS: string = 'TOGGLE_CLASS';
35+
export const TOGGLE_NATIVE: string = 'TOGGLE_NATIVE';
3536
export const TOGGLE_STATE: string = 'TOGGLE_STATE';
3637
export const UNDO: string = 'UNDO';
3738
export const UPDATE_COMPONENT: string = 'UPDATE_COMPONENT';

src/actions/actionCreators.ts

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
LOAD_INIT_DATA,
3535
REDO,
3636
TOGGLE_CLASS,
37+
TOGGLE_NATIVE,
3738
TOGGLE_STATE,
3839
UNDO,
3940
UPDATE_HTML_ATTR,
@@ -81,35 +82,6 @@ export const deleteChild = ({}) => (dispatch: (arg: Action) => void) => {
8182
dispatch({ type: DELETE_CHILD, payload: {} });
8283
};
8384

84-
export const deleteComponent = ({
85-
componentId,
86-
stateComponents
87-
}: {
88-
componentId: number;
89-
stateComponents: ComponentsInt;
90-
}) => (dispatch: (arg: Action) => void) => {
91-
// find all places where the "to be deleted" is a child and do what u gotta do
92-
stateComponents.forEach((parent: ComponentInt) => {
93-
parent.childrenArray
94-
.filter((child: ChildInt) => child.childComponentId === componentId)
95-
.forEach((child: ChildInt) => {
96-
dispatch({
97-
type: DELETE_CHILD,
98-
payload: {
99-
parentId: parent.id,
100-
childId: child.childId,
101-
calledFromDeleteComponent: true
102-
}
103-
});
104-
});
105-
});
106-
107-
// change focus to app
108-
dispatch({ type: CHANGE_FOCUS_COMPONENT, payload: { title: 'App' } });
109-
// after taking care of the children delete the component
110-
dispatch({ type: DELETE_COMPONENT, payload: { componentId } });
111-
};
112-
11385
export const changeComponentFocusChild = ({
11486
componentId,
11587
childId
@@ -130,6 +102,7 @@ export const changeFocusChild = ({ childId }: { childId: number }) => (
130102
dispatch({ type: CHANGE_FOCUS_CHILD, payload: { childId } });
131103
};
132104

105+
133106
export const changeFocusComponent = ({ title }: { title: string }) => (
134107
dispatch: (arg: Action) => void
135108
) => {
@@ -195,6 +168,36 @@ export const deleteAllData = () => ({
195168
type: DELETE_ALL_DATA
196169
});
197170

171+
172+
export const deleteComponent = ({
173+
componentId,
174+
stateComponents
175+
}: {
176+
componentId: number;
177+
stateComponents: ComponentsInt;
178+
}) => (dispatch: (arg: Action) => void) => {
179+
// find all places where the "to be deleted" is a child and do what u gotta do
180+
stateComponents.forEach((parent: ComponentInt) => {
181+
parent.childrenArray
182+
.filter((child: ChildInt) => child.childComponentId === componentId)
183+
.forEach((child: ChildInt) => {
184+
dispatch({
185+
type: DELETE_CHILD,
186+
payload: {
187+
parentId: parent.id,
188+
childId: child.childId,
189+
calledFromDeleteComponent: true
190+
}
191+
});
192+
});
193+
});
194+
195+
// change focus to app
196+
dispatch({ type: CHANGE_FOCUS_COMPONENT, payload: { title: 'App' } });
197+
// after taking care of the children delete the component
198+
dispatch({ type: DELETE_COMPONENT, payload: { componentId } });
199+
};
200+
198201
export const deleteImage = () => ({
199202
type: DELETE_IMAGE
200203
});
@@ -301,7 +304,11 @@ export const toggleEditMode = ({ id }: { id: number }) => (
301304
) => {
302305
dispatch({ type: EDIT_MODE, payload: { id } });
303306
};
304-
//action creators for undo and redo
307+
308+
export const toggleNative = () => ({
309+
type: TOGGLE_NATIVE,
310+
});
311+
305312
export const undo = () => ({
306313
type: UNDO
307314
});

src/components/bottom/BottomPanel.tsx

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
import React, { Component } from 'react';
22
import { connect } from 'react-redux';
3-
import { handleClose, deleteProp, addProp } from '../../actions/actionCreators';
3+
import { handleClose, deleteProp, addProp, toggleNative, changeComponentFocusChild } from '../../actions/actionCreators';
44
import BottomTabs from './BottomTabs';
55
import { PropsInt, PropInt } from '../../interfaces/Interfaces';
66
import { toggleCodeEdit } from '../../actions/actionCreators';
77

88
const IPC = require('electron').ipcRenderer;
99

1010
const mapDispatchToProps = (dispatch: any) => ({
11-
handleNotificationClose: () => dispatch(handleClose()),
12-
deleteProp: (id: number) => dispatch(deleteProp(id)),
1311
addProp: (prop: PropInt) => dispatch(addProp(prop)),
14-
toggleCodeEdit: () => dispatch(toggleCodeEdit())
12+
deleteProp: (id: number) => dispatch(deleteProp(id)),
13+
handleNotificationClose: () => dispatch(handleClose()),
14+
toggleNative: () => dispatch(toggleNative()),
15+
toggleCodeEdit: () => dispatch(toggleCodeEdit()),
1516
});
1617

1718
const mapStateToProps = (store: any) => ({
1819
focusChild: store.workspace.focusChild,
1920
components: store.workspace.components,
21+
native: store.workspace.native,
2022
codeReadOnly: store.workspace.codeReadOnly
2123
});
2224

@@ -25,8 +27,14 @@ interface BottomPanelPropsInt extends PropsInt {
2527
addProp(prop: PropInt): void;
2628
changeFocusComponent(arg: { title: string }): void;
2729
updateCode(arg: { componentId: number; code: string }): void;
30+
toggleNative(): void;
31+
native: boolean;
2832
toggleCodeEdit(): void;
2933
codeReadOnly: boolean;
34+
changeComponentFocusChild(arg: {
35+
componentId: number;
36+
childId: number;
37+
}): void;
3038
}
3139

3240
class BottomPanel extends Component<BottomPanelPropsInt> {
@@ -39,8 +47,11 @@ class BottomPanel extends Component<BottomPanelPropsInt> {
3947
focusChild,
4048
changeFocusComponent,
4149
updateCode,
50+
toggleNative,
51+
native,
4252
toggleCodeEdit,
43-
codeReadOnly
53+
codeReadOnly,
54+
changeComponentFocusChild
4455
} = this.props;
4556

4657
return (
@@ -53,6 +64,8 @@ class BottomPanel extends Component<BottomPanelPropsInt> {
5364
focusChild={focusChild}
5465
changeFocusComponent={changeFocusComponent}
5566
updateCode={updateCode}
67+
toggleNative={toggleNative}
68+
native={native}
5669
toggleCodeEdit={toggleCodeEdit}
5770
codeReadOnly={codeReadOnly}
5871
/>

0 commit comments

Comments
 (0)