Skip to content
This repository was archived by the owner on Apr 19, 2025. It is now read-only.

Commit 29a69fc

Browse files
committed
feat(client/nui): Ability to display custom metadata
1 parent 20f1c4e commit 29a69fc

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

modules/items/client.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
local Items = shared.items
22

3+
local function displayMetadata(metadata, value)
4+
local data = metadata
5+
if type(metadata) == 'string' and value then data = { [metadata] = value } end
6+
SendNUIMessage({
7+
action = 'displayMetadata',
8+
data = data
9+
})
10+
end
11+
exports('displayMetadata', displayMetadata)
12+
313
local function GetItem(item)
414
if item then
515
item = string.lower(item)

web/src/components/App.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ debugData([
3636
durability: 100,
3737
description: `# Testing something \n**Yes**`,
3838
serial: 'SUPERCOOLWATER9725',
39+
mustard: '60%',
40+
ketchup: '30%',
41+
mayo: '10%',
3942
},
4043
count: 5,
4144
},

web/src/components/inventory/InventoryGrid.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,19 @@ import { createPortal } from 'react-dom';
1212
import useNuiEvent from '../../hooks/useNuiEvent';
1313
import useKeyPress from '../../hooks/useKeyPress';
1414
import { setClipboard } from '../../utils/setClipboard';
15+
import { debugData } from '../../utils/debugData';
16+
17+
// debugData([
18+
// {
19+
// action: 'displayMetadata',
20+
// data: { ['mustard']: 'Mustard', ['ketchup']: 'Ketchup' },
21+
// },
22+
// ]);
1523

1624
const InventoryGrid: React.FC<{ inventory: Inventory }> = ({ inventory }) => {
1725
const [currentItem, setCurrentItem] = React.useState<SlotWithItem>();
1826
const [contextVisible, setContextVisible] = React.useState<boolean>(false);
27+
const [additionalMetadata, setAdditionalMetadata] = React.useState<{ [key: string]: any }>({});
1928

2029
const isControlPressed = useKeyPress('Control');
2130
const isCopyPressed = useKeyPress('c');
@@ -46,6 +55,10 @@ const InventoryGrid: React.FC<{ inventory: Inventory }> = ({ inventory }) => {
4655
ReactTooltip.rebuild();
4756
});
4857

58+
useNuiEvent<{ [key: string]: any }>('displayMetadata', (data) =>
59+
setAdditionalMetadata((oldMetadata) => ({ ...oldMetadata, ...data }))
60+
);
61+
4962
return (
5063
<>
5164
<div className="column-wrapper">
@@ -131,6 +144,15 @@ const InventoryGrid: React.FC<{ inventory: Inventory }> = ({ inventory }) => {
131144
{Locale.ui_tint}: {currentItem.metadata.weapontint}
132145
</p>
133146
)}
147+
{Object.keys(additionalMetadata).map((data: string, index: number) => (
148+
<React.Fragment key={`metadata-${index}`}>
149+
{currentItem.metadata && currentItem.metadata[data] && (
150+
<p>
151+
{additionalMetadata[data]}: {currentItem.metadata[data]}
152+
</p>
153+
)}
154+
</React.Fragment>
155+
))}
134156
</>
135157
</ReactTooltip>
136158
)}

0 commit comments

Comments
 (0)