Update ReadAllNotificationsButton.plugin.js

This commit is contained in:
Mirco Wittrien 2022-10-11 13:31:49 +02:00
parent 1e5e501d53
commit 69b1e41e5d
1 changed files with 19 additions and 15 deletions

View File

@ -2,7 +2,7 @@
* @name ReadAllNotificationsButton * @name ReadAllNotificationsButton
* @author DevilBro * @author DevilBro
* @authorId 278543574059057154 * @authorId 278543574059057154
* @version 1.7.2 * @version 1.7.3
* @description Adds a Clear Button to the Server List and the Mentions Popout * @description Adds a Clear Button to the Server List and the Mentions Popout
* @invite Jx3TjNS * @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien * @donate https://www.paypal.me/MircoWittrien
@ -137,8 +137,8 @@ module.exports = (_ => {
this.defaults = { this.defaults = {
general: { general: {
addClearButton: {value: true, description: "Add a 'Clear Mentions' button to the recent mentions popout"}, addClearButton: {value: true, description: "Adds a 'Clear Mentions' button to the recent mentions popout"},
confirmClear: {value: false, description: "Ask for your confirmation before clearing reads"} confirmClear: {value: false, description: "Asks for your confirmation before clearing reads"}
}, },
batch: { batch: {
guilds: {value: true, description: "unread Servers"}, guilds: {value: true, description: "unread Servers"},
@ -222,6 +222,18 @@ module.exports = (_ => {
})) }))
})); }));
let listInstance = null, batchSetGuilds = value => {
if (!value) {
for (let id of BDFDB.LibraryModules.SortedGuildUtils.getFlattenedGuildIds()) blacklist.push(id);
blacklist = BDFDB.ArrayUtils.removeCopies(blacklist);
}
else blacklist = [];
this.saveBlacklist(blacklist);
if (listInstance) {
listInstance.props.disabled = blacklist;
BDFDB.ReactUtils.forceUpdate(listInstance);
}
};
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, { settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, {
title: "Server Black List", title: "Server Black List",
collapseStates: collapseStates, collapseStates: collapseStates,
@ -229,20 +241,21 @@ module.exports = (_ => {
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsGuildList, { BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsGuildList, {
className: BDFDB.disCN.marginbottom20, className: BDFDB.disCN.marginbottom20,
disabled: BDFDB.DataUtils.load(this, "blacklist"), disabled: BDFDB.DataUtils.load(this, "blacklist"),
onClick: disabledGuilds => this.saveBlacklist(disabledGuilds) onClick: disabledGuilds => this.saveBlacklist(disabledGuilds),
ref: instance => {listInstance = instance;}
}), }),
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, { BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, {
type: "Button", type: "Button",
color: BDFDB.LibraryComponents.Button.Colors.GREEN, color: BDFDB.LibraryComponents.Button.Colors.GREEN,
label: "Enable for all Servers", label: "Enable for all Servers",
onClick: _ => this.batchSetGuilds(settingsPanel, collapseStates, true), onClick: _ => batchSetGuilds(true),
children: BDFDB.LanguageUtils.LanguageStrings.ENABLE children: BDFDB.LanguageUtils.LanguageStrings.ENABLE
}), }),
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, { BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, {
type: "Button", type: "Button",
color: BDFDB.LibraryComponents.Button.Colors.PRIMARY, color: BDFDB.LibraryComponents.Button.Colors.PRIMARY,
label: "Disable for all Servers", label: "Disable for all Servers",
onClick: _ => this.batchSetGuilds(settingsPanel, collapseStates, false), onClick: _ => batchSetGuilds(false),
children: BDFDB.LanguageUtils.LanguageStrings.DISABLE children: BDFDB.LanguageUtils.LanguageStrings.DISABLE
}) })
] ]
@ -309,15 +322,6 @@ module.exports = (_ => {
].flat(10); ].flat(10);
} }
batchSetGuilds (settingsPanel, collapseStates, value) {
if (!value) {
for (let id of BDFDB.LibraryModules.SortedGuildUtils.getFlattenedGuildIds()) blacklist.push(id);
this.saveBlacklist(BDFDB.ArrayUtils.removeCopies(blacklist));
}
else this.saveBlacklist([]);
BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel, collapseStates);
}
saveBlacklist (savedBlacklist) { saveBlacklist (savedBlacklist) {
blacklist = savedBlacklist; blacklist = savedBlacklist;
BDFDB.DataUtils.save(savedBlacklist, this, "blacklist"); BDFDB.DataUtils.save(savedBlacklist, this, "blacklist");