@@ -8,7 +8,7 @@ import NewExportButton from './NewExportButton';
8
8
import { RootState } from '../../redux/store' ;
9
9
import logo from '../../public/icons/win/logo.png' ;
10
10
import { useSelector , useDispatch } from 'react-redux' ;
11
- import { publishProject } from '../../helperFunctions/projectGetSaveDel' ;
11
+ import { publishProject , unpublishProject } from '../../helperFunctions/projectGetSaveDel' ;
12
12
import PublishModal from './PublishModal' ;
13
13
import { updateProjectId , updateProjectName , updateProjectPublished } from '../../redux/reducers/slice/appStateSlice' ;
14
14
import { State } from '../../interfaces/Interfaces' ;
@@ -92,6 +92,27 @@ const NavBar = () => {
92
92
console . log ( 'stateName = ' , state . name ) ;
93
93
console . log ( 'published =' , state . published ) ;
94
94
} , [ state . name , state . published ] )
95
+
96
+ // handleUnpublish = () => {
97
+ // .then((project:State) => {
98
+ // dispatch(updateProjectPublished(project.published(false));
99
+ // })
100
+ // }
101
+
102
+ const handleUnpublish = ( ) => {
103
+ unpublishProject ( state )
104
+ . then ( ( unpublishedProject : State ) => {
105
+ console . log ( 'Project unpublished successfully' , unpublishedProject ) ;
106
+ dispatch ( updateProjectPublished ( false ) ) ;
107
+ } )
108
+ . catch ( ( error ) => {
109
+ console . error ( 'Error unpublishing project:' , error . message ) ;
110
+ } ) ;
111
+ } ;
112
+
113
+ // In handlePublish pass in state
114
+ //check to see if user is logged the same way as in publish project for the most part
115
+ // then somehow do dispatch(updateProjectPublished(newProject.published === false))
95
116
96
117
return (
97
118
< nav
@@ -111,9 +132,15 @@ const NavBar = () => {
111
132
</ div >
112
133
</ Link >
113
134
< div style = { buttonContainerStyle } >
114
- < button style = { buttonStyle } onClick = { handlePublish } >
115
- Publish
116
- </ button >
135
+ { state . published ? (
136
+ < button style = { buttonStyle } onClick = { handleUnpublish } >
137
+ Unpublish
138
+ </ button >
139
+ ) : (
140
+ < button style = { buttonStyle } onClick = { handlePublish } >
141
+ Publish
142
+ </ button >
143
+ ) }
117
144
< NewExportButton />
118
145
< Button
119
146
style = { moreVertButtonStyle }
0 commit comments