mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-19 16:06:02 +01:00
feat(context): prevent event triggering (#34)
This commit is contained in:
@@ -34,11 +34,13 @@ RegisterNUICallback('openContext', function(id, cb)
|
|||||||
lib.showContext(id)
|
lib.showContext(id)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
RegisterNUICallback('clickContext', function(data, cb)
|
RegisterNUICallback('clickContext', function(id, cb)
|
||||||
cb(1)
|
cb(1)
|
||||||
SetNuiFocus(false, false)
|
SetNuiFocus(false, false)
|
||||||
|
local data = contextMenus[openContextMenu].options[id]
|
||||||
if data.event then TriggerEvent(data.event, data.args) end
|
if data.event then TriggerEvent(data.event, data.args) end
|
||||||
if data.serverEvent then TriggerServerEvent(data.serverEvent, data.args) end
|
if data.serverEvent then TriggerServerEvent(data.serverEvent, data.args) end
|
||||||
|
|
||||||
openContextMenu = nil
|
openContextMenu = nil
|
||||||
SendNUIMessage({
|
SendNUIMessage({
|
||||||
action = 'hideContext'
|
action = 'hideContext'
|
||||||
|
|||||||
@@ -13,19 +13,12 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|||||||
import { Option, ContextMenuProps } from "../../interfaces/context";
|
import { Option, ContextMenuProps } from "../../interfaces/context";
|
||||||
import { fetchNui } from "../../utils/fetchNui";
|
import { fetchNui } from "../../utils/fetchNui";
|
||||||
|
|
||||||
interface DataProps {
|
|
||||||
event?: string;
|
|
||||||
serverEvent?: string;
|
|
||||||
args?: any;
|
|
||||||
}
|
|
||||||
|
|
||||||
const openMenu = (id: string | undefined) => {
|
const openMenu = (id: string | undefined) => {
|
||||||
fetchNui<ContextMenuProps>("openContext", id);
|
fetchNui<ContextMenuProps>("openContext", id);
|
||||||
};
|
};
|
||||||
|
|
||||||
const clickContext = (data: DataProps) => {
|
const clickContext = (id: string) => {
|
||||||
if (!data.event && !data.serverEvent) return;
|
fetchNui("clickContext", id);
|
||||||
fetchNui("clickContext", data);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const Item: React.FC<{
|
const Item: React.FC<{
|
||||||
@@ -58,11 +51,7 @@ const Item: React.FC<{
|
|||||||
onClick={() =>
|
onClick={() =>
|
||||||
option[1].menu
|
option[1].menu
|
||||||
? openMenu(option[1].menu)
|
? openMenu(option[1].menu)
|
||||||
: clickContext({
|
: clickContext(option[0])
|
||||||
event: option[1].event,
|
|
||||||
serverEvent: option[1].serverEvent,
|
|
||||||
args: option[1].args,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<Box>
|
<Box>
|
||||||
|
|||||||
Reference in New Issue
Block a user