@@ -23,6 +23,15 @@ import { resetAllState } from '../../redux/reducers/slice/appStateSlice';
23
23
import { setStyle } from '../../redux/reducers/slice/styleSlice' ;
24
24
import { emitEvent } from '../../helperFunctions/socket' ;
25
25
26
+ // added imports for publish logic
27
+ import { publishProject } from '../../helperFunctions/projectGetSaveDel' ;
28
+ import {
29
+ updateProjectId ,
30
+ updateProjectName ,
31
+ updateProjectPublished ,
32
+ toggleScreenshotTrigger ,
33
+ } from '../../redux/reducers/slice/appStateSlice' ;
34
+
26
35
const { API_BASE_URL } = serverConfig ;
27
36
28
37
const useStyles = makeStyles ( ( theme ) => createStyles ( {
@@ -121,50 +130,70 @@ const navbarDropDown = (props): JSX.Element => {
121
130
props . setDropDownMenu ( true ) ;
122
131
} ;
123
132
124
- const clearWorkspace = ( ) => {
125
- // Reset state for project to initial state
126
- const resetState = ( ) => {
127
- if ( roomCode ) emitEvent ( 'clearCanvasAction' , roomCode , userName ) ;
128
- else dispatch ( resetAllState ( ) ) ;
129
- } ;
130
- // Set modal options
131
- const children = (
132
- < List className = "export-preference" style = { { zIndex : '12' } } >
133
- < ListItem
134
- key = { 'clear' }
135
- button
136
- onClick = { resetState }
137
- style = { {
138
- backgroundColor : '#E12D39' ,
139
- borderRadius : '50px' ,
140
- marginBottom : '2%' ,
141
- marginTop : '5%' ,
142
- } }
143
- >
144
- < ListItemText
145
- primary = { 'Yes, delete all project data' }
146
- style = { { textAlign : 'center' } }
147
- onClick = { closeModal }
148
- />
149
- </ ListItem >
150
- </ List >
151
- ) ;
133
+ // const clearWorkspace = () => {
134
+ // // Reset state for project to initial state
135
+ // const resetState = () => {
136
+ // if (roomCode) emitEvent('clearCanvasAction', roomCode, userName);
137
+ // else dispatch(resetAllState());
138
+ // };
139
+ // // Set modal options
140
+ // const children = (
141
+ // <List className="export-preference" style={{ zIndex: '12' }}>
142
+ // <ListItem
143
+ // key={'clear'}
144
+ // button
145
+ // onClick={resetState}
146
+ // style={{
147
+ // backgroundColor: '#E12D39',
148
+ // borderRadius: '50px',
149
+ // marginBottom: '2%',
150
+ // marginTop: '5%',
151
+ // }}
152
+ // >
153
+ // <ListItemText
154
+ // primary={'Yes, delete all project data'}
155
+ // style={{ textAlign: 'center' }}
156
+ // onClick={closeModal}
157
+ // />
158
+ // </ListItem>
159
+ // </List>
160
+ // );
152
161
153
- // Create modal
154
- setModal (
155
- createModal ( {
156
- closeModal,
157
- children,
158
- message : 'Are you sure you want to delete all data?' ,
159
- primBtnLabel : null ,
160
- primBtnAction : null ,
161
- secBtnAction : null ,
162
- secBtnLabel : null ,
163
- open : true ,
164
- } ) ,
165
- ) ;
166
- } ;
162
+ // // Create modal
163
+ // setModal(
164
+ // createModal({
165
+ // closeModal,
166
+ // children,
167
+ // message: 'Are you sure you want to delete all data?',
168
+ // primBtnLabel: null,
169
+ // primBtnAction: null,
170
+ // secBtnAction: null,
171
+ // secBtnLabel: null,
172
+ // open: true,
173
+ // }),
174
+ // );
175
+ // };
167
176
177
+ // handlePublish logic
178
+ const handlePublish = ( ) => {
179
+ if ( ! state . name ) {
180
+ console . error ( 'Project name cannot be empty' ) ;
181
+ return ;
182
+ }
183
+ if ( ! state . isLoggedIn ) {
184
+ console . error ( 'User must be logged in to publish' ) ;
185
+ return ;
186
+ }
187
+ publishProject ( state . name , state )
188
+ . then ( ( newProject ) => {
189
+ dispatch ( updateProjectId ( newProject . _id ) ) ;
190
+ dispatch ( updateProjectName ( newProject . name ) ) ;
191
+ dispatch ( updateProjectPublished ( newProject . published ) ) ;
192
+ dispatch ( toggleScreenshotTrigger ( ) ) ;
193
+ console . log ( 'Project published successfully!' ) ;
194
+ } )
195
+ . catch ( ( error ) => console . error ( 'Error publishing project:' , error ) ) ;
196
+ } ;
168
197
const handleClose = ( ) => {
169
198
setAnchorEl ( null ) ;
170
199
props . setDropMenu ( false ) ;
@@ -217,7 +246,21 @@ const navbarDropDown = (props): JSX.Element => {
217
246
< span > Tutorial</ span >
218
247
</ button >
219
248
</ Link >
220
- < button onClick = { ( ) => clearWorkspace ( ) } >
249
+ < button onClick = { handlePublish } style = { { backgroundColor : '#0671E3' , color : 'white' } } >
250
+ < svg
251
+ xmlns = "http://www.w3.org/2000/svg"
252
+ width = "16"
253
+ height = "16"
254
+ fill = "currentColor"
255
+ className = "bi bi-upload"
256
+ viewBox = "0 0 16 16"
257
+ >
258
+ < path d = "M.5 9.5a.5.5 0 0 0 .5.5h3v5a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1v-5h3a.5.5 0 0 0 .5-.5v-4a.5.5 0 0 0-.5-.5H10V1.5a.5.5 0 0 0-1 0v3H7V1.5a.5.5 0 0 0-1 0v3H.5a.5.5 0 0 0-.5.5v4z" />
259
+ < path d = "M7 6v6h2V6H7z" />
260
+ </ svg >
261
+ < span > Publish</ span >
262
+ </ button >
263
+ { /* <button onClick={() => clearWorkspace()}>
221
264
<svg
222
265
xmlns="http://www.w3.org/2000/svg"
223
266
width="16"
@@ -229,7 +272,7 @@ const navbarDropDown = (props): JSX.Element => {
229
272
<path d="M6.5 1h3a.5.5 0 0 1 .5.5v1H6v-1a.5.5 0 0 1 .5-.5ZM11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3A1.5 1.5 0 0 0 5 1.5v1H2.506a.58.58 0 0 0-.01 0H1.5a.5.5 0 0 0 0 1h.538l.853 10.66A2 2 0 0 0 4.885 16h6.23a2 2 0 0 0 1.994-1.84l.853-10.66h.538a.5.5 0 0 0 0-1h-.995a.59.59 0 0 0-.01 0H11Zm1.958 1-.846 10.58a1 1 0 0 1-.997.92h-6.23a1 1 0 0 1-.997-.92L3.042 3.5h9.916Zm-7.487 1a.5.5 0 0 1 .528.47l.5 8.5a.5.5 0 0 1-.998.06L5 5.03a.5.5 0 0 1 .47-.53Zm5.058 0a.5.5 0 0 1 .47.53l-.5 8.5a.5.5 0 1 1-.998-.06l.5-8.5a.5.5 0 0 1 .528-.47ZM8 4.5a.5.5 0 0 1 .5.5v8.5a.5.5 0 0 1-1 0V5a.5.5 0 0 1 .5-.5Z" />
230
273
</svg>
231
274
<span>Clear Canvas</span>
232
- </ button >
275
+ </button> */ }
233
276
{ state . isLoggedIn && (
234
277
< button onClick = { handleClick } >
235
278
< svg
0 commit comments