feat(context): prevent event triggering (#34)

This commit is contained in:
JsSusenka
2022-05-28 19:15:35 +02:00
committed by GitHub
parent 8aa9ebf41d
commit a5026ed8e9
2 changed files with 7 additions and 16 deletions

View File

@@ -13,7 +13,7 @@ function lib.showContext(id)
menu = data.menu,
options = data.options
}
}, {sort_keys=true}))
}, { sort_keys = true }))
end
function lib.registerContext(context)
@@ -34,11 +34,13 @@ RegisterNUICallback('openContext', function(id, cb)
lib.showContext(id)
end)
RegisterNUICallback('clickContext', function(data, cb)
RegisterNUICallback('clickContext', function(id, cb)
cb(1)
SetNuiFocus(false, false)
local data = contextMenus[openContextMenu].options[id]
if data.event then TriggerEvent(data.event, data.args) end
if data.serverEvent then TriggerServerEvent(data.serverEvent, data.args) end
openContextMenu = nil
SendNUIMessage({
action = 'hideContext'

View File

@@ -13,19 +13,12 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { Option, ContextMenuProps } from "../../interfaces/context";
import { fetchNui } from "../../utils/fetchNui";
interface DataProps {
event?: string;
serverEvent?: string;
args?: any;
}
const openMenu = (id: string | undefined) => {
fetchNui<ContextMenuProps>("openContext", id);
};
const clickContext = (data: DataProps) => {
if (!data.event && !data.serverEvent) return;
fetchNui("clickContext", data);
const clickContext = (id: string) => {
fetchNui("clickContext", id);
};
const Item: React.FC<{
@@ -58,11 +51,7 @@ const Item: React.FC<{
onClick={() =>
option[1].menu
? openMenu(option[1].menu)
: clickContext({
event: option[1].event,
serverEvent: option[1].serverEvent,
args: option[1].args,
})
: clickContext(option[0])
}
>
<Box>