From 33b70b6f1c06f8846b2d9a97335232f402fad1a6 Mon Sep 17 00:00:00 2001 From: Luke Date: Sat, 5 Nov 2022 11:20:59 +0100 Subject: [PATCH] refactor(web/context): cache context option into a variable --- web/src/features/menu/context/Item.tsx | 35 ++++++++++++++------------ 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/web/src/features/menu/context/Item.tsx b/web/src/features/menu/context/Item.tsx index ba16da0..dc4d0b4 100644 --- a/web/src/features/menu/context/Item.tsx +++ b/web/src/features/menu/context/Item.tsx @@ -16,7 +16,7 @@ import { Option, ContextMenuProps } from '../../../interfaces/context'; import { fetchNui } from '../../../utils/fetchNui'; const openMenu = (id: string | undefined) => { - fetchNui('openContext', {id: id, back: false}); + fetchNui('openContext', { id: id, back: false }); }; const clickContext = (id: string) => { @@ -26,6 +26,9 @@ const clickContext = (id: string) => { const Item: React.FC<{ option: [string, Option]; }> = ({ option }) => { + const button = option[1]; + const buttonKey = option[0]; + return ( <> @@ -45,33 +48,33 @@ const Item: React.FC<{ (option[1].menu ? openMenu(option[1].menu) : clickContext(option[0]))} + onClick={() => (button.menu ? openMenu(button.menu) : clickContext(buttonKey))} > - {option[1]?.icon && ( + {button?.icon && ( )} - + - {option[1].title ? option[1].title : option[0]} + {button.title ? button.title : buttonKey} - {option[1].description && ( + {button.description && ( - {option[1].description} + {button.description} )} - {(option[1].menu || option[1].arrow) && option[1].arrow !== false && ( + {(button.menu || button.arrow) && button.arrow !== false && ( <> @@ -81,7 +84,7 @@ const Item: React.FC<{ )} - {(option[1].metadata || option[1].image) && ( + {(button.metadata || button.image) && ( <> - {option[1].image && } - {Array.isArray(option[1].metadata) ? ( - option[1].metadata.map((metadata: string | { label: string; value: any }, index: number) => ( + {button.image && } + {Array.isArray(button.metadata) ? ( + button.metadata.map((metadata: string | { label: string; value: any }, index: number) => ( {typeof metadata === 'string' ? `${metadata}` : `${metadata.label}: ${metadata.value}`} )) ) : ( <> - {typeof option[1].metadata === 'object' && - Object.entries(option[1].metadata).map((metadata: { [key: string]: any }, index) => ( + {typeof button.metadata === 'object' && + Object.entries(button.metadata).map((metadata: { [key: string]: any }, index) => ( {metadata[0]}: {metadata[1]}