-
-
Notifications
You must be signed in to change notification settings - Fork 432
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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`
- Loading branch information
1 parent
4a20a0c
commit 3034a32
Showing
3 changed files
with
28 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters