Skip to content
This repository was archived by the owner on Apr 29, 2025. It is now read-only.

feat(alert): added lib.getOpenAlertDialog #739

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions resource/interface/client/alert.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
]]

---@type promise?
local alert = nil
local alert, alertData = nil, nil
local alertId = 0

---@class AlertDialogProps
Expand All @@ -28,11 +28,12 @@ function lib.alertDialog(data, timeout)
local id = alertId + 1
alertId = id
alert = promise.new()
alertData = data

lib.setNuiFocus(false)
SendNUIMessage({
action = 'sendAlert',
data = data
data = alertData
})

if timeout then
Expand All @@ -41,7 +42,11 @@ function lib.alertDialog(data, timeout)
end)
end

return Citizen.Await(alert)
return alert:await()
end

function lib.getOpenAlertDialog()
return alert ~= nil, alertData
end

---@param reason? string An optional reason for the window to be closed.
Expand All @@ -54,7 +59,7 @@ function lib.closeAlertDialog(reason)
})

local p = alert
alert = nil
alert, alertData = nil, nil

if reason then p:reject(reason) else p:resolve() end
end
Expand All @@ -64,7 +69,7 @@ RegisterNUICallback('closeAlert', function(data, cb)
lib.resetNuiFocus()

local promise = alert --[[@as promise]]
alert = nil
alert, alertData = nil, nil

promise:resolve(data)
end)
Expand Down