import { useNuiEvent } from "../hooks/useNuiEvent"; import { Box, Text, Flex, Popover, PopoverTrigger, Portal, PopoverContent, PopoverBody, Spacer, ScaleFade, } from "@chakra-ui/react"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { debugData } from "../utils/debugData"; import { useState } from "react"; interface Props { title: string; options: Options; } interface Options { [key: string]: { description?: string; metadata?: string[] | { [key: string]: any }; subMenu?: boolean; }; } debugData([ { action: "showContext", data: { title: "Vehicle garage", options: { ["Dinka Blista"]: { description: "Super cool vehicle", subMenu: true, metadata: { ["Plate"]: "KLT 192", ["Status"]: "In garage", ["Health"]: "30%", }, }, ["Elegy Nitro"]: { description: "Even cooler vehicle", metadata: ["Plate: JGM 971", "Status: In garage"], }, ["Burger"]: { description: "Make a delicious burger", metadata: { ["Bun"]: 3, ["Lettuce"]: 2, ["Meat"]: 1, ["Tomato"]: 1, ["Cheese"]: 2, }, }, }, }, }, ]); const ContextMenu: React.FC = () => { const [visible, setVisible] = useState(false); const [contextMenu, setContextMenu] = useState({ title: "", options: { [""]: { description: "", metadata: [""] } }, }); useNuiEvent("showContext", (data) => { setContextMenu(data); setVisible(true); }); return ( {contextMenu.title} {Object.entries(contextMenu.options).map((option, index) => ( {/* TODO: react-markdown (?) */} {option[0]} {option[1].description && ( {option[1].description} )} {option[1].subMenu && ( <> )} {option[1]?.metadata && Array.isArray(option[1].metadata) ? ( option[1].metadata.map( (metadata: string, index) => ( {metadata} ) ) ) : ( <> {typeof option[1].metadata === "object" && Object.entries(option[1].metadata).map( (metadata: { [key: string]: any }, index) => ( {metadata[0]}: {metadata[1]} ) )} )} ))} ); }; export default ContextMenu;