mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 23:46:03 +01:00
feat(interface/context): context menu onBack function (#122)
* feat(interface/context): back button pressed * fix(context): types
This commit is contained in:
@@ -23,6 +23,7 @@ interface ContextMenuProps {
|
|||||||
title: string;
|
title: string;
|
||||||
menu?: string;
|
menu?: string;
|
||||||
onExit?: () => void;
|
onExit?: () => void;
|
||||||
|
onBack?: () => void;
|
||||||
canClose?: boolean;
|
canClose?: boolean;
|
||||||
options: { [key: string]: ContextMenuItem } | ContextMenuArrayItem[];
|
options: { [key: string]: ContextMenuItem } | ContextMenuArrayItem[];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ local openContextMenu = nil
|
|||||||
---@field title string
|
---@field title string
|
||||||
---@field menu? string
|
---@field menu? string
|
||||||
---@field onExit? fun()
|
---@field onExit? fun()
|
||||||
|
---@field onBack? fun()
|
||||||
---@field canClose? boolean
|
---@field canClose? boolean
|
||||||
---@field options { [string]: ContextMenuItem } | ContextMenuArrayItem[]
|
---@field options { [string]: ContextMenuItem } | ContextMenuArrayItem[]
|
||||||
|
|
||||||
@@ -68,9 +69,10 @@ function lib.getOpenContextMenu() return openContextMenu end
|
|||||||
---@param onExit boolean?
|
---@param onExit boolean?
|
||||||
function lib.hideContext(onExit) closeContext(nil, nil, onExit) end
|
function lib.hideContext(onExit) closeContext(nil, nil, onExit) end
|
||||||
|
|
||||||
RegisterNUICallback('openContext', function(id, cb)
|
RegisterNUICallback('openContext', function(data, cb)
|
||||||
|
if data.back and contextMenus[openContextMenu].onBack then contextMenus[openContextMenu].onBack() end
|
||||||
cb(1)
|
cb(1)
|
||||||
lib.showContext(id)
|
lib.showContext(data.id)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
RegisterNUICallback('clickContext', function(id, cb)
|
RegisterNUICallback('clickContext', function(id, cb)
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|||||||
import { fetchNui } from '../../../utils/fetchNui';
|
import { fetchNui } from '../../../utils/fetchNui';
|
||||||
|
|
||||||
const openMenu = (id: string | undefined) => {
|
const openMenu = (id: string | undefined) => {
|
||||||
fetchNui<ContextMenuProps>('openContext', id);
|
fetchNui<ContextMenuProps>('openContext', {id: id, back: true});
|
||||||
};
|
};
|
||||||
|
|
||||||
const ContextMenu: React.FC = () => {
|
const ContextMenu: React.FC = () => {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import { Option, ContextMenuProps } from '../../../interfaces/context';
|
|||||||
import { fetchNui } from '../../../utils/fetchNui';
|
import { fetchNui } from '../../../utils/fetchNui';
|
||||||
|
|
||||||
const openMenu = (id: string | undefined) => {
|
const openMenu = (id: string | undefined) => {
|
||||||
fetchNui<ContextMenuProps>('openContext', id);
|
fetchNui<ContextMenuProps>('openContext', {id: id, back: false});
|
||||||
};
|
};
|
||||||
|
|
||||||
const clickContext = (id: string) => {
|
const clickContext = (id: string) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user