From fc27f027a96ddeb41d7ad8aef802757e5994a7a9 Mon Sep 17 00:00:00 2001 From: tabarra Date: Tue, 25 Apr 2023 10:24:08 -0300 Subject: [PATCH] feat(menu/vehicle): added shortcut buttons to spawn dialog --- nui/src/components/MainPage/MainPageList.tsx | 3 +- nui/src/provider/DialogProvider.tsx | 55 ++++++++++++++------ 2 files changed, 40 insertions(+), 18 deletions(-) diff --git a/nui/src/components/MainPage/MainPageList.tsx b/nui/src/components/MainPage/MainPageList.tsx index 4e3afedd0..2aa52ddc5 100644 --- a/nui/src/components/MainPage/MainPageList.tsx +++ b/nui/src/components/MainPage/MainPageList.tsx @@ -198,7 +198,8 @@ export const MainPageList: React.FC = () => { openDialog({ title: t("nui_menu.page_main.vehicle.spawn.dialog_title"), description: t("nui_menu.page_main.vehicle.spawn.dialog_desc"), - placeholder: dialogData.shortcuts.join(', ') + ', etc.', + placeholder: 'any vehicle model or ' + dialogData.shortcuts.join(', '), + suggestions: dialogData.shortcuts, onSubmit: (modelName: string) => { modelName = vehiclePlaceholderReplacer(modelName, dialogData.shortcutsData); fetchNui("spawnVehicle", { model: modelName }).then(({ e }) => { diff --git a/nui/src/provider/DialogProvider.tsx b/nui/src/provider/DialogProvider.tsx index d8d66cc1d..e3283e304 100644 --- a/nui/src/provider/DialogProvider.tsx +++ b/nui/src/provider/DialogProvider.tsx @@ -29,6 +29,7 @@ import { useSnackbar } from "notistack"; import { useTranslate } from "react-polyglot"; import { useSetDisableTab, useSetListenForExit } from "../state/keys.state"; import { txAdminMenuPage, usePageValue } from "../state/page.state"; +import { Box } from "@mui/system"; const StyledDialogTitle = styled(DialogTitle)(({theme}) => ({ color: theme.palette.primary.main, @@ -43,6 +44,7 @@ interface InputDialogProps { placeholder: string; onSubmit: (inputValue: string) => void; isMultiline?: boolean; + suggestions?: string[] } interface DialogProviderContext { @@ -87,17 +89,17 @@ export const DialogProvider: React.FC = ({ children }) => { } }, [dialogOpen, setDisabledKeyNav, setDisableTabs]); - const handleDialogSubmit = () => { - if (!dialogInputVal.trim()) { + const handleDialogSubmit = (suggested?: string) => { + if (!canSubmit) return; + + const input = suggested ?? dialogInputVal; + if (!input.trim()) { return enqueueSnackbar(t("nui_menu.misc.dialog_empty_input"), { variant: "error", }); } - if (!canSubmit) return; - - dialogProps.onSubmit(dialogInputVal); - + dialogProps.onSubmit(input); setCanSubmit(false); setListenForExit(true); @@ -178,17 +180,36 @@ export const DialogProvider: React.FC = ({ children }) => { /> - - + + + {Array.isArray(dialogProps.suggestions) && dialogProps.suggestions.map(suggestion => ( + + ))} + + + + + + +