Skip to content

Commit 531bd13

Browse files
committed
now the readOnly property is stored in thge global store
1 parent 4c95b7a commit 531bd13

File tree

4 files changed

+30
-15
lines changed

4 files changed

+30
-15
lines changed

src/components/bottom/BottomPanel.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,17 @@ const mapDispatchToProps = (dispatch: any) => ({
1616

1717
const mapStateToProps = (store: any) => ({
1818
focusChild: store.workspace.focusChild,
19-
components: store.workspace.components
19+
components: store.workspace.components,
20+
codeReadOnly: store.workspace.codeReadOnly
2021
});
2122

2223
interface BottomPanelPropsInt extends PropsInt {
2324
deleteProp(id: number): void;
2425
addProp(prop: PropInt): void;
2526
changeFocusComponent(arg: { title: string }): void;
2627
updateCode(arg: { componentId: number; code: string }): void;
27-
toggleCodeEdit();
28+
toggleCodeEdit(): void;
29+
codeReadOnly: boolean;
2830
}
2931

3032
class BottomPanel extends Component<BottomPanelPropsInt> {
@@ -36,7 +38,9 @@ class BottomPanel extends Component<BottomPanelPropsInt> {
3638
addProp,
3739
focusChild,
3840
changeFocusComponent,
39-
updateCode
41+
updateCode,
42+
toggleCodeEdit,
43+
codeReadOnly
4044
} = this.props;
4145

4246
return (
@@ -49,6 +53,8 @@ class BottomPanel extends Component<BottomPanelPropsInt> {
4953
focusChild={focusChild}
5054
changeFocusComponent={changeFocusComponent}
5155
updateCode={updateCode}
56+
toggleCodeEdit={toggleCodeEdit}
57+
codeReadOnly={codeReadOnly}
5258
/>
5359
</div>
5460
);

src/components/bottom/BottomTabs.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ interface BottomTabsPropsInt extends PropsInt {
1515
classes: any;
1616
changeFocusComponent(arg: { title: string }): void;
1717
updateCode(arg: { componentId: number; code: string }): void;
18+
toggleCodeEdit(): void;
19+
codeReadOnly: boolean;
1820
}
1921

2022
// interface TreeInt {
@@ -141,7 +143,9 @@ class BottomTabs extends Component<BottomTabsPropsInt, StateInt> {
141143
deleteProp,
142144
addProp,
143145
focusChild,
144-
updateCode
146+
updateCode,
147+
toggleCodeEdit,
148+
codeReadOnly
145149
} = this.props;
146150
const { value } = this.state;
147151

@@ -161,12 +165,12 @@ class BottomTabs extends Component<BottomTabsPropsInt, StateInt> {
161165
<Tab
162166
disableRipple
163167
classes={{ root: classes.tabRoot, selected: classes.tabSelected }}
164-
label='Application Tree'
168+
label="Application Tree"
165169
/>
166170
<Tab
167171
disableRipple
168172
classes={{ root: classes.tabRoot, selected: classes.tabSelected }}
169-
label='Code Preview'
173+
label="Code Preview"
170174
/>
171175
<Tab
172176
disableRipple
@@ -183,13 +187,13 @@ class BottomTabs extends Component<BottomTabsPropsInt, StateInt> {
183187
<Tab
184188
disableRipple
185189
classes={{ root: classes.tabRoot, selected: classes.tabSelected }}
186-
label='Add Child Props'
190+
label="Add Child Props"
187191
/>
188192
</Tabs>
189193

190194
{value === 0 && (
191195
<div
192-
id='treeWrapper'
196+
id="treeWrapper"
193197
style={{
194198
width: '100%',
195199
height: '100%'
@@ -229,6 +233,8 @@ class BottomTabs extends Component<BottomTabsPropsInt, StateInt> {
229233
updateCode={updateCode}
230234
components={components}
231235
changeFocusComponent={this.props.changeFocusComponent}
236+
toggleCodeEdit={toggleCodeEdit}
237+
codeReadOnly={codeReadOnly}
232238
/>
233239
)}
234240
{value === 2 && <Props />}

src/components/bottom/CodePreview.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ type CodePreviewProps = {
1515
updateCode(arg: { componentId: number; code: string }): void;
1616
changeFocusComponent(arg: { title: string }): void;
1717
classes: any;
18+
toggleCodeEdit(): void;
19+
codeReadOnly: boolean;
1820
};
1921
interface StateInt {
2022
readOnly: boolean;
@@ -23,9 +25,6 @@ interface StateInt {
2325
class CodePreview extends Component<CodePreviewProps, StateInt> {
2426
constructor(props: CodePreviewProps) {
2527
super(props);
26-
this.state = {
27-
readOnly: false
28-
};
2928
}
3029

3130
//checking if the code has been asigned yet or not
@@ -93,7 +92,7 @@ class CodePreview extends Component<CodePreviewProps, StateInt> {
9392
}
9493
value={this.props.focusComponent.code}
9594
name="Code_div"
96-
readOnly={this.state.readOnly}
95+
readOnly={this.props.codeReadOnly}
9796
editorProps={{ $blockScrolling: true }}
9897
fontSize={16}
9998
/>
@@ -108,10 +107,10 @@ class CodePreview extends Component<CodePreviewProps, StateInt> {
108107
style={{ justifySelf: 'center' }}
109108
className={this.props.classes.startEdit}
110109
onClick={e => {
111-
this.setState({ readOnly: !this.state.readOnly });
110+
this.props.toggleCodeEdit();
112111
}}
113112
>
114-
{this.state.readOnly ? 'Enter Edit Mode' : 'Exit Edit Mode'}
113+
{this.props.codeReadOnly ? 'Enter Edit Mode' : 'Exit Edit Mode'}
115114
</Button>
116115
<div
117116
style={{

src/reducers/rootReducer.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ import {
2929
deleteProp,
3030
updateChildrenSort,
3131
updateHtmlAttr,
32-
updateCode
32+
updateCode,
33+
toggleCodeEdit
3334
} from './bottomReducers';
3435
import {
3536
ADD_CHILD,
@@ -40,6 +41,7 @@ import {
4041
CHANGE_FOCUS_COMPONENT,
4142
CHANGE_IMAGE_SOURCE,
4243
CHANGE_TUTORIAL,
44+
CODE_EDIT,
4345
DELETE_ALL_DATA,
4446
DELETE_CHILD,
4547
DELETE_COMPONENT,
@@ -101,6 +103,8 @@ const componentReducer = (state = initialApplicationState, action: Action) => {
101103
return changeImageSource(state, action.payload);
102104
case CHANGE_TUTORIAL:
103105
return changeTutorial(state, action.payload);
106+
case CODE_EDIT:
107+
return toggleCodeEdit(state);
104108
case DELETE_ALL_DATA:
105109
return {
106110
...initialApplicationState,

0 commit comments

Comments
 (0)