Revert "refactor(client/context): rename lastHoveredContextItem variable"

This reverts commit 61db40c07d.
This commit is contained in:
Luke
2023-02-08 10:04:53 +01:00
parent 407cfd8eb2
commit c9c90efaf8
2 changed files with 21 additions and 14 deletions

View File

@@ -1,5 +1,5 @@
local contextMenus = {} local contextMenus = {}
local currentHover = nil local lastHoveredContextItem = nil
local openContextMenu = nil local openContextMenu = nil
local keepInput = IsNuiFocusKeepingInput() local keepInput = IsNuiFocusKeepingInput()
@@ -43,10 +43,10 @@ local function closeContext(_, cb, onExit)
if not cb then SendNUIMessage({ action = 'hideContext' }) end if not cb then SendNUIMessage({ action = 'hideContext' }) end
if currentHover then if lastHoveredContextItem then
local data = contextMenus[openContextMenu].options[currentHover] local data = contextMenus[openContextMenu].options[lastHoveredContextItem]
if data.onHover then data.onHover(false, data.args) end if data.onHover then data.onHover(false, data.args) end
currentHover = nil lastHoveredContextItem = nil
end end
openContextMenu = nil openContextMenu = nil
@@ -125,10 +125,10 @@ RegisterNUICallback('clickContext', function(id, cb)
if data.event then TriggerEvent(data.event, data.args) end if data.event then TriggerEvent(data.event, data.args) end
if data.serverEvent then TriggerServerEvent(data.serverEvent, data.args) end if data.serverEvent then TriggerServerEvent(data.serverEvent, data.args) end
if currentHover then if lastHoveredContextItem then
local data = contextMenus[openContextMenu].options[currentHover] local data = contextMenus[openContextMenu].options[lastHoveredContextItem]
if data.onHover then data.onHover(false) end if data.onHover then data.onHover(false, data.args) end
currentHover = nil lastHoveredContextItem = nil
end end
SendNUIMessage({ SendNUIMessage({
@@ -140,13 +140,20 @@ RegisterNUICallback('onHover', function(data, cb)
cb(1) cb(1)
local id = checkID(data.id) local id = checkID(data.id)
local entered = data.entered local hoverState = data.hoverState
local data = contextMenus[openContextMenu].options[id] local data = contextMenus[openContextMenu].options[id]
if not data.onHover then return end if not data.onHover then return end
currentHover = entered and id if data.onHover and hoverState == true then
data.onHover(entered) lastHoveredContextItem = id
data.onHover(true, data.args)
end
if data.onHover and hoverState == false then
lastHoveredContextItem = nil
data.onHover(false, data.args)
end
end) end)
RegisterNUICallback('closeContext', closeContext) RegisterNUICallback('closeContext', closeContext)

View File

@@ -50,8 +50,8 @@ const ContextButton: React.FC<{
onClick={() => onClick={() =>
!button.disabled ? (button.menu ? openMenu(button.menu) : fetchNui('clickContext', buttonKey)) : null !button.disabled ? (button.menu ? openMenu(button.menu) : fetchNui('clickContext', buttonKey)) : null
} }
onMouseEnter={() => (!button.disabled ? fetchNui('onHover', { entered: true, id: buttonKey }) : null)} onMouseEnter={() => (!button.disabled ? fetchNui('onHover', { hoverState: true, id: buttonKey }) : null)}
onMouseLeave={() => (!button.disabled ? fetchNui('onHover', { entered: false, id: buttonKey }) : null)} onMouseLeave={() => (!button.disabled ? fetchNui('onHover', { hoverState: false, id: buttonKey }) : null)}
variant="default" variant="default"
h="fit-content" h="fit-content"
p={10} p={10}