From 6e1a9780386d63b4d81bc66da2716d38a19111d9 Mon Sep 17 00:00:00 2001 From: Luke <39926192+LukeWasTakenn@users.noreply.github.com> Date: Sat, 25 Feb 2023 14:27:20 +0100 Subject: [PATCH] fix(web/radial): check whether radial menu was closed during transition Closing the radial menu during the transition from the more pages would cause the menu to be stuck open --- resource/interface/client/radial.lua | 14 +++++++++++++- web/src/features/menu/radial/index.tsx | 7 +++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/resource/interface/client/radial.lua b/resource/interface/client/radial.lua index 08e5237..d2bb7fd 100644 --- a/resource/interface/client/radial.lua +++ b/resource/interface/client/radial.lua @@ -207,6 +207,9 @@ RegisterNUICallback('radialBack', function(_, cb) Wait(100) + -- If menu was closed during transition, don't open the submenu + if not isOpen then return end + SendNUIMessage({ action = 'openRadialMenu', data = { @@ -226,6 +229,15 @@ RegisterNUICallback('radialClose', function(_, cb) currentRadial = nil end) +RegisterNUICallback('radialTransition', function(_, cb) + Wait(100) + + -- If menu was closed during transition, don't open the submenu + if not isOpen then return cb(false) end + + cb(true) +end) + lib.addKeybind({ name = 'ox_lib-radial', description = 'Open radial menu', @@ -235,7 +247,7 @@ lib.addKeybind({ menuPage = 1 return lib.hideRadial() end - + menuPage = nil if #menuItems == 0 or IsNuiFocused() or IsPauseMenuActive() then return end diff --git a/web/src/features/menu/radial/index.tsx b/web/src/features/menu/radial/index.tsx index 61490db..133c6a5 100644 --- a/web/src/features/menu/radial/index.tsx +++ b/web/src/features/menu/radial/index.tsx @@ -70,8 +70,11 @@ const RadialMenu: React.FC = () => { const changePage = async (increment?: boolean) => { setVisible(false); - // May cause issues if user toggles off the menu while in transition? - await new Promise((resolve) => setTimeout(resolve, 100)); + + const didTransition: boolean = await fetchNui('radialTransition'); + + if (!didTransition) return; + setVisible(true); setMenu({ ...menu, page: increment ? menu.page + 1 : menu.page - 1 }); };