Skip to content

Commit c6bf362

Browse files
committed
fix(wrapper): filter children items via shouldAdd
1 parent 41ed718 commit c6bf362

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

jsHelper/spicetifyWrapper.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,14 +1745,19 @@ Spicetify.ContextMenuV2 = (() => {
17451745
}
17461746

17471747
class ItemSubMenu {
1748-
static itemsToComponents = (items) => items.map((item) => item._element);
1748+
static itemsToComponents = (items, props, trigger, target) => {
1749+
return items
1750+
.filter((item) => (item.shouldAdd || (() => true))?.(props, trigger, target))
1751+
.map((item) => item._element);
1752+
};
17491753

17501754
constructor({ text, disabled = false, leadingIcon, divider, items, shouldAdd = () => true }) {
17511755
this.shouldAdd = shouldAdd;
17521756

17531757
this._text = text;
17541758
this._disabled = disabled;
17551759
this._leadingIcon = leadingIcon;
1760+
this._divider = divider;
17561761
this._items = items;
17571762
this._element = Spicetify.ReactJSX.jsx(() => {
17581763
const [_text, setText] = Spicetify.React.useState(this._text);
@@ -1776,6 +1781,9 @@ Spicetify.ContextMenuV2 = (() => {
17761781
};
17771782
});
17781783

1784+
const context = Spicetify.React.useContext(Spicetify.ContextMenuV2._context) ?? {};
1785+
const { props, trigger, target } = context;
1786+
17791787
return Spicetify.React.createElement(Spicetify.ReactComponent.MenuSubMenuItem, {
17801788
displayText: _text,
17811789
divider: _divider,
@@ -1785,7 +1793,7 @@ Spicetify.ContextMenuV2 = (() => {
17851793
onClick: () => undefined,
17861794
disabled: _disabled,
17871795
leadingIcon: _leadingIcon && createIconComponent(_leadingIcon),
1788-
children: ItemSubMenu.itemsToComponents(_items),
1796+
children: ItemSubMenu.itemsToComponents(_items, props, trigger, target),
17891797
});
17901798
}, {});
17911799
}

0 commit comments

Comments
 (0)