Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(context): Added onMenu field option #657

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion resource/interface/client/context.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ local openContextMenu = nil
---@field image? string
---@field progress? number
---@field onSelect? fun(args: any)
---@field onMenu? fun(args: any)
---@field arrow? boolean
---@field description? string
---@field metadata? string | { [string]: any } | string[]
Expand Down Expand Up @@ -83,7 +84,24 @@ function lib.getOpenContextMenu() return openContextMenu end
function lib.hideContext(onExit) closeContext(nil, nil, onExit) end

RegisterNUICallback('openContext', function(data, cb)
if data.back and contextMenus[openContextMenu].onBack then contextMenus[openContextMenu].onBack() end
if data.back then
if contextMenus[openContextMenu].onBack then
contextMenus[openContextMenu].onBack()
end
else
if not data.optionId then return end
local id = data.optionId
if math.type(tonumber(id)) == 'float' then
id = math.tointeger(id)
elseif tonumber(id) then
id += 1
end

if contextMenus[openContextMenu].options[id].onMenu then
contextMenus[openContextMenu].options[id].onMenu()
end
end

cb(1)
lib.showContext(data.id)
end)
Expand Down
6 changes: 3 additions & 3 deletions web/src/features/menu/context/components/ContextButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { IconProp } from '@fortawesome/fontawesome-svg-core';
import MarkdownComponents from '../../../../config/MarkdownComponents';
import LibIcon from '../../../../components/LibIcon';

const openMenu = (id: string | undefined) => {
fetchNui<ContextMenuProps>('openContext', { id: id, back: false });
const openMenu = (id: string | undefined, optionId: string | undefined) => {
fetchNui<ContextMenuProps>('openContext', { id: id, optionId: optionId, back: false });
};

const clickContext = (id: string) => {
Expand Down Expand Up @@ -96,7 +96,7 @@ const ContextButton: React.FC<{
onClick={() =>
!button.disabled && !button.readOnly
? button.menu
? openMenu(button.menu)
? openMenu(button.menu, buttonKey)
: clickContext(buttonKey)
: null
}
Expand Down