2022-06-17 20:29:40 +02:00
|
|
|
local alert = nil
|
|
|
|
|
|
2022-09-18 09:06:32 +10:00
|
|
|
---@class AlertDialogProps
|
|
|
|
|
---@field header string;
|
|
|
|
|
---@field content string;
|
|
|
|
|
---@field centered? boolean?;
|
2023-02-01 10:19:08 -05:00
|
|
|
---@field size? 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
|
|
|
---@field overflow? boolean?;
|
2022-09-18 09:06:32 +10:00
|
|
|
---@field cancel? boolean?;
|
2022-12-08 11:46:21 +01:00
|
|
|
---@field labels? {cancel?: string, confirm?: string}
|
2022-09-18 09:06:32 +10:00
|
|
|
|
|
|
|
|
---@param data AlertDialogProps
|
|
|
|
|
---@return 'cancel' | 'confirm' | nil
|
2022-06-11 11:33:15 +02:00
|
|
|
function lib.alertDialog(data)
|
2022-06-17 20:29:40 +02:00
|
|
|
if alert then return end
|
2022-12-30 11:16:33 +01:00
|
|
|
|
2023-03-01 07:25:28 +11:00
|
|
|
alert = promise.new()
|
2023-03-23 05:55:16 +11:00
|
|
|
|
2023-03-01 07:25:28 +11:00
|
|
|
lib.setNuiFocus(false)
|
2022-06-11 11:33:15 +02:00
|
|
|
SendNUIMessage({
|
|
|
|
|
action = 'sendAlert',
|
|
|
|
|
data = data
|
|
|
|
|
})
|
2022-06-17 20:29:40 +02:00
|
|
|
|
|
|
|
|
return Citizen.Await(alert)
|
2022-06-11 11:33:15 +02:00
|
|
|
end
|
|
|
|
|
|
2022-09-29 11:39:30 +02:00
|
|
|
function lib.closeAlertDialog()
|
|
|
|
|
if not alert then return end
|
2023-03-01 07:25:28 +11:00
|
|
|
|
|
|
|
|
lib.resetNuiFocus()
|
2022-09-29 11:39:30 +02:00
|
|
|
SendNUIMessage({
|
|
|
|
|
action = 'closeAlertDialog'
|
|
|
|
|
})
|
2023-03-01 07:25:28 +11:00
|
|
|
|
2023-03-23 05:55:16 +11:00
|
|
|
alert:resolve(nil)
|
2023-03-01 07:25:28 +11:00
|
|
|
alert = nil
|
2022-09-29 11:39:30 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
2022-06-17 20:29:40 +02:00
|
|
|
RegisterNUICallback('closeAlert', function(data, cb)
|
2022-06-11 11:33:15 +02:00
|
|
|
cb(1)
|
2023-03-01 07:25:28 +11:00
|
|
|
lib.resetNuiFocus()
|
|
|
|
|
|
2022-08-17 23:47:31 +02:00
|
|
|
local promise = alert
|
2022-06-17 20:29:40 +02:00
|
|
|
alert = nil
|
2023-03-01 07:25:28 +11:00
|
|
|
|
2022-08-17 23:47:31 +02:00
|
|
|
promise:resolve(data)
|
2022-06-17 01:23:56 -07:00
|
|
|
end)
|
|
|
|
|
|
2022-12-30 11:16:33 +01:00
|
|
|
RegisterNetEvent('ox_lib:alertDialog', lib.alertDialog)
|