No more ugly

This commit is contained in:
Jiiks 2018-08-22 18:33:00 +03:00
parent c4f28a6ac5
commit b8dc9c0d25
3 changed files with 13 additions and 14 deletions

View File

@ -56,21 +56,20 @@ export default new class EmoteModule extends BuiltinModule {
GlobalAc.add(';', this); GlobalAc.add(';', this);
// Add favourite button to context menu // Add favourite button to context menu
DiscordContextMenu.add([ DiscordContextMenu.add(target => [
{ {
text: 'Favourite', text: 'Favourite',
type: 'toggle', type: 'toggle',
checked: (target) => { checked: target && target.alt ? this.favourites.find(e => e.alt === target.alt) : false,
const { alt } = target;
if (!alt) return false;
return this.favourites.find(e => e.alt === alt);
},
onChange: (checked, target) => { onChange: (checked, target) => {
const { alt } = target; const { alt } = target;
if (!alt) return false; if (checked) {
const fav = this.favourites.find(e => e.alt === alt); this.favourites.push({ alt: target.alt });
if (fav) return this._favourites = this._favourites.filter(e => e.alt !== target.alt); return true;
this.favourites.push({ alt: target.alt }); }
if (!this._favourites) this._favourites = [];
this._favourites = this._favourites.filter(e => e.alt !== target.alt);
return false;
} }
} }
], filter => filter.closest('.bd-emote')); ], filter => filter.closest('.bd-emote'));

View File

@ -12,14 +12,14 @@
<div class="bd-cmGroup" ref="test"> <div class="bd-cmGroup" ref="test">
<template v-for="(item, index) in items"> <template v-for="(item, index) in items">
<CMButton v-if="!item.type || item.type === 'button'" :item="item" :onClick="() => { item.onClick(); closeMenu(); }" /> <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)"> <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}} {{item.text}}
<MiChevronDown /> <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"> <template v-for="(item, index) in item.items">
<CMButton v-if="!item.type || item.type === 'button'" :item="item" :onClick="() => { item.onClick(); closeMenu(); }" /> <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> </template>
</div> </div>
</div> </div>

View File

@ -78,7 +78,7 @@ export class DiscordContextMenu {
top, top,
left, left,
closeMenu: () => WebpackModules.getModuleByProps(['closeContextMenu']).closeContextMenu(), closeMenu: () => WebpackModules.getModuleByProps(['closeContextMenu']).closeContextMenu(),
items: menu.items items: typeof menu.items === 'function' ? menu.items(target) : menu.items
})); }));
} }
} }