refactor(dialog/alert): allow defining cancel button

Using the same promise type of API that the input dialog is using, if the user closes the dialog via esc or the cancel button the promise will resolve `cancel` otherwise the promise will resolve `confirm`
This commit is contained in:
Luke
2022-06-17 20:29:40 +02:00
parent 4a20a0c3ff
commit 3034a32955
3 changed files with 28 additions and 5 deletions

View File

@@ -1,14 +1,23 @@
local alert = nil
function lib.alertDialog(data)
if alert then return end
alert = promise.new()
SetNuiFocus(true, true)
SendNUIMessage({
action = 'sendAlert',
data = data
})
return Citizen.Await(alert)
end
RegisterNUICallback('closeAlert', function(_, cb)
RegisterNUICallback('closeAlert', function(data, cb)
cb(1)
SetNuiFocus(false, false)
alert:resolve(data)
alert = nil
end)
RegisterNetEvent('ox_lib:alertDialog', lib.alertDialog)