1
- import React , { useState , useEffect } from 'react' ;
1
+ import React , { useState , useContext , useEffect } from 'react' ;
2
2
import { makeStyles } from '@material-ui/core/styles' ;
3
3
import Button from '@material-ui/core/Button' ;
4
4
import Avatar from '@material-ui/core/Avatar' ;
@@ -8,12 +8,12 @@ import ListItemAvatar from '@material-ui/core/ListItemAvatar';
8
8
import ListItemText from '@material-ui/core/ListItemText' ;
9
9
import DialogTitle from '@material-ui/core/DialogTitle' ;
10
10
import Dialog from '@material-ui/core/Dialog' ;
11
- import PersonIcon from '@material-ui/icons/Person ' ;
11
+ import FolderOpenIcon from '@material-ui/icons/FolderOpen ' ;
12
12
import AddIcon from '@material-ui/icons/Add' ;
13
- import Typography from '@material-ui/core/Typography' ;
14
13
import { blue } from '@material-ui/core/colors' ;
15
14
16
15
import { getProjects } from '../../helperFunctions/projectGetSave' ;
16
+ import { stateContext } from '../../context/context' ;
17
17
18
18
const useStyles = makeStyles ( {
19
19
avatar : {
@@ -28,12 +28,15 @@ export interface ProjectDialogProps {
28
28
onClose : ( ) => void ;
29
29
}
30
30
31
- //const projects = ['test'];
32
-
33
31
// The options to be rendered when dialog is open
34
32
function ProjectsDialog ( props : ProjectDialogProps ) {
35
33
const classes = useStyles ( ) ;
36
34
const { onClose, open, projects } = props ;
35
+ const [ _ , dispatch ] = useContext ( stateContext ) ;
36
+
37
+ useEffect ( ( ) => {
38
+ console . log ( 'state is' , _ ) ;
39
+ } , [ _ ] )
37
40
38
41
// If no projects selected, keep the name of the current displayed
39
42
const handleClose = ( ) => {
@@ -44,25 +47,28 @@ function ProjectsDialog(props: ProjectDialogProps) {
44
47
45
48
// If new project selected, close and set value to new project name
46
49
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 } ) ;
47
53
onClose ( ) ;
48
54
} ;
49
55
50
56
return (
51
57
< Dialog onClose = { handleClose } aria-labelledby = "project-dialog-title" open = { open } >
52
58
< DialogTitle id = "project-dialog-title" > Open Project</ DialogTitle >
53
59
< 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 } >
56
62
< ListItemAvatar >
57
63
< Avatar className = { classes . avatar } >
58
- < PersonIcon />
64
+ < FolderOpenIcon />
59
65
</ Avatar >
60
66
</ ListItemAvatar >
61
67
< ListItemText primary = { project . name } />
62
68
</ ListItem >
63
69
) ) }
64
70
{ /* Change state to empty for new project */ }
65
- < ListItem autoFocus button onClick = { ( ) => handleListItemClick ( 'addProject' ) } >
71
+ < ListItem autoFocus button onClick = { ( ) => handleClose ( ) } >
66
72
< ListItemAvatar >
67
73
< Avatar >
68
74
< AddIcon />
0 commit comments