No more ugly
This commit is contained in:
parent
c4f28a6ac5
commit
b8dc9c0d25
|
@ -56,21 +56,20 @@ export default new class EmoteModule extends BuiltinModule {
|
|||
GlobalAc.add(';', this);
|
||||
|
||||
// Add favourite button to context menu
|
||||
DiscordContextMenu.add([
|
||||
DiscordContextMenu.add(target => [
|
||||
{
|
||||
text: 'Favourite',
|
||||
type: 'toggle',
|
||||
checked: (target) => {
|
||||
const { alt } = target;
|
||||
if (!alt) return false;
|
||||
return this.favourites.find(e => e.alt === alt);
|
||||
},
|
||||
checked: target && target.alt ? this.favourites.find(e => e.alt === target.alt) : false,
|
||||
onChange: (checked, target) => {
|
||||
const { alt } = target;
|
||||
if (!alt) return false;
|
||||
const fav = this.favourites.find(e => e.alt === alt);
|
||||
if (fav) return this._favourites = this._favourites.filter(e => e.alt !== target.alt);
|
||||
this.favourites.push({ alt: target.alt });
|
||||
if (checked) {
|
||||
this.favourites.push({ alt: target.alt });
|
||||
return true;
|
||||
}
|
||||
if (!this._favourites) this._favourites = [];
|
||||
this._favourites = this._favourites.filter(e => e.alt !== target.alt);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
], filter => filter.closest('.bd-emote'));
|
||||
|
|
|
@ -12,14 +12,14 @@
|
|||
<div class="bd-cmGroup" ref="test">
|
||||
<template v-for="(item, index) in items">
|
||||
<CMButton v-if="!item.type || item.type === 'button'" :item="item" :onClick="() => { item.onClick(); closeMenu(); }" />
|
||||
<CMToggle v-else-if="item.type === 'toggle'" :item="item" :checked="typeof item.checked === 'function' ? item.checked(target) : item.checked" :onClick="() => { typeof item.checked === 'function' ? (item.onChange(!item.checked(target), target), $forceUpdate()) : item.onChange(!item.checked) }" />
|
||||
<CMToggle v-else-if="item.type === 'toggle'" :item="item" :checked="item.checked" :onClick="() => { item.checked = item.onChange(!item.checked, target) }" />
|
||||
<div v-else-if="item.type === 'sub'" class="bd-cmItem bd-cmSub" @mouseenter="e => subMenuMouseEnter(e, index, item)" @mouseleave="e => subMenuMouseLeave(e, index, item)">
|
||||
{{item.text}}
|
||||
<MiChevronDown />
|
||||
<div ref="test2" class="bd-cm" v-if="index === visibleSub" :style="subStyle">
|
||||
<div class="bd-cm" v-if="index === visibleSub" :style="subStyle">
|
||||
<template v-for="(item, index) in item.items">
|
||||
<CMButton v-if="!item.type || item.type === 'button'" :item="item" :onClick="() => { item.onClick(); closeMenu(); }" />
|
||||
<CMToggle v-else-if="item.type === 'toggle'" :item="item" :checked="typeof item.checked === 'function' ? item.checked(target) : item.checked" :onClick="() => { typeof item.checked === 'function' ? item.onChange(!item.checked(target), target) && $forceUpdate() : item.onChange(!item.checked) }" />
|
||||
<CMToggle v-else-if="item.type === 'toggle'" :item="item" :checked="item.checked" :onClick="() => { item.checked = item.onChange(!item.checked, target) }" />
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -78,7 +78,7 @@ export class DiscordContextMenu {
|
|||
top,
|
||||
left,
|
||||
closeMenu: () => WebpackModules.getModuleByProps(['closeContextMenu']).closeContextMenu(),
|
||||
items: menu.items
|
||||
items: typeof menu.items === 'function' ? menu.items(target) : menu.items
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue