This commit is contained in:
Mirco Wittrien 2021-05-17 12:44:34 +02:00
parent a6dbeb6caf
commit 5e81f626e2
2 changed files with 107 additions and 97 deletions

View File

@ -799,6 +799,7 @@ img:not([src]), img[src=""], img[src="null"] {
min-height: 56px; min-height: 56px;
} }
[REPLACE_CLASS_popoutwrapper] [REPLACE_CLASS_messagespopouttabbarheader] [REPLACE_CLASS_messagespopouttabbar] { [REPLACE_CLASS_popoutwrapper] [REPLACE_CLASS_messagespopouttabbarheader] [REPLACE_CLASS_messagespopouttabbar] {
align-items: center;
flex: 1 1 auto; flex: 1 1 auto;
min-height: 32px; min-height: 32px;
} }

View File

@ -2,7 +2,7 @@
* @name PersonalPins * @name PersonalPins
* @author DevilBro * @author DevilBro
* @authorId 278543574059057154 * @authorId 278543574059057154
* @version 2.0.2 * @version 2.0.3
* @description Allows you to locally pin Messages * @description Allows you to locally pin Messages
* @invite Jx3TjNS * @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien * @donate https://www.paypal.me/MircoWittrien
@ -17,8 +17,14 @@ module.exports = (_ => {
"info": { "info": {
"name": "PersonalPins", "name": "PersonalPins",
"author": "DevilBro", "author": "DevilBro",
"version": "2.0.2", "version": "2.0.3",
"description": "Allows you to locally pin Messages" "description": "Allows you to locally pin Messages"
},
"changeLog": {
"improved": {
"Performance": "Added Pagination to the Notes Popout to reduce the Stress for People who saved a lot of Notes",
"Pagination": "Fixed some Performance Issues"
},
} }
}; };
@ -73,6 +79,7 @@ module.exports = (_ => {
const orderKeys = ["ascending", "descending"]; const orderKeys = ["ascending", "descending"];
const popoutProps = {}; const popoutProps = {};
let notes = {};
const NotesPopoutComponent = class NotesPopout extends BdApi.React.Component { const NotesPopoutComponent = class NotesPopout extends BdApi.React.Component {
containsSearchkey(data, key, searchKey) { containsSearchkey(data, key, searchKey) {
@ -80,7 +87,7 @@ module.exports = (_ => {
return value && value.toUpperCase().indexOf(searchKey) > -1; return value && value.toUpperCase().indexOf(searchKey) > -1;
} }
filterMessages() { filterMessages() {
let messages = [], notes = BDFDB.DataUtils.load(_this, "notes"), updateData = false; let messages = [], updateData = false;
for (let guild_id in notes) for (let channel_id in notes[guild_id]) for (let message_idPOS in notes[guild_id][channel_id]) { for (let guild_id in notes) for (let channel_id in notes[guild_id]) for (let message_idPOS in notes[guild_id][channel_id]) {
let message = JSON.parse(notes[guild_id][channel_id][message_idPOS].message); let message = JSON.parse(notes[guild_id][channel_id][message_idPOS].message);
message.author = new BDFDB.DiscordObjects.User(message.author); message.author = new BDFDB.DiscordObjects.User(message.author);
@ -132,12 +139,7 @@ module.exports = (_ => {
} }
BDFDB.ArrayUtils.keySort(messages, popoutProps.selectedSort.value); BDFDB.ArrayUtils.keySort(messages, popoutProps.selectedSort.value);
if (popoutProps.selectedOrder.value != "descending") messages.reverse(); if (popoutProps.selectedOrder.value != "descending") messages.reverse();
return Object.keys(messages).length ? return messages;
messages.map(messageData => this.renderMessage(messageData.note, messageData.message, messageData.channel)).flat(10).filter(n => n) :
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.MessagesPopoutComponents.EmptyStateCenter, {
msg: BDFDB.LanguageUtils.LanguageStrings.AUTOCOMPLETE_NO_RESULTS_HEADER,
image: BDFDB.DiscordUtils.getTheme() == BDFDB.disCN.themelight ? "/assets/03c7541028afafafd1a9f6a81cb7f149.svg" : "/assets/6793e022dc1b065b21f12d6df02f91bd.svg"
});
} }
renderMessage(note, message, channel) { renderMessage(note, message, channel) {
if (!message || !channel) return null; if (!message || !channel) return null;
@ -151,7 +153,8 @@ module.exports = (_ => {
channelName = channelName + ((BDFDB.LibraryModules.UserStore.getUser(dmuser_id) || {}).username || BDFDB.LanguageUtils.LanguageStrings.UNKNOWN_USER); channelName = channelName + ((BDFDB.LibraryModules.UserStore.getUser(dmuser_id) || {}).username || BDFDB.LanguageUtils.LanguageStrings.UNKNOWN_USER);
} }
} }
return [popoutProps.selectedFilter.value == "channel" ? null : BDFDB.ReactUtils.createElement("div", { return [
popoutProps.selectedFilter.value == "channel" ? null : BDFDB.ReactUtils.createElement("div", {
className: BDFDB.disCN.messagespopoutchannelseparator, className: BDFDB.disCN.messagespopoutchannelseparator,
children: [ children: [
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Clickable, { BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Clickable, {
@ -228,10 +231,12 @@ module.exports = (_ => {
] ]
}) })
] ]
})]; })
];
} }
render() { render() {
let searchTimeout; let searchTimeout;
const messages = this.filterMessages();
return BDFDB.ReactUtils.createElement(BDFDB.ReactUtils.Fragment, { return BDFDB.ReactUtils.createElement(BDFDB.ReactUtils.Fragment, {
children: [ children: [
BDFDB.ReactUtils.createElement("div", { BDFDB.ReactUtils.createElement("div", {
@ -302,9 +307,15 @@ module.exports = (_ => {
] ]
}) })
}), }),
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Scrollers.Thin, { messages.length ? BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.PaginatedList, {
className: BDFDB.disCN.messagespopout, className: BDFDB.disCN.messagespopout,
children: this.filterMessages() items: messages,
amount: 25,
copyToBottom: true,
renderItem: messageData => this.renderMessage(messageData.note, messageData.message, messageData.channel).flat(10).filter(n => n)
}) : BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.MessagesPopoutComponents.EmptyStateCenter, {
msg: BDFDB.LanguageUtils.LanguageStrings.AUTOCOMPLETE_NO_RESULTS_HEADER,
image: BDFDB.DiscordUtils.getTheme() == BDFDB.disCN.themelight ? "/assets/03c7541028afafafd1a9f6a81cb7f149.svg" : "/assets/6793e022dc1b065b21f12d6df02f91bd.svg"
}) })
] ]
}); });
@ -331,6 +342,7 @@ module.exports = (_ => {
} }
onStart () { onStart () {
notes = BDFDB.DataUtils.load(this, "notes");
BDFDB.PatchUtils.forceAllUpdates(this); BDFDB.PatchUtils.forceAllUpdates(this);
} }
@ -359,10 +371,11 @@ module.exports = (_ => {
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, { settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, {
type: "Button", type: "Button",
color: BDFDB.LibraryComponents.Button.Colors.RED, color: BDFDB.LibraryComponents.Button.Colors.RED,
label: "Delete all notes", label: "Delete all Notes",
onClick: _ => { onClick: _ => BDFDB.ModalUtils.confirm(this, "Are you sure you want to delete all pinned Notes?", _ => {
BDFDB.ModalUtils.confirm(this, "Are you sure you want to delete all pinned Notes?", _ => BDFDB.DataUtils.remove(this, "notes")); notes = {};
}, BDFDB.DataUtils.remove(this, "notes");
}),
children: BDFDB.LanguageUtils.LanguageStrings.DELETE children: BDFDB.LanguageUtils.LanguageStrings.DELETE
})); }));
@ -494,7 +507,6 @@ module.exports = (_ => {
addMessageToNotes (message, channel) { addMessageToNotes (message, channel) {
if (!message) return; if (!message) return;
let notes = BDFDB.DataUtils.load(this, "notes");
channel = channel || BDFDB.LibraryModules.ChannelStore.getChannel(message.channel_id); channel = channel || BDFDB.LibraryModules.ChannelStore.getChannel(message.channel_id);
let guild_id = channel.guild_id || BDFDB.DiscordConstants.ME; let guild_id = channel.guild_id || BDFDB.DiscordConstants.ME;
notes[guild_id] = notes[guild_id] || {}; notes[guild_id] = notes[guild_id] || {};
@ -514,15 +526,14 @@ module.exports = (_ => {
} }
isNoteOutdated (note, message) { isNoteOutdated (note, message) {
let notemessage = note && JSON.parse(note.message), keys = ["content", "embeds", "attachment"]; let noteMessage = note && JSON.parse(note.message), keys = ["content", "embeds", "attachment"];
return notemessage && !BDFDB.equals(BDFDB.ObjectUtils.extract(notemessage, keys), BDFDB.ObjectUtils.extract(message, keys)); return noteMessage && !BDFDB.equals(BDFDB.ObjectUtils.extract(noteMessage, keys), BDFDB.ObjectUtils.extract(message, keys));
} }
getNoteData (message, channel) { getNoteData (message, channel) {
if (!message) return; if (!message) return;
channel = channel || BDFDB.LibraryModules.ChannelStore.getChannel(message.channel_id); channel = channel || BDFDB.LibraryModules.ChannelStore.getChannel(message.channel_id);
let guild_id = channel.guild_id || BDFDB.DiscordConstants.ME; let guild_id = channel.guild_id || BDFDB.DiscordConstants.ME;
let notes = BDFDB.DataUtils.load(this, "notes");
return notes[guild_id] && notes[guild_id][channel.id] && notes[guild_id][channel.id][message.id]; return notes[guild_id] && notes[guild_id][channel.id] && notes[guild_id][channel.id][message.id];
} }
@ -531,7 +542,6 @@ module.exports = (_ => {
let channel = JSON.parse(note.channel); let channel = JSON.parse(note.channel);
if (!message || !channel) return; if (!message || !channel) return;
let guild_id = channel.guild_id || BDFDB.DiscordConstants.ME; let guild_id = channel.guild_id || BDFDB.DiscordConstants.ME;
let notes = BDFDB.DataUtils.load(this, "notes");
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.DataUtils.save(notes, this, "notes");
BDFDB.NotificationUtils.toast(this.labels.toast_noteupdate, {type: "info"}); BDFDB.NotificationUtils.toast(this.labels.toast_noteupdate, {type: "info"});
@ -542,7 +552,6 @@ module.exports = (_ => {
let channel = JSON.parse(note.channel); let channel = JSON.parse(note.channel);
if (!message || !channel) return; if (!message || !channel) return;
let guild_id = channel.guild_id || BDFDB.DiscordConstants.ME; let guild_id = channel.guild_id || BDFDB.DiscordConstants.ME;
let notes = BDFDB.DataUtils.load(this, "notes");
delete notes[guild_id][channel.id][note.id]; delete notes[guild_id][channel.id][note.id];
if (BDFDB.ObjectUtils.isEmpty(notes[guild_id][channel.id])) { if (BDFDB.ObjectUtils.isEmpty(notes[guild_id][channel.id])) {
delete notes[guild_id][channel.id]; delete notes[guild_id][channel.id];