-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProjectCard.tsx
74 lines (65 loc) · 2.96 KB
/
ProjectCard.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { Link } from "react-router-dom";
import { ProjectData } from "../../models/schedule";
export default function ProjectCard({ project, owner }: { project: ProjectData, owner: boolean }) {
const contextMenu = document.getElementById('contextMenu')
const deletePopup = document.getElementById('deletePopup')
function positionContextMenu(target: HTMLElement) {
if (!contextMenu || !deletePopup) return
contextMenu.setAttribute('data-id', project.id)
deletePopup.setAttribute('data-id', project.id)
const posX = window.scrollX + target.getBoundingClientRect().left + 25
const posY = window.scrollY + target.getBoundingClientRect().top
const windowWidth = window.innerWidth + window.scrollX
const windowHeight = window.innerHeight + window.scrollY
// Get the width and height of the context menu
const cmWidth = contextMenu.offsetWidth
const cmHeight = contextMenu.offsetHeight
// Determine which side of the mouse the context menu should be on
const xQuadrant = windowWidth - posX - cmWidth < 5 ? 'right' : 'left'
const yQuadrant = windowHeight - posY - cmHeight < 5 ? 'bottom' : 'top'
// Position the context menu
if ([xQuadrant, yQuadrant].join() == 'left,top') {
contextMenu.style.left = posX + 'px'
contextMenu.style.top = posY + 'px'
}
if ([xQuadrant, yQuadrant].join() == 'right,top') {
contextMenu.style.left = posX - cmWidth - 25 + 'px'
contextMenu.style.top = posY + 'px'
}
if ([xQuadrant, yQuadrant].join() == 'left,bottom') {
contextMenu.style.left = posX + 'px'
contextMenu.style.top = posY - cmHeight + 'px'
}
if ([xQuadrant, yQuadrant].join() == 'right,bottom') {
contextMenu.style.left = posX - cmWidth - 25 + 'px'
contextMenu.style.top = posY - cmHeight + 'px'
}
}
return <Link to={`/project/${project.id}`} key={project.id}>
<div className="project-container">
<h2>{project.title || 'Untitled Schedule'}
<i className="fa-solid fa-ellipsis-vertical" onClick={(e) => {
e.stopPropagation();
e.preventDefault()
}}
onMouseEnter={(e) => {
positionContextMenu(e.target as HTMLElement)
if (!contextMenu) return
contextMenu.classList?.add("show")
contextMenu.setAttribute("data-isOwner", String(owner))
const leavePopupSpan = document.querySelector("#leavePopup > div > p > span");
const deletePopupSpan = document.querySelector("#deletePopup > div > p > span");
if (leavePopupSpan) leavePopupSpan.innerHTML = project.title || 'Untitled Schedule';
if (deletePopupSpan) deletePopupSpan.innerHTML = project.title || 'Untitled Schedule';
}}
onMouseLeave={() => contextMenu?.classList.remove("show")}
tabIndex={0}
role="button"
onKeyDown={() => { }}
>
</i>
</h2>
<p>{project.description || 'No Description'}</p>
</div>
</Link >
}