diff --git a/web/src/components/features/menu/ContextMenu.tsx b/web/src/components/features/menu/ContextMenu.tsx index 47980fe..d81f18d 100644 --- a/web/src/components/features/menu/ContextMenu.tsx +++ b/web/src/components/features/menu/ContextMenu.tsx @@ -2,41 +2,38 @@ import { useNuiEvent } from "../../../hooks/useNuiEvent"; import { Box, Text, Flex, ScaleFade } from "@chakra-ui/react"; import { debugData } from "../../../utils/debugData"; import { useState } from "react"; -import { Options } from "../../../interfaces"; +import { ContextMenuProps } from "../../../interfaces"; import Item from "./Item"; +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; +import { fetchNui } from "../../../utils/fetchNui"; -interface Props { - title: string; - options: Options; -} - -debugData([ +debugData([ { action: "showContext", data: { title: "Vehicle garage", options: { - ["Dinka Blista"]: { + "Dinka Blista": { description: "Super cool vehicle", - subMenu: true, + menu: "some_other_identifier", metadata: { - ["Plate"]: "KLT 192", - ["Status"]: "In garage", - ["Health"]: "30%", + Plate: "KLT 192", + Status: "In garage", + Health: "30%", }, }, - ["Elegy Nitro"]: { + "Elegy Nitro": { description: "Even cooler vehicle", metadata: ["Plate: JGM 971", "Status: In garage"], }, - ["Burger"]: { + Burger: { description: "Make a delicious burger", metadata: { - ["Bun"]: 3, - ["Lettuce"]: 2, - ["Meat"]: 1, - ["Tomato"]: 1, - ["Cheese"]: 2, + Bun: 3, + Lettuce: 2, + Meat: 1, + Tomato: 1, + Cheese: 2, }, }, }, @@ -44,14 +41,22 @@ debugData([ }, ]); +const openMenu = (id: string | undefined) => { + fetchNui("openContext", id); +}; + const ContextMenu: React.FC = () => { const [visible, setVisible] = useState(false); - const [contextMenu, setContextMenu] = useState({ + const [contextMenu, setContextMenu] = useState({ title: "", - options: { [""]: { description: "", metadata: [""] } }, + options: { "": { description: "", metadata: [] } }, }); - useNuiEvent("showContext", (data) => { + useNuiEvent("showContext", async (data) => { + if (visible) { + setVisible(false); + await new Promise((resolve) => setTimeout(resolve, 100)); + } setContextMenu(data); setVisible(true); }); @@ -63,20 +68,39 @@ const ContextMenu: React.FC = () => { h="80%" justifyContent="flex-end" alignItems="center" + bg="red" > - - - {contextMenu.title} - - + + {contextMenu.menu && ( + openMenu(contextMenu.menu)} + > + + + )} + + + {contextMenu.title} + + + {Object.entries(contextMenu.options).map((option, index) => ( diff --git a/web/src/components/features/menu/Item.tsx b/web/src/components/features/menu/Item.tsx index 10e9369..f25d71d 100644 --- a/web/src/components/features/menu/Item.tsx +++ b/web/src/components/features/menu/Item.tsx @@ -10,7 +10,17 @@ import { Spacer, } from "@chakra-ui/react"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; -import { Option } from "../../../interfaces"; +import { Option, ContextMenuProps } from "../../../interfaces"; +import { fetchNui } from "../../../utils/fetchNui"; + +const openMenu = (id: string | undefined) => { + fetchNui("openContext", id); +}; + +const clickContext = () => { + // todo + fetchNui("clickContext"); +}; const Item: React.FC<{ option: [string, Option]; @@ -36,7 +46,12 @@ const Item: React.FC<{ transition="300ms" _hover={{ bg: "gray.700" }} > - + + option[1].menu ? openMenu(option[1].menu) : clickContext() + } + > @@ -49,7 +64,7 @@ const Item: React.FC<{ )} - {option[1].subMenu && ( + {option[1].menu && ( <>