Skip to content

Commit be1d731

Browse files
committed
working PorjectsFolder component, issues with Canvas Focus rendering
1 parent 769a9c7 commit be1d731

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

src/components/login/ProjectsFolder.tsx

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useEffect } from 'react';
1+
import React, { useState, useContext, useEffect } from 'react';
22
import { makeStyles } from '@material-ui/core/styles';
33
import Button from '@material-ui/core/Button';
44
import Avatar from '@material-ui/core/Avatar';
@@ -8,12 +8,12 @@ import ListItemAvatar from '@material-ui/core/ListItemAvatar';
88
import ListItemText from '@material-ui/core/ListItemText';
99
import DialogTitle from '@material-ui/core/DialogTitle';
1010
import Dialog from '@material-ui/core/Dialog';
11-
import PersonIcon from '@material-ui/icons/Person';
11+
import FolderOpenIcon from '@material-ui/icons/FolderOpen';
1212
import AddIcon from '@material-ui/icons/Add';
13-
import Typography from '@material-ui/core/Typography';
1413
import { blue } from '@material-ui/core/colors';
1514

1615
import { getProjects } from '../../helperFunctions/projectGetSave';
16+
import { stateContext } from '../../context/context';
1717

1818
const useStyles = makeStyles({
1919
avatar: {
@@ -28,12 +28,15 @@ export interface ProjectDialogProps {
2828
onClose: () => void;
2929
}
3030

31-
//const projects = ['test'];
32-
3331
// The options to be rendered when dialog is open
3432
function ProjectsDialog(props: ProjectDialogProps) {
3533
const classes = useStyles();
3634
const { onClose, open, projects } = props;
35+
const [_, dispatch] = useContext(stateContext);
36+
37+
useEffect(() => {
38+
console.log('state is', _);
39+
}, [_])
3740

3841
// If no projects selected, keep the name of the current displayed
3942
const handleClose = () => {
@@ -44,25 +47,28 @@ function ProjectsDialog(props: ProjectDialogProps) {
4447

4548
// If new project selected, close and set value to new project name
4649
const handleListItemClick = (value: string) => {
50+
const selectedProject = projects.filter(project => project.name === value)[0].project;
51+
console.log('project to open', selectedProject);
52+
dispatch({ type: 'OPEN PROJECT', payload: selectedProject });
4753
onClose();
4854
};
4955

5056
return (
5157
<Dialog onClose={handleClose} aria-labelledby="project-dialog-title" open={open}>
5258
<DialogTitle id="project-dialog-title">Open Project</DialogTitle>
5359
<List>
54-
{projects.map((project) => (
55-
<ListItem button onClick={() => handleListItemClick(project.name)} key={project.name}>
60+
{projects.map((project, index) => (
61+
<ListItem button onClick={() => handleListItemClick(project.name)} key={index}>
5662
<ListItemAvatar>
5763
<Avatar className={classes.avatar}>
58-
<PersonIcon />
64+
<FolderOpenIcon />
5965
</Avatar>
6066
</ListItemAvatar>
6167
<ListItemText primary={project.name} />
6268
</ListItem>
6369
))}
6470
{/* Change state to empty for new project */}
65-
<ListItem autoFocus button onClick={() => handleListItemClick('addProject')}>
71+
<ListItem autoFocus button onClick={() => handleClose()}>
6672
<ListItemAvatar>
6773
<Avatar>
6874
<AddIcon />

src/containers/LeftContainer.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ const useStyles = makeStyles({
6060
const LeftContainer = (): JSX.Element => {
6161
const [state, dispatch] = useContext(stateContext);
6262
const classes = useStyles();
63-
const [projectName, setprojectName] = useState('');
64-
console.log('projectName is', projectName);
6563
// state to keep track of how the user wants their components to be exported
6664
// genOption = 0 --> export only components
6765
// genOption = 1 --> export an entire project w/ webpack, server, etc.

src/reducers/componentReducer.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ const reducer = (state: State, action: Action) => {
262262
const canvasFocus = { ...state.canvasFocus, childId: null };
263263
return { ...state, components, canvasFocus };
264264
}
265+
265266
case 'SET INITIAL STATE': {
266267
return { ...action.payload };
267268
}
@@ -274,9 +275,23 @@ const reducer = (state: State, action: Action) => {
274275
}
275276
}
276277

278+
case 'OPEN PROJECT': {
279+
const { name, components, rootComponents, canvasFocus, nextComponentId, nextChildId } = action.payload;
280+
console.log('triggered reducer');
281+
return {
282+
...state,
283+
name: name,
284+
components: components,
285+
rootComponents: rootComponents,
286+
nextComponentId: nextComponentId,
287+
nextChildId: nextChildId,
288+
canvasFocus: canvasFocus
289+
}
290+
}
291+
277292
default:
278293
return state;
279294
}
280295
};
281296

282-
export default reducer;
297+
export default reducer;

0 commit comments

Comments
 (0)