Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Context menu #801

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 120 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
"react-router-dom": "^6.24.1",
"sharedb": "^5.0.2",
"sharedb-client-browser": "^5.0.2",
"styled-components": "^6.1.12",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not adopt styled-components please. We are already all set up with Sass.

"vizhub-ui": "^3.23.0",
"ws": "^8.18.0"
},
Expand Down
27 changes: 27 additions & 0 deletions src/client/VZSidebar/ContextMenu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import styled, { css } from "styled-components";

export const ContextMenu = styled.div`
position: absolute;
width: 200px;
background-color: #383838;
border-radius: 5px;
box-sizing: border-box;
${({ top, left }) => css`
top: ${top}px;
left: ${left}px;
`}
ul {
box-sizing: border-box;
padding: 10px;
margin: 0;
list-style: none;
}
ul li {
padding: 18px 12px;
}
/* hover */
ul li:hover {
cursor: pointer;
background-color: #000000;
}
`;
63 changes: 53 additions & 10 deletions src/client/VZSidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
useContext,
useMemo,
useState,
useEffect
} from 'react';
import {
FileId,
Expand All @@ -28,6 +29,7 @@ import { VZCodeContext } from '../VZCodeContext';
import { Listing } from './Listing';
import { useDragAndDrop } from './useDragAndDrop';
import './styles.scss';
import {ContextMenu} from "./ContextMenu.js"

// TODO turn this UI back on when we are actually detecting
// the connection status.
Expand Down Expand Up @@ -111,6 +113,20 @@ export const VZSidebar = ({
handleDrop,
} = useDragAndDrop();

const [clicked, setClicked] = useState(false);
const [points, setPoints] = useState({
x: 0,
y: 0,
});

useEffect(()=>{
const handleClick = () => setClicked(false);
window.addEventListener("click", handleClick);
return () => {
window.removeEventListener("click", handleClick);
};
}, []);

return (
<div
className="vz-sidebar"
Expand Down Expand Up @@ -290,15 +306,27 @@ export const VZSidebar = ({
const { fileId } = entity as FileTreeFile;
const { path } = entity as FileTree;
const key = fileId ? fileId : path;

return (
<Listing
key={key}
entity={entity}
handleFileClick={handleFileClick}
handleFileDoubleClick={
handleFileDoubleClick
}
/>
<div
onContextMenu={(e)=>{
e.preventDefault();
setClicked(true);
setPoints({
x: e.pageX,
y: e.pageY
});

}}>
<Listing
key={key}
entity={entity}
handleFileClick={handleFileClick}
handleFileDoubleClick={
handleFileDoubleClick
}
/>
</div>
);
})
) : (
Expand All @@ -309,13 +337,26 @@ export const VZSidebar = ({
above to create your first file.
</div>
</div>
)}
)
}
</div>
) : (
<div className="sidebar-search">
<Search />
</div>
)}
)

}
{clicked && (
<ContextMenu top = {points.y} left = {points.x}>
<ul>
<li>Edit</li>
<li>Copy</li>
<li>Delete</li>
</ul>
</ContextMenu>
)
}
</div>
</div>

Expand All @@ -332,5 +373,7 @@ export const VZSidebar = ({
</div>
)}
</div>


);
};
1 change: 1 addition & 0 deletions src/client/VZSidebar/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,4 @@
}
}
}