2022-03-22 21:41:56 +01:00
|
|
|
import { useNuiEvent } from "../hooks/useNuiEvent";
|
2022-03-24 20:00:09 +01:00
|
|
|
import {
|
|
|
|
|
Box,
|
|
|
|
|
Text,
|
2022-03-25 23:56:50 +01:00
|
|
|
Flex,
|
2022-03-24 20:00:09 +01:00
|
|
|
Popover,
|
|
|
|
|
PopoverTrigger,
|
|
|
|
|
Portal,
|
|
|
|
|
PopoverContent,
|
|
|
|
|
PopoverBody,
|
2022-03-26 09:55:05 +01:00
|
|
|
Spacer,
|
2022-03-26 09:59:26 +01:00
|
|
|
ScaleFade,
|
2022-03-24 20:00:09 +01:00
|
|
|
} from "@chakra-ui/react";
|
2022-03-26 09:55:05 +01:00
|
|
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
2022-03-22 21:41:56 +01:00
|
|
|
import { debugData } from "../utils/debugData";
|
|
|
|
|
import { useState } from "react";
|
|
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
|
title: string;
|
|
|
|
|
options: Options;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface Options {
|
|
|
|
|
[key: string]: {
|
2022-03-23 17:52:30 +01:00
|
|
|
description?: string;
|
|
|
|
|
metadata?: string[] | { [key: string]: any };
|
2022-03-26 09:55:05 +01:00
|
|
|
subMenu?: boolean;
|
2022-03-22 21:41:56 +01:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
debugData<Props>([
|
|
|
|
|
{
|
|
|
|
|
action: "showContext",
|
|
|
|
|
data: {
|
|
|
|
|
title: "Vehicle garage",
|
|
|
|
|
options: {
|
|
|
|
|
["Dinka Blista"]: {
|
2022-03-23 17:52:30 +01:00
|
|
|
description: "Super cool vehicle",
|
2022-03-26 09:55:05 +01:00
|
|
|
subMenu: true,
|
2022-03-23 17:52:30 +01:00
|
|
|
metadata: {
|
|
|
|
|
["Plate"]: "KLT 192",
|
|
|
|
|
["Status"]: "In garage",
|
|
|
|
|
["Health"]: "30%",
|
|
|
|
|
},
|
2022-03-22 21:41:56 +01:00
|
|
|
},
|
|
|
|
|
["Elegy Nitro"]: {
|
2022-03-23 17:52:30 +01:00
|
|
|
description: "Even cooler vehicle",
|
|
|
|
|
metadata: ["Plate: JGM 971", "Status: In garage"],
|
2022-03-22 21:41:56 +01:00
|
|
|
},
|
2022-03-25 23:56:50 +01:00
|
|
|
["Burger"]: {
|
|
|
|
|
description: "Make a delicious burger",
|
|
|
|
|
metadata: {
|
|
|
|
|
["Bun"]: 3,
|
|
|
|
|
["Lettuce"]: 2,
|
|
|
|
|
["Meat"]: 1,
|
|
|
|
|
["Tomato"]: 1,
|
|
|
|
|
["Cheese"]: 2,
|
|
|
|
|
},
|
|
|
|
|
},
|
2022-03-22 21:41:56 +01:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
const ContextMenu: React.FC = () => {
|
|
|
|
|
const [visible, setVisible] = useState(false);
|
|
|
|
|
const [contextMenu, setContextMenu] = useState<Props>({
|
|
|
|
|
title: "",
|
2022-03-23 17:52:30 +01:00
|
|
|
options: { [""]: { description: "", metadata: [""] } },
|
2022-03-22 21:41:56 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
useNuiEvent<Props>("showContext", (data) => {
|
|
|
|
|
setContextMenu(data);
|
|
|
|
|
setVisible(true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return (
|
2022-03-25 23:56:50 +01:00
|
|
|
<Flex
|
2022-03-24 20:00:09 +01:00
|
|
|
position="absolute"
|
2022-03-25 23:56:50 +01:00
|
|
|
w="75%"
|
|
|
|
|
h="80%"
|
|
|
|
|
justifyContent="flex-end"
|
|
|
|
|
alignItems="center"
|
2022-03-24 20:00:09 +01:00
|
|
|
>
|
2022-03-26 09:59:26 +01:00
|
|
|
<ScaleFade in={visible} unmountOnExit>
|
|
|
|
|
<Box w="xs" h={580}>
|
|
|
|
|
<Box borderRadius="md" bg="gray.800" mb={3}>
|
|
|
|
|
<Text
|
|
|
|
|
fontFamily="Poppins"
|
|
|
|
|
fontSize="md"
|
|
|
|
|
p={2}
|
|
|
|
|
textAlign="center"
|
|
|
|
|
fontWeight="light"
|
2022-03-25 23:56:50 +01:00
|
|
|
>
|
2022-03-26 09:59:26 +01:00
|
|
|
{contextMenu.title}
|
|
|
|
|
</Text>
|
|
|
|
|
</Box>
|
|
|
|
|
<Box maxH={560} overflowY="scroll">
|
|
|
|
|
{Object.entries(contextMenu.options).map((option, index) => (
|
|
|
|
|
<Popover
|
|
|
|
|
placement="right-start"
|
|
|
|
|
trigger="hover"
|
|
|
|
|
eventListeners={{ scroll: true }}
|
|
|
|
|
isLazy
|
|
|
|
|
>
|
|
|
|
|
<PopoverTrigger>
|
|
|
|
|
<Box
|
|
|
|
|
bg="gray.800"
|
|
|
|
|
borderRadius="md"
|
|
|
|
|
h="fit-content"
|
|
|
|
|
w="100%"
|
|
|
|
|
p={2}
|
|
|
|
|
mb={1}
|
|
|
|
|
fontFamily="Poppins"
|
|
|
|
|
fontSize="md"
|
|
|
|
|
transition="300ms"
|
|
|
|
|
_hover={{ bg: "gray.700" }}
|
|
|
|
|
key={`option-${index}`}
|
|
|
|
|
>
|
|
|
|
|
{/* TODO: react-markdown (?) */}
|
|
|
|
|
<Flex w="100%">
|
|
|
|
|
<Box>
|
2022-03-26 09:55:05 +01:00
|
|
|
<Box paddingBottom={1}>
|
2022-03-26 09:59:26 +01:00
|
|
|
<Text w="100%" fontWeight="medium">
|
|
|
|
|
{option[0]}
|
|
|
|
|
</Text>
|
2022-03-26 09:55:05 +01:00
|
|
|
</Box>
|
2022-03-26 09:59:26 +01:00
|
|
|
{option[1].description && (
|
|
|
|
|
<Box paddingBottom={1}>
|
|
|
|
|
<Text>{option[1].description}</Text>
|
|
|
|
|
</Box>
|
2022-03-25 23:56:50 +01:00
|
|
|
)}
|
2022-03-26 09:59:26 +01:00
|
|
|
</Box>
|
|
|
|
|
{option[1].subMenu && (
|
|
|
|
|
<>
|
|
|
|
|
<Spacer />
|
|
|
|
|
<Box
|
|
|
|
|
alignSelf="center"
|
|
|
|
|
justifySelf="center"
|
|
|
|
|
mr={4}
|
|
|
|
|
fontSize="xl"
|
|
|
|
|
>
|
|
|
|
|
<FontAwesomeIcon icon="chevron-right" />
|
|
|
|
|
</Box>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</Flex>
|
|
|
|
|
<Portal>
|
|
|
|
|
<PopoverContent
|
|
|
|
|
fontFamily="Poppins"
|
|
|
|
|
bg="gray.800"
|
|
|
|
|
outline="none"
|
|
|
|
|
border="none"
|
|
|
|
|
w="fit-content"
|
|
|
|
|
maxW="2xs"
|
|
|
|
|
>
|
|
|
|
|
<PopoverBody>
|
|
|
|
|
{option[1]?.metadata &&
|
|
|
|
|
Array.isArray(option[1].metadata) ? (
|
|
|
|
|
option[1].metadata.map(
|
|
|
|
|
(metadata: string, index) => (
|
|
|
|
|
<Text key={`context-metadata-${index}`}>
|
|
|
|
|
{metadata}
|
|
|
|
|
</Text>
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
|
|
|
|
{typeof option[1].metadata === "object" &&
|
|
|
|
|
Object.entries(option[1].metadata).map(
|
|
|
|
|
(metadata: { [key: string]: any }, index) => (
|
|
|
|
|
<Text key={`context-metadata-${index}`}>
|
|
|
|
|
{metadata[0]}: {metadata[1]}
|
|
|
|
|
</Text>
|
|
|
|
|
)
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</PopoverBody>
|
|
|
|
|
</PopoverContent>
|
|
|
|
|
</Portal>
|
|
|
|
|
</Box>
|
|
|
|
|
</PopoverTrigger>
|
|
|
|
|
</Popover>
|
|
|
|
|
))}
|
|
|
|
|
</Box>
|
2022-03-25 23:56:50 +01:00
|
|
|
</Box>
|
2022-03-26 09:59:26 +01:00
|
|
|
</ScaleFade>
|
2022-03-25 23:56:50 +01:00
|
|
|
</Flex>
|
2022-03-22 21:41:56 +01:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default ContextMenu;
|