Skip to content

Commit 824d95d

Browse files
committed
updated broken publish button and switched import/export
1 parent 04c3de2 commit 824d95d

File tree

4 files changed

+103
-61
lines changed

4 files changed

+103
-61
lines changed

app/src/components/top/NavBar.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ import logo from '../../public/icons/win/logo.png';
1313
import { useSelector, useDispatch } from 'react-redux';
1414
import {
1515
publishProject,
16-
unpublishProject,
16+
unpublishProject
1717
} from '../../helperFunctions/projectGetSaveDel';
1818
import PublishModal from './PublishModal';
1919
import {
2020
updateProjectId,
2121
updateProjectName,
2222
updateProjectPublished,
23-
toggleScreenshotTrigger,
23+
toggleScreenshotTrigger
2424
} from '../../redux/reducers/slice/appStateSlice';
2525
import { State } from '../../interfaces/Interfaces';
2626

@@ -49,7 +49,8 @@ const NavBar: React.FC = (): JSX.Element => {
4949
const [publishModalOpen, setPublishModalOpen] = useState(false);
5050
const [projectName, setProjectName] = useState(state.name || '');
5151
const [invalidProjectName, setInvalidProjectName] = useState(false);
52-
const [invalidProjectNameMessage, setInvalidProjectNameMessage] = useState('');
52+
const [invalidProjectNameMessage, setInvalidProjectNameMessage] =
53+
useState('');
5354
const urlAdd = useHistory();
5455
const isMarketplace = urlAdd.location.pathname === '/marketplace';
5556

@@ -76,19 +77,19 @@ const NavBar: React.FC = (): JSX.Element => {
7677
const buttonContainerStyle = {
7778
display: 'flex',
7879
alignItems: 'center',
79-
justifyContent: 'flex-start',
80+
justifyContent: 'flex-start'
8081
};
8182

8283
const buttonStyle = {
83-
backgroundColor: '#0671E3',
84+
backgroundColor: '#2D313A',
8485
border: 'none',
8586
color: 'white',
8687
fontSize: '12px',
8788
padding: '8px 15px',
8889
cursor: 'pointer',
8990
marginRight: '10px',
9091
marginLeft: '5px',
91-
borderRadius: '10px',
92+
borderRadius: '10px'
9293
};
9394

9495
const moreVertButtonStyle = {
@@ -103,7 +104,7 @@ const NavBar: React.FC = (): JSX.Element => {
103104
minWidth: '20px',
104105
marginLeft: '0px',
105106
marginRight: '10px',
106-
boxShadow: 'none',
107+
boxShadow: 'none'
107108
};
108109

109110
const handlePublish = () => {
@@ -142,7 +143,7 @@ const NavBar: React.FC = (): JSX.Element => {
142143

143144
const handleAlertClose = (
144145
event: React.SyntheticEvent | Event,
145-
reason?: string,
146+
reason?: string
146147
) => {
147148
if (reason === 'clickaway') {
148149
return;
@@ -156,7 +157,7 @@ const NavBar: React.FC = (): JSX.Element => {
156157

157158
const Alert = React.forwardRef<HTMLDivElement, AlertProps>(function Alert(
158159
props,
159-
ref,
160+
ref
160161
) {
161162
return <MuiAlert elevation={6} ref={ref} variant="filled" {...props} />;
162163
});
@@ -178,7 +179,7 @@ const NavBar: React.FC = (): JSX.Element => {
178179
</button>
179180
) : (
180181
<button style={buttonStyle} onClick={handlePublish}>
181-
Publish
182+
Import
182183
</button>
183184
)}
184185
<NewExportButton />

app/src/components/top/NavBarButtons.tsx

Lines changed: 87 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ import { resetAllState } from '../../redux/reducers/slice/appStateSlice';
2323
import { setStyle } from '../../redux/reducers/slice/styleSlice';
2424
import { emitEvent } from '../../helperFunctions/socket';
2525

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+
2635
const { API_BASE_URL } = serverConfig;
2736

2837
const useStyles = makeStyles((theme) => createStyles({
@@ -121,50 +130,70 @@ const navbarDropDown = (props): JSX.Element => {
121130
props.setDropDownMenu(true);
122131
};
123132

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+
// );
152161

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+
// };
167176

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+
};
168197
const handleClose = () => {
169198
setAnchorEl(null);
170199
props.setDropMenu(false);
@@ -217,7 +246,21 @@ const navbarDropDown = (props): JSX.Element => {
217246
<span>Tutorial</span>
218247
</button>
219248
</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()}>
221264
<svg
222265
xmlns="http://www.w3.org/2000/svg"
223266
width="16"
@@ -229,7 +272,7 @@ const navbarDropDown = (props): JSX.Element => {
229272
<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" />
230273
</svg>
231274
<span>Clear Canvas</span>
232-
</button>
275+
</button> */}
233276
{state.isLoggedIn && (
234277
<button onClick={handleClick}>
235278
<svg

app/src/components/top/NewExportButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default function NewExportButton(): JSX.Element {
3333
const closeModal = () => setModal('');
3434

3535
const buttonStyle = {
36-
backgroundColor: '#2D313A',
36+
backgroundColor: '#0671E3',
3737
border: 'none',
3838
color: 'white',
3939
fontSize: '12px',

app/src/components/top/PublishModal.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ const PublishModal = ({
3535
projectName,
3636
onChange,
3737
invalidProjectName,
38-
invalidProjectNameMessage,
39-
}): JSX.Element => {
40-
return (
38+
invalidProjectNameMessage
39+
}): JSX.Element => (
4140
<Dialog
4241
style={{ color: '#000' }}
4342
open={open}
@@ -68,11 +67,10 @@ const PublishModal = ({
6867
Cancel
6968
</Button>
7069
<Button onClick={onSave} color="primary">
71-
Publish
70+
Import
7271
</Button>
7372
</DialogActions>
7473
</Dialog>
75-
);
76-
};
74+
);
7775

7876
export default PublishModal;

0 commit comments

Comments
 (0)