refactor(client/interface): nui focus tweaks

Add helper functions to set nui focus and restore previous input state.
Ensure focus is reset before triggering responses (promises/callbacks).
This commit is contained in:
Linden
2023-03-01 07:25:28 +11:00
parent 284b563483
commit 3dd996c38b
4 changed files with 33 additions and 40 deletions

View File

@@ -1,10 +1,4 @@
local alert = nil
local keepInput = IsNuiFocusKeepingInput()
local function resetFocus()
SetNuiFocus(false, false)
SetNuiFocusKeepInput(keepInput)
end
---@class AlertDialogProps
---@field header string;
@@ -19,10 +13,9 @@ end
---@return 'cancel' | 'confirm' | nil
function lib.alertDialog(data)
if alert then return end
alert = promise.new()
keepInput = IsNuiFocusKeepingInput()
lib.setNuiFocus(false)
SetNuiFocus(true, true)
SetNuiFocusKeepInput(false)
SendNUIMessage({
@@ -35,20 +28,24 @@ end
function lib.closeAlertDialog()
if not alert then return end
alert:resolve(nil)
alert = nil
resetFocus()
lib.resetNuiFocus()
SendNUIMessage({
action = 'closeAlertDialog'
})
alert:resolve(nil)
alert = nil
end
RegisterNUICallback('closeAlert', function(data, cb)
cb(1)
resetFocus()
lib.resetNuiFocus()
local promise = alert
alert = nil
promise:resolve(data)
end)