Skip to content

Commit 712e508

Browse files
authored
Merge pull request #11 from oslabs-beta/xiao-eventhandler
Xiao eventhandler
2 parents ee7985b + 8ff48f3 commit 712e508

File tree

12 files changed

+131
-105
lines changed

12 files changed

+131
-105
lines changed

app/src/components/StateManagement/CreateTab/components/StatePropsPanel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ const StatePropsPanel = ({ isThemeLight, data}): JSX.Element => {
251251
</FormControl>
252252
</div>
253253
<br />
254-
<div style={{display: 'flex', overflowX: 'scroll', width: '1700px'}}>
254+
<div style={{display: 'flex', overflowX: 'scroll'}}>
255255
<div style={{display: 'flex', flexDirection: 'column'}}>
256256
<h4 className={isThemeLight ? classes.lightThemeFontColor : classes.darkThemeFontColor}>
257257
Current Component State: {state.components[state.canvasFocus.componentId - 1].name}

app/src/components/StateManagement/StateManagement.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ import DisplayContainer from './DisplayTab/DisplayContainer';
1313
const useStyles = makeStyles({
1414
contextContainer: {
1515
backgroundColor: 'white',
16-
height: 'fit-content'
16+
height: 'fit-content',
17+
width: 'fit-content',
18+
minWidth: '100%'
1719
}
1820
});
1921

app/src/components/bottom/BottomTabs.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const BottomTabs = (props): JSX.Element => {
5252
style={{ backgroundColor: '#003366' }}
5353
>
5454
<Box display="flex" justifyContent="space-between" alignItems="center" paddingBottom="10px" paddingRight="10px">
55-
<Tabs value={tab} onChange={handleChange} classes={{ root: classes.tabsRoot, indicator: classes.tabsIndicator }}>
55+
<Tabs value={tab} onChange={handleChange} classes={{ root: classes.tabsRoot, indicator: classes.tabsIndicator }} variant="scrollable" scrollButtons="auto" >
5656
<Tab disableRipple classes={{ root: classes.tabRoot, selected: classes.tabSelected }} label="Creation Panel" />
5757
<Tab disableRipple classes={{ root: classes.tabRoot, selected: classes.tabSelected }} label="Customization" />
5858
<Tab disableRipple classes={{ root: classes.tabRoot, selected: classes.tabSelected }} label="CSS Editor" />
@@ -110,7 +110,8 @@ const useStyles = makeStyles(theme => ({
110110
textTransform: 'initial',
111111
minWidth: 40,
112112
fontWeight: theme.typography.fontWeightRegular,
113-
marginRight: theme.spacing(4), // JZ: updated syntax as per deprecation warning
113+
marginRight: theme.spacing(2), // JZ: updated syntax as per deprecation warning
114+
marginLeft: theme.spacing(2),
114115

115116
fontFamily: [
116117
'-apple-system',
@@ -149,7 +150,8 @@ const useStyles = makeStyles(theme => ({
149150
},
150151
projectTypeWrapper: {
151152
marginTop: '10px',
152-
marginBotton: '10px'
153+
marginBotton: '10px',
154+
marginLeft: '10px',
153155
},
154156
projectSelector: {
155157
backgroundColor: '#0099E6',

app/src/components/main/Annotation.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Annotations } from '../../interfaces/Interfaces';
33
import Modal from '@material-ui/core/Modal';
44
import StateContext from '../../context/context';
55

6-
function Annotation({ id, name, annotations }: Annotations) {
6+
function Annotation({ id, name }: Annotations) {
77
const [state, dispatch] = useContext(StateContext);
88

99
// -------------------------------- NEW CODE for DELETE BUTTONS, REPLACING ANNOTATIONS ---------------------------------------
@@ -20,7 +20,11 @@ function Annotation({ id, name, annotations }: Annotations) {
2020
<button
2121
className="annotate-button-empty" // NOTE: This className no longer accurate --> to update to delete button, same w/ Annotation export throughout
2222
id={'btn' + id}
23-
onClick={() => deleteHTMLtype(id)}
23+
onClick={(event) => {
24+
event.stopPropagation();
25+
deleteHTMLtype(id);
26+
}}
27+
// ref={ref}
2428
>
2529
x
2630
</button>

app/src/components/main/Canvas.tsx

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -64,27 +64,27 @@ function Canvas(props): JSX.Element {
6464
// find the current component to render on the canvas
6565
const currentComponent: Component = state.components.find(
6666
(elem: Component) => elem.id === state.canvasFocus.componentId
67-
);
68-
69-
// changes focus of the canvas to a new component / child
70-
const changeFocus = (componentId?: number, childId?: number | null) => {
71-
dispatch({ type: 'CHANGE FOCUS', payload: { componentId, childId } });
72-
};
73-
// onClickHandler is responsible for changing the focused component and child component
74-
function onClickHandler(event) {
75-
event.stopPropagation();
76-
// note: a null value for the child id means that we are focusing on the top-level component rather than any child
77-
changeFocus(state.canvasFocus.componentId, null);
78-
};
79-
80-
// stores a snapshot of state into the past array for UNDO. snapShotFunc is also invoked for nestable elements in DirectChildHTMLNestable.tsx
81-
const snapShotFunc = () => {
82-
// make a deep clone of state
83-
const deepCopiedState = JSON.parse(JSON.stringify(state));
84-
const focusIndex = state.canvasFocus.componentId - 1;
85-
//pushes the last user action on the canvas into the past array of Component
86-
state.components[focusIndex].past.push(deepCopiedState.components[focusIndex].children);
87-
};
67+
);
68+
69+
// changes focus of the canvas to a new component / child
70+
const changeFocus = (componentId?: number, childId?: number | null) => {
71+
dispatch({ type: 'CHANGE FOCUS', payload: { componentId, childId } });
72+
};
73+
// onClickHandler is responsible for changing the focused component and child component
74+
function onClickHandler(event) {
75+
event.stopPropagation();
76+
// note: a null value for the child id means that we are focusing on the top-level component rather than any child
77+
changeFocus(state.canvasFocus.componentId, null);
78+
};
79+
80+
// stores a snapshot of state into the past array for UNDO. snapShotFunc is also invoked for nestable elements in DirectChildHTMLNestable.tsx
81+
const snapShotFunc = () => {
82+
// make a deep clone of state
83+
const deepCopiedState = JSON.parse(JSON.stringify(state));
84+
const focusIndex = state.canvasFocus.componentId - 1;
85+
//pushes the last user action on the canvas into the past array of Component
86+
state.components[focusIndex].past.push(deepCopiedState.components[focusIndex].children);
87+
};
8888

8989
// This hook will allow the user to drag items from the left panel on to the canvas
9090
const [{ isOver }, drop] = useDrop({

app/src/components/main/DirectChildComponent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function DirectChildComponent({ childId, type, typeId, style, name }: ChildEleme
7272
<Annotation
7373
id={childId}
7474
name={name}
75-
annotations={annotations}
75+
// annotations={annotations}
7676
/>
7777

7878
</div>

app/src/components/top/NavBar.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,11 @@ const NavBar = (props) => {
173173
>
174174
ReacType
175175
</Typography>
176-
<Link to="/tutorial" style={{ textDecoration: 'none' }}>
176+
<Link to="/tutorial" style={{ textDecoration: 'none' }} target='_blank'>
177177
<Button
178178
variant="contained"
179179
color="secondary"
180180
style={{ minWidth: '137.69px' }}
181-
onClick={clearWorkspace}
182181
className="navbarButton"
183182
id="navbarButton"
184183
>

app/src/containers/CustomizationPanel.tsx

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,24 @@ const CustomizationPanel = ({ isThemeLight }): JSX.Element => {
5353
const [eventAll, setEventAll] = useState(['', '']);
5454
const [eventRow, setEventRow] = useState([]);
5555
// ------------------------------------------- added code above -------------------------------------------
56-
57-
const currFocus = state.components
58-
.find((el) => {
59-
return el.id === state.canvasFocus.componentId;
60-
})
61-
.children.find((el) => {
62-
return el.childId === state.canvasFocus.childId;
63-
});
64-
console.log(currFocus);
56+
const currFocus = getFocus().child;
57+
// state.components
58+
// .find((el) => {
59+
// return el.id === state.canvasFocus.componentId;
60+
// })
61+
// .children.find((el) => {
62+
// return el.childId === state.canvasFocus.childId;
63+
// });
6564
useEffect( () => {
6665
currFocus?.attributes?.compLink && setCompLink(currFocus.attributes.compLink);
66+
setEventAll(['', '']);
6767
if (currFocus) {
6868
const addedEvent: [] = [];
6969
for (const [event, funcName] of Object.entries(currFocus?.events)){
7070
addedEvent.push({ id: event , funcName })
7171
}
7272
setEventRow(addedEvent);
7373
}
74-
console.log(state);
7574
}, [state]);
7675

7776
//this function allows properties to persist and appear in nested divs
@@ -109,7 +108,6 @@ const CustomizationPanel = ({ isThemeLight }): JSX.Element => {
109108
setCompHeight(style.height ? style.height : '');
110109
setBGColor(style.backgroundColor ? style.backgroundColor : '');
111110
setEventAll(['', '']);
112-
// setFuncName('');
113111
};
114112
let configTarget;
115113
// after component renders, reset the input fields with the current styles of the selected child
@@ -153,7 +151,6 @@ const CustomizationPanel = ({ isThemeLight }): JSX.Element => {
153151
// ------------------------------------------- added code below -------------------------------------------
154152
case 'event':
155153
setEventAll(inputVal ? [inputVal, `handle${inputVal.slice(2)}`] : ['', '']);
156-
// setFuncName(currFocus.events[inputVal] ? currFocus.events[inputVal] : `handle${event.slice(2)}`);
157154
break;
158155
case 'funcName':
159156
setEventAll([eventAll[0], inputVal]);
@@ -165,7 +162,7 @@ const CustomizationPanel = ({ isThemeLight }): JSX.Element => {
165162
};
166163
// returns the current component referenced in canvasFocus
167164
// along with its child instance, if it exists
168-
const getFocus = () => {
165+
function getFocus() {
169166
// find and store component's name based on canvasFocus.componentId
170167
// note: deep clone here to make sure we don't end up altering state
171168
const focusTarget = JSON.parse(
@@ -189,24 +186,26 @@ const CustomizationPanel = ({ isThemeLight }): JSX.Element => {
189186
if (currentChild.childId === childInstanceId) {
190187
focusChild = currentChild;
191188
focusTarget.child.style = focusChild.style;
189+
focusTarget.child.events = focusChild.events;
190+
focusTarget.child.attributes = focusChild.attributes;
192191
break;
193192
}
194193
if (currentChild.name !== 'input' && currentChild.name !== 'img')
195194
currentChild.children.forEach(child => searchArray.push(child));
196195
}
197-
196+
198197
// if type is Component, use child's typeId to search through state components and find matching component's name
199198
if (focusChild.type === 'Component') {
200199
focusTarget.child.type = 'component';
201200
focusTarget.child.name = state.components.find(
202-
comp => comp.id === focusChild.typeId
203-
).name;
204-
// if type is HTML Element, search through HTML types to find matching element's name
201+
comp => comp.id === focusChild.typeId
202+
).name;
203+
// if type is HTML Element, search through HTML types to find matching element's name
205204
} else if (focusChild.type === 'HTML Element') {
206205
focusTarget.child.type = 'HTML element';
207206
focusTarget.child.name = state.HTMLTypes.find(
208-
elem => elem.id === focusChild.typeId
209-
).name;
207+
elem => elem.id === focusChild.typeId
208+
).name;
210209
}
211210
}
212211
return focusTarget;
@@ -279,25 +278,25 @@ const CustomizationPanel = ({ isThemeLight }): JSX.Element => {
279278
{
280279
field: 'funcName',
281280
headerName: 'Function Name',
282-
width: '40%',
281+
width: '50%',
283282
editable: false,
284283
flex: 1,
285284
disableColumnMenu: true,
286285
},
287286
{
288287
field: 'delete',
289-
headerName: 'Delete Event',
290-
width: '20%',
288+
headerName: 'Delete',
289+
width: '10%',
291290
editable: false,
292291
flex: 1,
292+
sortable: false,
293293
disableColumnMenu: true,
294-
disableColumnFilter: true,
295294
renderCell: function renderCell(params: any) {
296295
return (
297296
<Button
298-
style={{ width: `${3}px` }}
297+
style={{ width: `${3}px`, color: 'black' }}
299298
onClick={() => {
300-
// deleteState(params.id);
299+
deleteEvent(params.id);
301300
}}
302301
>
303302
<ClearIcon style={{ width: `${15}px` }} />
@@ -307,53 +306,54 @@ const CustomizationPanel = ({ isThemeLight }): JSX.Element => {
307306
}
308307
];
309308

309+
const deleteEvent = selectedEvent => {
310+
dispatch({
311+
type: 'DELETE EVENT',
312+
payload: { event: selectedEvent }
313+
});
314+
};
315+
310316

311317
const handleSave = (): Object => {
312318
// ------------------------------------------- change code below -------------------------------------------
313-
const actions: object[] = [];
319+
dispatch({
320+
type: 'UPDATE STATE USED',
321+
payload: {stateUsedObj: stateUsedObj}
322+
})
323+
324+
dispatch({
325+
type: 'UPDATE USE CONTEXT',
326+
payload: { useContextObj: useContextObj}
327+
})
314328

315329
const styleObj: any = {};
316-
let updateCSS: boolean = false;
317-
if (displayMode !== '') {
318-
updateCSS = true;
319-
styleObj.display = displayMode;
320-
}
330+
if (displayMode !== '') styleObj.display = displayMode;
321331
if (flexDir !== '') styleObj.flexDirection = flexDir;
322332
if (flexJustify !== '') styleObj.justifyContent = flexJustify;
323333
if (flexAlign !== '') styleObj.alignItems = flexAlign;
324334
if (compWidth !== '') styleObj.width = compWidth;
325335
if (compHeight !== '') styleObj.height = compHeight;
326336
if (BGColor !== '') styleObj.backgroundColor = BGColor;
337+
dispatch({
338+
type: 'UPDATE CSS',
339+
payload: { style: styleObj }
340+
});
327341

328342
const attributesObj: any = {};
329343
if (compText !== '') attributesObj.compText = compText;
330344
if (compLink !== '') attributesObj.compLink = compLink;
331345
if (cssClasses !== '') attributesObj.cssClasses = cssClasses;
332-
333-
const eventsObj: any = {};
334-
if (eventAll[0] !== '') eventsObj[eventAll[0]] = eventAll[1];
335-
336-
dispatch({
337-
type: 'UPDATE STATE USED',
338-
payload: {stateUsedObj: stateUsedObj}
339-
})
340-
dispatch({
341-
type: 'UPDATE USE CONTEXT',
342-
payload: { useContextObj: useContextObj}
343-
})
344-
dispatch({
345-
type: 'UPDATE CSS',
346-
payload: { style: styleObj }
347-
});
348346
dispatch({
349347
type: 'UPDATE ATTRIBUTES',
350348
payload: { attributes: attributesObj }
351349
});
350+
351+
const eventsObj: any = {};
352+
if (eventAll[0] !== '') eventsObj[eventAll[0]] = eventAll[1];
352353
dispatch({
353354
type: 'UPDATE EVENTS',
354355
payload: { events: eventsObj }
355356
});
356-
setEventAll(['', ''])
357357
// ------------------------------------------- change code above -------------------------------------------
358358
return styleObj;
359359
};
@@ -781,11 +781,11 @@ const CustomizationPanel = ({ isThemeLight }): JSX.Element => {
781781
/>
782782
</FormControl>
783783
</div> )}
784-
{ Object.keys(currFocus.events).length !== 0 && (<div className={'event-table'}>
784+
{ currFocus && Object.keys(currFocus.events).length !== 0 && (<div className={'event-table'}>
785785
<DataGrid
786786
rows={eventRow}
787787
columns={eventColumnTabs}
788-
// pageSize={5}
788+
pageSize={5}
789789
// editRowsModel={editRowsModel}
790790
// className={props.isThemeLight ? classes.themeLight : classes.themeDark}
791791
/>

0 commit comments

Comments
 (0)