@@ -7,17 +7,17 @@ import {
7
7
PUBLISH_PROJECT ,
8
8
ADD_COMMENT ,
9
9
} from './gqlStrings' ;
10
- import {
11
- withStyles ,
12
- createStyles ,
13
- makeStyles ,
14
- Theme
15
- } from '@material-ui/core/styles' ;
10
+ import { withStyles , createStyles , makeStyles , Theme } from '@material-ui/core/styles' ;
16
11
import CloseIcon from '@material-ui/icons/Close' ;
17
12
import FavoriteBorderIcon from '@material-ui/icons/FavoriteBorder' ;
13
+ import FavoriteIcon from '@material-ui/icons/Favorite' ;
18
14
import GetAppIcon from '@material-ui/icons/GetApp' ;
19
15
import IconButton from '@material-ui/core/IconButton' ;
20
16
import PublishIcon from '@material-ui/icons/Publish' ;
17
+ import List from '@material-ui/core/List' ;
18
+ import ListItem from '@material-ui/core/ListItem' ;
19
+ import ListItemText from '@material-ui/core/ListItemText' ;
20
+ import createModal from '../components/right/createModal' ;
21
21
// Variable validation using typescript
22
22
type props = {
23
23
name : string ,
@@ -41,19 +41,28 @@ const Project = ({
41
41
// 2) always request the 'id' in a mutation request
42
42
const [ commentVal , setCommentVal ] = useState ( '' ) ;
43
43
const [ clicked , setClicked ] = useState ( false ) ;
44
+ const [ modal , setModal ] = useState ( null ) ;
44
45
45
46
const [ addLike ] = useMutation ( ADD_LIKE ) ;
46
47
const [ makeCopy ] = useMutation ( MAKE_COPY ) ;
47
48
const [ deleteProject ] = useMutation ( DELETE_PROJECT ) ;
48
49
const [ publishProject ] = useMutation ( PUBLISH_PROJECT ) ;
49
50
const [ addComment ] = useMutation ( ADD_COMMENT ) ;
50
51
51
- const handleIconClick = ( id ) => {
52
- setClicked ( true ) ;
53
- }
52
+ const noPointer = { cursor : 'default' } ;
54
53
54
+ // const handleIconClick = () => {
55
+ // if(clicked === false) {
56
+ // setClicked(true);
57
+ // } else if (clicked === true) {
58
+ // setClicked(false);
59
+ // }
60
+ // }
61
+
62
+ //Likes the project when the heart icon is clicked
55
63
function handleLike ( e ) {
56
64
e . preventDefault ( ) ;
65
+ ( clicked === false ) ? setClicked ( true ) : ( clicked === true ) ? setClicked ( false ) : '' ;
57
66
const myVar = {
58
67
variables :
59
68
{
@@ -65,7 +74,7 @@ const Project = ({
65
74
addLike ( myVar ) ;
66
75
}
67
76
68
-
77
+ //Makes a copy of the public project and saves as a user project
69
78
function handleDownload ( e ) {
70
79
e . preventDefault ( ) ;
71
80
const myVar = {
@@ -79,17 +88,7 @@ const Project = ({
79
88
makeCopy ( myVar ) ;
80
89
}
81
90
82
- function handleDelete ( e ) {
83
- e . preventDefault ( ) ;
84
- const myVar = {
85
- variables :
86
- {
87
- projId : id ,
88
- } ,
89
- } ;
90
- deleteProject ( myVar ) ;
91
- }
92
-
91
+ //Publishes project from user dashboard to public dashboard
93
92
function handlePublish ( e ) {
94
93
e . preventDefault ( ) ;
95
94
const myVar = {
@@ -102,6 +101,7 @@ const Project = ({
102
101
publishProject ( myVar ) ;
103
102
}
104
103
104
+ //Adds the comment to the project
105
105
function handleComment ( e ) {
106
106
e . preventDefault ( ) ;
107
107
const myVar = {
@@ -115,11 +115,13 @@ const Project = ({
115
115
addComment ( myVar )
116
116
}
117
117
118
+ //sets state of commentVal to what the user types in to comment
118
119
function handleChange ( e ) {
119
120
const inputVal = e . target . value ;
120
121
setCommentVal ( inputVal ) ;
121
122
}
122
123
124
+ //renders the last 5 comments into the comment area
123
125
const recentComments = [ ] ;
124
126
if ( comments . length > 0 ) {
125
127
const reversedCommentArray = comments . slice ( 0 ) . reverse ( ) ;
@@ -132,12 +134,66 @@ const Project = ({
132
134
) }
133
135
}
134
136
135
- const noPointer = { cursor : 'default' } ;
137
+ // ---Clear canvas functionality---
138
+ // Closes out the open modal
139
+ const closeModal = ( ) => setModal ( '' ) ;
140
+
141
+ // Creates modal that asks if user wants to clear workspace
142
+ // If user clears their workspace, then their components are removed from state and the modal is closed
143
+ const clearWorkspace = ( ) => {
144
+ //Deletes project from the database
145
+ const handleDelete = ( e ) => {
146
+ e . preventDefault ( ) ;
147
+ const myVar = {
148
+ variables :
149
+ {
150
+ projId : id ,
151
+ } ,
152
+ } ;
153
+ deleteProject ( myVar ) ;
154
+ }
155
+
156
+ // Set modal options
157
+ const children = (
158
+ < List className = "export-preference" >
159
+ < ListItem
160
+ key = { 'clear' }
161
+ button
162
+ onClick = { handleDelete }
163
+ style = { {
164
+ border : '1px solid #3f51b5' ,
165
+ marginBottom : '2%' ,
166
+ marginTop : '5%'
167
+ } }
168
+ >
169
+ < ListItemText
170
+ primary = { 'Yes, delete this project' }
171
+ style = { { textAlign : 'center' } }
172
+ onClick = { closeModal }
173
+ />
174
+ </ ListItem >
175
+ </ List >
176
+ ) ;
177
+
178
+ // Create modal
179
+ setModal (
180
+ createModal ( {
181
+ closeModal,
182
+ children,
183
+ message : 'Are you sure want to delete this project?' ,
184
+ primBtnLabel : null ,
185
+ primBtnAction : null ,
186
+ secBtnAction : null ,
187
+ secBtnLabel : null ,
188
+ open : true
189
+ } )
190
+ ) ;
191
+ } ;
136
192
137
193
return (
138
194
< div className = 'project' >
139
195
{ currUsername === username ?
140
- < IconButton tooltip = "Delete Project" onClick = { handleDelete } style = { { position : 'absolute' , right : '0' , padding : '0' } } >
196
+ < IconButton tooltip = "Delete Project" onClick = { clearWorkspace } style = { { position : 'absolute' , right : '0' , padding : '0' } } >
141
197
< CloseIcon />
142
198
</ IconButton >
143
199
: '' }
@@ -147,18 +203,16 @@ const Project = ({
147
203
< h3 > Likes: { likes } </ h3 >
148
204
</ div >
149
205
< div className = "icons" >
150
- { currUsername !== username ?
151
206
< IconButton tooltip = "Like Template" style = { noPointer } onClick = { handleLike } >
152
- < FavoriteBorderIcon fontSize = "large" className = "heart" style = { noPointer } />
207
+ { clicked ? < FavoriteIcon fontSize = 'Large' color = 'secondary' /> : < FavoriteBorderIcon fontSize = 'Large' /> }
153
208
</ IconButton >
154
- : '' }
155
209
{ currUsername !== username ?
156
210
< IconButton tooltip = "Download Template" style = { noPointer } onClick = { handleDownload } >
157
211
< GetAppIcon fontSize = "large" className = "download" />
158
212
</ IconButton >
159
213
: '' }
160
214
{ currUsername === username ?
161
- < IconButton tooltip = "Download Template" style = { noPointer } onClick = { handlePublish } >
215
+ < IconButton tooltip = "Publish Template" style = { noPointer } onClick = { handlePublish } >
162
216
< PublishIcon fontSize = "large" />
163
217
</ IconButton >
164
218
: '' }
@@ -176,6 +230,7 @@ const Project = ({
176
230
</ div >
177
231
</ div >
178
232
: '' }
233
+ { modal }
179
234
</ div >
180
235
) ;
181
236
} ;
0 commit comments