From edc7264ed773952d2478445fdfde5ecb55b4a379 Mon Sep 17 00:00:00 2001 From: Mirco Wittrien <23700969+mwittrien@users.noreply.github.com> Date: Fri, 17 Jun 2022 18:52:53 +0200 Subject: [PATCH] Update PersonalPins.plugin.js --- Plugins/PersonalPins/PersonalPins.plugin.js | 100 ++++++++++++++++++-- 1 file changed, 92 insertions(+), 8 deletions(-) diff --git a/Plugins/PersonalPins/PersonalPins.plugin.js b/Plugins/PersonalPins/PersonalPins.plugin.js index 0b78b11131..01ba179513 100644 --- a/Plugins/PersonalPins/PersonalPins.plugin.js +++ b/Plugins/PersonalPins/PersonalPins.plugin.js @@ -2,7 +2,7 @@ * @name PersonalPins * @author DevilBro * @authorId 278543574059057154 - * @version 2.0.9 + * @version 2.1.0 * @description Allows you to locally pin Messages * @invite Jx3TjNS * @donate https://www.paypal.me/MircoWittrien @@ -17,8 +17,13 @@ module.exports = (_ => { "info": { "name": "PersonalPins", "author": "DevilBro", - "version": "2.0.9", + "version": "2.1.0", "description": "Allows you to locally pin Messages" + }, + "changeLog": { + "added": { + "Tags": "You can now add tags to notes, they will be included in the search query, allowing you to find notes more easily with your own key words" + } } }; @@ -74,7 +79,7 @@ module.exports = (_ => { const popoutProps = {}; let notes = {}; - + const NotesPopoutComponent = class NotesPopout extends BdApi.React.Component { containsSearchkey(data, key, searchKey) { let value = BDFDB.ObjectUtils.get(data, key); @@ -130,7 +135,7 @@ module.exports = (_ => { let searchKey = popoutProps.searchKey.toUpperCase(); if (searchKey) { let searchValues = ["content", "author.username", "rawDescription", "author.name"]; - messages = messages.filter(m => searchValues.some(key => this.containsSearchkey(m.message, key, searchKey) || m.message.embeds.some(embed => this.containsSearchkey(embed, key, searchKey)))); + messages = messages.filter(m => m.note.tags && m.note.tags.some(tag => tag.indexOf(searchKey.toUpperCase()) > -1) || searchValues.some(key => this.containsSearchkey(m.message, key, searchKey) || m.message.embeds.some(embed => this.containsSearchkey(embed, key, searchKey)))); } BDFDB.ArrayUtils.keySort(messages, popoutProps.selectedSort.value); if (popoutProps.selectedOrder.value != "descending") messages.reverse(); @@ -149,7 +154,7 @@ module.exports = (_ => { } } return [ - popoutProps.selectedFilter.value == "channel" ? null : BDFDB.ReactUtils.createElement("div", { + popoutProps.selectedFilter.value != "channel" && BDFDB.ReactUtils.createElement("div", { className: BDFDB.disCN.messagespopoutchannelseparator, children: [ BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Clickable, { @@ -165,7 +170,8 @@ module.exports = (_ => { children: channel.guild_id ? (BDFDB.LibraryModules.GuildStore.getGuild(channel.guild_id) || {}).name || BDFDB.LanguageUtils.LanguageStrings.GUILD_UNAVAILABLE_HEADER : BDFDB.LanguageUtils.LanguageStrings.DIRECT_MESSAGES }) : null ] - }), BDFDB.ReactUtils.createElement("div", { + }), + BDFDB.ReactUtils.createElement("div", { className: BDFDB.disCN.messagespopoutgroupwrapper, key: message.id, children: [ @@ -226,6 +232,58 @@ module.exports = (_ => { }) }) ] + }), + BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, { + wrap: BDFDB.LibraryComponents.Flex.Wrap.WRAP, + justify: BDFDB.LibraryComponents.Flex.Justify.END, + children: [note.tags].flat(10).filter(n => n).map(label => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Badges.TextBadge, { + className: BDFDB.disCN._personalpinsmessagetag, + color: "var(--background-tertiary)", + onClick: _ => { + BDFDB.ArrayUtils.remove(note.tags, label, true); + BDFDB.DataUtils.save(notes, _this, "notes"); + BDFDB.ReactUtils.forceUpdate(this); + }, + text: [ + BDFDB.ReactUtils.createElement("div", { + className: BDFDB.disCN._personalpinsmessagetagname, + children: label + }), + BDFDB.ReactUtils.createElement("div", { + className: BDFDB.disCN._personalpinsmessagetagdelete, + children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SvgIcon, { + name: BDFDB.LibraryComponents.SvgIcon.Names.CLOSE, + width: 14, + height: 14, + nativeClass: true, + }) + }) + ] + })).concat(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.PopoutContainer, { + children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Badges.TextBadge, { + className: BDFDB.disCNS._personalpinsmessagetag + BDFDB.disCN._personalpinsmessagetagadd, + color: "var(--background-tertiary)", + text: "+" + }), + animation: BDFDB.LibraryComponents.PopoutContainer.Animation.SCALE, + position: BDFDB.LibraryComponents.PopoutContainer.Positions.TOP, + align: BDFDB.LibraryComponents.PopoutContainer.Align.CENTER, + arrow: true, + onOpen: instance => BDFDB.DOMUtils.addClass(instance.domElementRef.current, BDFDB.disCN._personalpinsmessagetagaddactive), + onClose: instance => BDFDB.DOMUtils.removeClass(instance.domElementRef.current, BDFDB.disCN._personalpinsmessagetagaddactive), + renderPopout: instance => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextInput, { + onKeyDown: (event, textInstance) => { + let tag = textInstance.props.value && textInstance.props.value.toUpperCase(); + if (tag && event.which == 13 && (!note.tags || note.tags.indexOf(tag) == -1)) { + instance.toggle(); + if (!note.tags) note.tags = []; + note.tags.push(tag); + BDFDB.DataUtils.save(notes, _this, "notes"); + BDFDB.ReactUtils.forceUpdate(this); + } + } + }) + })) }) ] }) @@ -336,6 +394,32 @@ module.exports = (_ => { HeaderBar: "default" } }; + + this.css = ` + ${BDFDB.dotCN._personalpinsmessagetag} { + margin: 0 3px 4px 3px; + cursor: pointer; + } + ${BDFDB.dotCN._personalpinsmessagetag}:hover ${BDFDB.dotCN._personalpinsmessagetagname} { + height: 0; + visibility: hidden; + } + ${BDFDB.dotCNS._personalpinsmessagetag + BDFDB.dotCN._personalpinsmessagetagdelete} { + visibility: hidden; + } + ${BDFDB.dotCN._personalpinsmessagetag}:hover ${BDFDB.dotCN._personalpinsmessagetagdelete} { + visibility: visible; + } + ${BDFDB.dotCN._personalpinsmessagetag + BDFDB.notCN._personalpinsmessagetagadd}:hover { + background-color: var(--bdfdb-red) !important; + } + ${BDFDB.dotCN._personalpinsmessagetagadd} { + font-size: 16px; + } + ${BDFDB.dotCN._personalpinsmessagetagadd + BDFDB.dotCN._personalpinsmessagetagaddactive} { + background-color: var(--bdfdb-blurple) !important; + } + `; } onStart () { @@ -556,12 +640,12 @@ module.exports = (_ => { return notes[guild_id] && notes[guild_id][channel.id] && notes[guild_id][channel.id][message.id]; } - updateNoteData (note, newmessage) { + updateNoteData (note, newMessage) { let message = JSON.parse(note.message); let channel = JSON.parse(note.channel); if (!message || !channel) return; let guild_id = channel.guild_id || BDFDB.DiscordConstants.ME; - notes[guild_id][channel.id][note.id].message = JSON.stringify(newmessage); + notes[guild_id][channel.id][note.id].message = JSON.stringify(newMessage); BDFDB.DataUtils.save(notes, this, "notes"); BDFDB.NotificationUtils.toast(this.labels.toast_noteupdate, {type: "info"}); }