mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 15:36:02 +01:00
feat(client/interface): close functions for input and alert dialogs
This commit is contained in:
@@ -8,3 +8,5 @@ interface AlertDialogProps {
|
|||||||
type alertDialog = (data: AlertDialogProps) => Promise<'cancel' | 'confirm'>;
|
type alertDialog = (data: AlertDialogProps) => Promise<'cancel' | 'confirm'>;
|
||||||
|
|
||||||
export const alertDialog: alertDialog = async (data) => await exports.ox_lib.alertDialog(data);
|
export const alertDialog: alertDialog = async (data) => await exports.ox_lib.alertDialog(data);
|
||||||
|
|
||||||
|
export const closeAlertDialog = () => exports.ox_lib.closeAlertDialog();
|
||||||
|
|||||||
@@ -20,3 +20,5 @@ type inputDialog = (
|
|||||||
rows: string[] | InputDialogRowProps[]
|
rows: string[] | InputDialogRowProps[]
|
||||||
) => Promise<Array<string | number | boolean> | undefined>;
|
) => Promise<Array<string | number | boolean> | undefined>;
|
||||||
export const inputDialog: inputDialog = async (heading, rows) => await exports.ox_lib.inputDialog(heading, rows);
|
export const inputDialog: inputDialog = async (heading, rows) => await exports.ox_lib.inputDialog(heading, rows);
|
||||||
|
|
||||||
|
export const closeInputDialog = () => exports.ox_lib.inputDialog();
|
||||||
|
|||||||
@@ -21,6 +21,17 @@ function lib.alertDialog(data)
|
|||||||
return Citizen.Await(alert)
|
return Citizen.Await(alert)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function lib.closeAlertDialog()
|
||||||
|
if not alert then return end
|
||||||
|
alert:resolve(nil)
|
||||||
|
alert = nil
|
||||||
|
SetNuiFocus(false, false)
|
||||||
|
SendNUIMessage({
|
||||||
|
action = 'closeAlertDialog'
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
RegisterNUICallback('closeAlert', function(data, cb)
|
RegisterNUICallback('closeAlert', function(data, cb)
|
||||||
cb(1)
|
cb(1)
|
||||||
SetNuiFocus(false, false)
|
SetNuiFocus(false, false)
|
||||||
|
|||||||
@@ -40,6 +40,16 @@ function lib.inputDialog(heading, rows)
|
|||||||
return Citizen.Await(input)
|
return Citizen.Await(input)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function lib.closeInputDialog()
|
||||||
|
if not input then return end
|
||||||
|
input:resolve(nil)
|
||||||
|
input = nil
|
||||||
|
SetNuiFocus(false, false)
|
||||||
|
SendNUIMessage({
|
||||||
|
action = 'closeInputDialog'
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
RegisterNUICallback('inputData', function(data, cb)
|
RegisterNUICallback('inputData', function(data, cb)
|
||||||
cb(1)
|
cb(1)
|
||||||
SetNuiFocus(false, false)
|
SetNuiFocus(false, false)
|
||||||
|
|||||||
@@ -40,6 +40,10 @@ const AlertDialog: React.FC = () => {
|
|||||||
onOpen();
|
onOpen();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useNuiEvent('closeAlertDialog', () => {
|
||||||
|
onClose();
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Dialog
|
<Dialog
|
||||||
|
|||||||
@@ -39,6 +39,10 @@ const InputDialog: React.FC = () => {
|
|||||||
setVisible(true);
|
setVisible(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useNuiEvent('closeInputDialog', () => {
|
||||||
|
setVisible(false);
|
||||||
|
});
|
||||||
|
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
fetchNui('inputData');
|
fetchNui('inputData');
|
||||||
|
|||||||
Reference in New Issue
Block a user