From 13d849673bfee0afbddf8dcbbb9d52563c6bf8da Mon Sep 17 00:00:00 2001 From: Ruben Vandamme Date: Mon, 1 Apr 2024 21:26:59 +0200 Subject: [PATCH] warning proceed not firing at some locations --- frontend/src/assets/styles/warneable.css | 50 +++++++++++++++++++ frontend/src/pages/admin/HomeAdmin.tsx | 61 ++++++++++++++++++++---- frontend/src/pages/admin/Warneable.tsx | 44 +++++++++++++++++ 3 files changed, 146 insertions(+), 9 deletions(-) create mode 100644 frontend/src/assets/styles/warneable.css create mode 100644 frontend/src/pages/admin/Warneable.tsx diff --git a/frontend/src/assets/styles/warneable.css b/frontend/src/assets/styles/warneable.css new file mode 100644 index 00000000..cf5213c4 --- /dev/null +++ b/frontend/src/assets/styles/warneable.css @@ -0,0 +1,50 @@ +.warning-header { + font-size: large; + font-weight: bold; + + display: flex; + flex-direction: column; + align-items: center; + + border-bottom: 1px solid rgb(187, 187, 187); +} + +.warning-content { + display: flex; + flex-direction: column; + align-items: center; + + padding: 10px; + padding-top: 12px; + + word-wrap: break-word; + white-space: pre-wrap; + word-break: break-word; + + max-height: 250px; + overflow-y: auto; +} + +.warning-actions { + display: flex; + flex-direction: row; + justify-content: center; +} + +.warning-button { + border-radius: 5px; + border-width: 1px; + + padding: 5px 10px; + margin: 5px 10px; +} +.warning-button:hover { + padding: 4px 9px; + border-width: 2px; +} + +.warning-proceed { + color: white; + background-color: rgb(255, 94, 94); + border-color: red; +} \ No newline at end of file diff --git a/frontend/src/pages/admin/HomeAdmin.tsx b/frontend/src/pages/admin/HomeAdmin.tsx index a5e556aa..125e02c1 100644 --- a/frontend/src/pages/admin/HomeAdmin.tsx +++ b/frontend/src/pages/admin/HomeAdmin.tsx @@ -9,15 +9,17 @@ import { VscNewFile } from "react-icons/vsc"; import { VscNewFolder } from "react-icons/vsc"; import Popup from 'reactjs-popup'; import 'reactjs-popup/dist/index.css'; +import Warneable from "./Warneable"; /* TODO: - - warning with proceed and cancel + x warning with proceed and cancel - remove - andere toestaan checkbox - enkele file/zip-bestand - kleurencodes uitleggen - algemene layout beter maken + - mergen & implementeren in projectview van teacher */ @@ -274,6 +276,7 @@ export default function HomeAdmin(): JSX.Element { } + /* add a new constraint */ function handleAdd(folder_id: number, type: string) { function add(constraint: FEConstraint) { if (constraint.id === folder_id) { @@ -302,6 +305,31 @@ export default function HomeAdmin(): JSX.Element { setData(structuredClone(data)) } + + /* remove a constraint and all its subconstraints recursively */ + function handleRemove(parent_id: number | undefined, id: number) { + + function remove(constraint: FEConstraint) { + if (constraint.id === parent_id) { + if (constraint.sub_constraints !== undefined) { + constraint.sub_constraints = constraint.sub_constraints.filter( + sub => sub.id !== id + ) + } + } + } + + remove(data) + + // update display + setData(structuredClone(data)) + + } + + function log() { + console.log("log") + } + return (
@@ -334,11 +362,11 @@ export default function HomeAdmin(): JSX.Element { {/* ...constraints... */} {flatten(data).map((v) => - <> +
{v.show &&
setIsHoveringMore(structuredClone(isHoveringMore.set(v.item.id, true)))} - onMouseOut={() => setIsHoveringMore(structuredClone(isHoveringMore.set(v.item.id, false)))} + onMouseOut={() => setIsHoveringMore(structuredClone(isHoveringMore.set(v.item.id, true)))} > {/* ... spacing ... */} @@ -348,19 +376,33 @@ export default function HomeAdmin(): JSX.Element { { (!isZip(v.item.type) && isHoveringMore.get(v.item.id) ) ?
+
+ {/* FIXME: warneable.proceed works */} + +
+ + } position="left center" arrow={true} on="click"> - } position="left center" arrow={true} on="hover"> + {/* FIXME: warneable.proceed doesn't work */}
-
-
remove
+ {/* ... menu-remove ... */} +
+ + + + } + proceed={() => handleRemove(v.item.parent_id, v.item.id)} /* FIXME: proceed doesn't fire here for some reason */ + />
+ {/* ... menu-allow-others ... */}
@@ -382,6 +424,7 @@ export default function HomeAdmin(): JSX.Element { : "dir-color" : "" )} + id={"name"+v.item.id} type="text" value={v.item.name} onChange={e => modifyName(v.item.id, e.target.value)} @@ -406,7 +449,7 @@ export default function HomeAdmin(): JSX.Element {
} - +
)}
diff --git a/frontend/src/pages/admin/Warneable.tsx b/frontend/src/pages/admin/Warneable.tsx new file mode 100644 index 00000000..9f22d72f --- /dev/null +++ b/frontend/src/pages/admin/Warneable.tsx @@ -0,0 +1,44 @@ +import Popup from 'reactjs-popup'; +import '../../assets/styles/warneable.css' +import { useState } from 'react'; + +export default function(props: { + text: string, + trigger: (onClick: () => void) => JSX.Element, + proceed: () => void, +}) { + + const [open, setOpen] = useState(false); + const closeModal = () => setOpen(false); + const onProceed = () => { + console.log("hallo2") + props.proceed() + }; + + return ( + <> + {props.trigger(() => {setOpen(o => !o)})} + + +
Warning!
+ +
+ {props.text} +
+ +
+ + + + + +
+
+ + + ) +}