Skip to content

Commit 73f9ce0

Browse files
committed
denton fixed clicking outside of dropdown, fixed wrong project with the same name being opened
1 parent 9d1b9d3 commit 73f9ce0

File tree

5 files changed

+31
-37
lines changed

5 files changed

+31
-37
lines changed

app/src/components/main/DemoRender.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ const DemoRender = (): JSX.Element => {
2323
width: '100%',
2424
backgroundColor: '#FBFBFB',
2525
borderBottom: 'none',
26-
overflow: 'auto'
26+
overflow: 'auto',
27+
2728
};
2829

2930
const html = `
@@ -48,6 +49,10 @@ const DemoRender = (): JSX.Element => {
4849
app.innerHTML = '<div style="color: red;"><h4>Syntax Error</h4>' + err + '</div>';
4950
}
5051
}, false);
52+
const handleClickInsideIframe = () => {
53+
window.parent.postMessage('iframeClicked', '*');
54+
};
55+
window.addEventListener('click', handleClickInsideIframe);
5156
</script>
5257
</body>
5358
</html>
@@ -200,6 +205,7 @@ const DemoRender = (): JSX.Element => {
200205
srcDoc={html}
201206
width="100%"
202207
height="100%"
208+
style = {{zIndex: -30}}
203209
/>
204210
</div>
205211
</>

app/src/components/right/OpenProjects.tsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,15 @@ function ProjectsDialog(props: ProjectDialogProps) {
3232
};
3333
// If new project selected, close and set value to new project name
3434
const handleListItemClick = (value: string) => {
35+
console.log('hadleList value', value)
3536
const selectedProject = projects.filter(
36-
(project: any) => project.name === value
37+
(project: any) => project._id === value
3738
)[0];
3839
// dispatch({ type: 'OPEN PROJECT', payload: selectedProject });
3940
console.log(selectedProject);
4041
dispatch(openProject(selectedProject))
4142
onClose();
4243
};
43-
// these two filter between user projects and market projects
44-
// const userProjects = projects.filter((project: any) => {
45-
// project.forked === undefined
46-
// })
47-
// const marketProjects = projects.filter((project: any) => {
48-
// project.forked !== undefined
49-
// })
5044

5145
return (
5246
<Dialog
@@ -60,7 +54,7 @@ function ProjectsDialog(props: ProjectDialogProps) {
6054
{projects.filter((project: any) => project.forked === undefined || project.forked === false).map((project: any, index: number) => (
6155
<ListItem
6256
button
63-
onClick={() => handleListItemClick(project.name)}
57+
onClick={() => handleListItemClick(project._id)}
6458
key={index}
6559
>
6660
<ListItemAvatar>
@@ -76,10 +70,10 @@ function ProjectsDialog(props: ProjectDialogProps) {
7670
{/* this section handles the projects cloned from the marketplace */}
7771
<DialogTitle style={{ color: "#000" }} id="project-dialog-title">MP Projects</DialogTitle>
7872
<List style={{ color: "#000" }}>
79-
{projects.filter((project: any) => project.forked === true).map((project: any, index: number) => (
73+
{projects.filter((project: any) => project.forked === true).map((project: any, index: number) => (
8074
<ListItem
8175
button
82-
onClick={() => handleListItemClick(project.name)}
76+
onClick={() => handleListItemClick(project._id)}
8377
key={index}
8478
>
8579
<ListItemAvatar>

app/src/components/top/NavBar.tsx

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,6 @@ const NavBar = () => {
8888

8989
};
9090

91-
useEffect(()=>{
92-
console.log('stateName = ',state.name);
93-
console.log('published =', state.published);
94-
}, [state.name, state.published])
95-
96-
// handleUnpublish = () => {
97-
// .then((project:State) => {
98-
// dispatch(updateProjectPublished(project.published(false));
99-
// })
100-
// }
101-
10291
const handleUnpublish = () => {
10392
unpublishProject(state)
10493
.then((unpublishedProject: State) => {
@@ -110,10 +99,6 @@ const NavBar = () => {
11099
});
111100
};
112101

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))
116-
117102
return (
118103
<nav
119104
className="main-navbar"

app/src/components/top/NavBarButtons.tsx

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useRef } from 'react';
1+
import React, { Ref, useEffect, useRef } from 'react';
22
import { useDispatch, useSelector } from 'react-redux';
33

44
import { Button } from '@mui/material';
@@ -295,29 +295,39 @@ function navbarDropDown(props) {
295295
let showMenu = props.dropMenu ? 'navDropDown' : 'hideNavDropDown';
296296

297297
//for closing the menu on clicks outside of it.
298-
const useOutsideClick = (callback) => {
298+
const useOutsideClick = () => {
299299
const dropdownRef = useRef(null);
300300

301301
useEffect(() => {
302302
const handleClick = (event) => {
303-
if (
304-
dropdownRef.current &&
305-
!dropdownRef.current.contains(event.target)
303+
if (event.type === "click" &&
304+
(dropdownRef.current &&
305+
!dropdownRef.current.contains(event.target)) || event.type === "message" && event.data === 'iframeClicked'
306306
) {
307-
callback();
307+
handleClose();
308308
}
309309
};
310-
document.addEventListener('click', handleClick, true);
310+
window.addEventListener('click', handleClick, true);
311+
window.addEventListener('message', handleClick);//to capture clicks in the iframe
311312

312313
return () => {
313-
document.removeEventListener('click', handleClick, true); //cleanup for memory purposes. ensures handleclick isn't called after the component is no longer rendered
314+
window.removeEventListener('click', handleClick, true);
315+
window.addEventListener('message', handleClick); //cleanup for memory purposes. ensures handleclick isn't called after the component is no longer rendered
314316
};
315317
}, [dropdownRef]);
316318

317319
return dropdownRef;
318320
};
319321

320-
const ref = useOutsideClick(handleClose);
322+
const ref = useOutsideClick();
323+
324+
// const handleMessage = (event) => {
325+
// if (event.data === 'iframeClicked') {
326+
// // Handle the click event here, e.g., close the dropdown menu
327+
// handleClose();
328+
// }
329+
// };
330+
// window.addEventListener('message', handleMessage);
321331

322332
return (
323333
// <div ref={dropdownRef} className={showMenu}> dropdownRef making the menu fly off and anchorel messingup

server/controllers/marketplaceController.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ const marketplaceController: MarketplaceController = {
3939
publishProject: async (req, res, next) => {
4040
const { _id, project, comments, userId, username, name } = req.body;
4141
const createdAt = Date.now();
42-
console.log('Publish Project', _id, project, comments, userId, username, name )
4342

4443
if (userId === req.cookies.ssid) {
4544

0 commit comments

Comments
 (0)