This commit is contained in:
Mirco Wittrien 2019-10-17 11:36:34 +02:00
parent a0b46ec046
commit 115e2921cb
5 changed files with 428 additions and 456 deletions

File diff suppressed because one or more lines are too long

View File

@ -1727,18 +1727,18 @@ var BDFDB = {myPlugins: BDFDB && BDFDB.myPlugins ? BDFDB.myPlugins : {}, BDv2Api
BDFDB.createSettingsPanel = function (plugin, children) { BDFDB.createSettingsPanel = function (plugin, children) {
if (!BDFDB.isObject(plugin) || !children || (!BDFDB.React.isValidElement(children) && !Array.isArray(children)) || (Array.isArray(children) && !children.length)) return; if (!BDFDB.isObject(plugin) || !children || (!BDFDB.React.isValidElement(children) && !Array.isArray(children)) || (Array.isArray(children) && !children.length)) return;
var settingspanel = BDFDB.htmlToElement(`<div class="${plugin.name}-settings BDFDB-settings"></div>`); var settingspanel = BDFDB.htmlToElement(`<div class="${plugin.name}-settings BDFDB-settings"></div>`);
BDFDB.React.render(BDFDB.React.createElement(BDFDB.LibraryComponents.Flex, { BDFDB.React.render(BDFDB.React.createElement(LibraryComponents.Flex, {
direction: BDFDB.LibraryComponents.Flex.Direction.VERTICAL, direction: LibraryComponents.Flex.Direction.VERTICAL,
grow: 1, grow: 1,
children: [ children: [
BDFDB.React.createElement(BDFDB.LibraryComponents.FormComponents.FormTitle, { BDFDB.React.createElement(LibraryComponents.FormComponents.FormTitle, {
className: BDFDB.disCNS.marginbottom20 + "BDFDB-settings-title", className: BDFDB.disCNS.marginbottom20 + "BDFDB-settings-title",
tag: BDFDB.LibraryComponents.FormComponents.FormTitle.Tags.H2, tag: LibraryComponents.FormComponents.FormTitle.Tags.H2,
children: plugin.name children: plugin.name
}), }),
BDFDB.React.createElement(BDFDB.LibraryComponents.Flex, { BDFDB.React.createElement(LibraryComponents.Flex, {
className: "BDFDB-settings-inner", className: "BDFDB-settings-inner",
direction: BDFDB.LibraryComponents.Flex.Direction.VERTICAL, direction: LibraryComponents.Flex.Direction.VERTICAL,
grow: 1, grow: 1,
children: settingsitems children: settingsitems
}) })
@ -3391,7 +3391,7 @@ var BDFDB = {myPlugins: BDFDB && BDFDB.myPlugins ? BDFDB.myPlugins : {}, BDv2Api
} }
if (config.children) { if (config.children) {
let selectedtab, tabs = []; let selectedtab, tabs = [];
for (let child of (Array.isArray(config.children) ? config.children : Array.from(config.children))) if (LibraryModules.React.isValidElement(child)) { for (let child of (Array.isArray(config.children) ? config.children : Array.of(config.children))) if (LibraryModules.React.isValidElement(child)) {
if (child.type == LibraryComponents.ModalTabContent) { if (child.type == LibraryComponents.ModalTabContent) {
if (!tabs.length) child.props.open = true; if (!tabs.length) child.props.open = true;
else delete child.props.open; else delete child.props.open;
@ -5858,6 +5858,8 @@ var BDFDB = {myPlugins: BDFDB && BDFDB.myPlugins ? BDFDB.myPlugins : {}, BDv2Api
LibraryComponents.TextElement = BDFDB.WebModules.findByName('Text'); LibraryComponents.TextElement = BDFDB.WebModules.findByName('Text');
LibraryComponents.TextInput = reactInitialized ? class TextInput extends LibraryModules.React.Component { LibraryComponents.TextInput = reactInitialized ? class TextInput extends LibraryModules.React.Component {
handleChange(e) { handleChange(e) {
this.props.value = e;
this.forceUpdate();
if (typeof this.props.onChange == 'function') this.props.onChange(e, this); if (typeof this.props.onChange == 'function') this.props.onChange(e, this);
} }
render() {return BDFDB.React.createElement(NativeSubComponents.TextInput, Object.assign({}, this.props, {onChange: this.handleChange.bind(this)}));} render() {return BDFDB.React.createElement(NativeSubComponents.TextInput, Object.assign({}, this.props, {onChange: this.handleChange.bind(this)}));}

View File

@ -3,7 +3,7 @@
class EditChannels { class EditChannels {
getName () {return "EditChannels";} getName () {return "EditChannels";}
getVersion () {return "4.0.3";} getVersion () {return "4.0.4";}
getAuthor () {return "DevilBro";} getAuthor () {return "DevilBro";}
@ -90,8 +90,7 @@ class EditChannels {
onClick: _ => { onClick: _ => {
BDFDB.openConfirmModal(this, "Are you sure you want to reset all channels?", () => { BDFDB.openConfirmModal(this, "Are you sure you want to reset all channels?", () => {
BDFDB.removeAllData(this, "channels"); BDFDB.removeAllData(this, "channels");
this.changeAppTitle(); this.forceUpdateAll();
BDFDB.WebModules.forceAllUpdates(this);
}); });
}, },
children: BDFDB.LanguageStrings.RESET children: BDFDB.LanguageStrings.RESET
@ -142,9 +141,8 @@ class EditChannels {
var observer = new MutationObserver(() => {this.changeAppTitle();}); var observer = new MutationObserver(() => {this.changeAppTitle();});
BDFDB.addObserver(this, document.head.querySelector("title"), {name:"appTitleObserver",instance:observer}, {childList:true}); BDFDB.addObserver(this, document.head.querySelector("title"), {name:"appTitleObserver",instance:observer}, {childList:true});
this.changeAppTitle();
BDFDB.WebModules.forceAllUpdates(this); this.forceUpdateAll();
} }
else { else {
console.error(`%c[${this.getName()}]%c`, 'color: #3a71c1; font-weight: 700;', '', 'Fatal Error: Could not load BD functions!'); console.error(`%c[${this.getName()}]%c`, 'color: #3a71c1; font-weight: 700;', '', 'Fatal Error: Could not load BD functions!');
@ -155,7 +153,7 @@ class EditChannels {
if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) { if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
let data = BDFDB.loadAllData(this, "channels"); let data = BDFDB.loadAllData(this, "channels");
BDFDB.removeAllData(this, "channels"); BDFDB.removeAllData(this, "channels");
try {BDFDB.WebModules.forceAllUpdates(this);} catch (err) {} try {this.forceUpdateAll();} catch (err) {}
BDFDB.saveAllData(data, this, "channels"); BDFDB.saveAllData(data, this, "channels");
BDFDB.removeEles(".autocompleteEditChannels", ".autocompleteEditChannelsRow"); BDFDB.removeEles(".autocompleteEditChannels", ".autocompleteEditChannelsRow");
@ -194,8 +192,7 @@ class EditChannels {
action: e => { action: e => {
BDFDB.closeContextMenu(menu); BDFDB.closeContextMenu(menu);
BDFDB.removeData(instance.props.channel.id, this, "channels"); BDFDB.removeData(instance.props.channel.id, this, "channels");
this.changeAppTitle(); this.forceUpdateAll();
BDFDB.WebModules.forceAllUpdates(this);
} }
}) })
] ]
@ -208,8 +205,13 @@ class EditChannels {
} }
} }
forceUpdateAll () {
this.changeAppTitle();
BDFDB.WebModules.forceAllUpdates(this);
}
showChannelSettings (info) { showChannelSettings (info) {
var {name,color,inheritColor} = BDFDB.loadData(info.id, this, "channels") || {}; var data = BDFDB.loadData(info.id, this, "channels") || {};
BDFDB.openModal(this, { BDFDB.openModal(this, {
size: "MEDIUM", size: "MEDIUM",
@ -221,7 +223,7 @@ class EditChannels {
className: BDFDB.disCN.marginbottom20 + " input-channelname", className: BDFDB.disCN.marginbottom20 + " input-channelname",
children: [ children: [
BDFDB.React.createElement(BDFDB.LibraryComponents.TextInput, { BDFDB.React.createElement(BDFDB.LibraryComponents.TextInput, {
value: name, value: data.name,
placeholder: info.name, placeholder: info.name,
autoFocus: true autoFocus: true
}), }),
@ -235,7 +237,7 @@ class EditChannels {
className: BDFDB.disCN.marginbottom20, className: BDFDB.disCN.marginbottom20,
children: [ children: [
BDFDB.React.createElement(BDFDB.LibraryComponents.ColorSwatches, { BDFDB.React.createElement(BDFDB.LibraryComponents.ColorSwatches, {
color: color, color: data.color,
number: 1 number: 1
}) })
] ]
@ -244,7 +246,7 @@ class EditChannels {
type: "Switch", type: "Switch",
className: BDFDB.disCN.marginbottom20 + " input-inheritcolor", className: BDFDB.disCN.marginbottom20 + " input-inheritcolor",
label: this.labels.modal_inheritcolor_text, label: this.labels.modal_inheritcolor_text,
value: info.type == 4 && inheritColor, value: info.type == 4 && data.inheritColor,
disabled: info.type != 4 disabled: info.type != 4
}) })
], ],
@ -256,20 +258,20 @@ class EditChannels {
let channelnameinput = modal.querySelector(".input-channelname " + BDFDB.dotCN.input); let channelnameinput = modal.querySelector(".input-channelname " + BDFDB.dotCN.input);
let inheritcolorinput = modal.querySelector(".input-inheritcolor " + BDFDB.dotCN.switchinner); let inheritcolorinput = modal.querySelector(".input-inheritcolor " + BDFDB.dotCN.switchinner);
name = channelnameinput.value.trim() || null; data.name = channelnameinput.value.trim() || null;
color = BDFDB.getSwatchColor(modal, 1); data.color = BDFDB.getSwatchColor(modal, 1);
if (color != null && !BDFDB.isObject(color)) { if (data.color != null && !BDFDB.isObject(data.color)) {
if (color[0] < 30 && color[1] < 30 && color[2] < 30) color = BDFDB.colorCHANGE(color, 30); if (data.color[0] < 30 && data.color[1] < 30 && data.color[2] < 30) data.color = BDFDB.colorCHANGE(data.color, 30);
else if (color[0] > 225 && color[1] > 225 && color[2] > 225) color = BDFDB.colorCHANGE(color, -30); else if (data.color[0] > 225 && data.color[1] > 225 && data.color[2] > 225) data.color = BDFDB.colorCHANGE(data.color, -30);
} }
inheritColor = inheritcolorinput.checked; data.inheritColor = inheritcolorinput.checked;
if (name == null && color == null) BDFDB.removeData(info.id, this, "channels"); let changed = false;
else BDFDB.saveData(info.id, {name,color,inheritColor}, this, "channels"); if (Object.keys(data).every(key => data[key] == null || data[key] == false) && (changed = true)) BDFDB.removeData(info.id, this, "channels");
this.changeAppTitle(); else if (!BDFDB.equals(olddata, data) && (changed = true)) BDFDB.saveData(info.id, data, this, "channels");
BDFDB.WebModules.forceAllUpdates(this); if (changed) this.forceUpdateAll();
} }
}] }]
}); });
@ -422,8 +424,7 @@ class EditChannels {
processStandardSidebarView (instance, wrapper, returnvalue) { processStandardSidebarView (instance, wrapper, returnvalue) {
if (this.SettingsUpdated) { if (this.SettingsUpdated) {
delete this.SettingsUpdated; delete this.SettingsUpdated;
this.changeAppTitle(); this.forceUpdateAll();
BDFDB.WebModules.forceAllUpdates(this);
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -3,7 +3,7 @@
class EditUsers { class EditUsers {
getName () {return "EditUsers";} getName () {return "EditUsers";}
getVersion () {return "3.6.2";} getVersion () {return "3.6.3";}
getAuthor () {return "DevilBro";} getAuthor () {return "DevilBro";}
@ -11,7 +11,7 @@ class EditUsers {
constructor () { constructor () {
this.changelog = { this.changelog = {
"fixed":[["Profile Pictures","Fixed places where profile pictures weren't changed properly"]] "improved":[["Switching to React","Using React to create settings and modals, faster and more less likely to break"]]
}; };
this.labels = {}; this.labels = {};
@ -136,14 +136,13 @@ class EditUsers {
onClick: _ => { onClick: _ => {
BDFDB.openConfirmModal(this, "Are you sure you want to reset all users?", () => { BDFDB.openConfirmModal(this, "Are you sure you want to reset all users?", () => {
BDFDB.removeAllData(this, "users"); BDFDB.removeAllData(this, "users");
this.changeAppTitle(); this.forceUpdateAll();
BDFDB.WebModules.forceAllUpdates(this);
}); });
}, },
children: BDFDB.LanguageStrings.RESET children: BDFDB.LanguageStrings.RESET
})); }));
return BDFDB.createSettingsPanel(plugin, settingsitems); return BDFDB.createSettingsPanel(this, settingsitems);
} }
//legacy //legacy
@ -188,9 +187,8 @@ class EditUsers {
var observer = new MutationObserver(() => {this.changeAppTitle();}); var observer = new MutationObserver(() => {this.changeAppTitle();});
BDFDB.addObserver(this, document.head.querySelector("title"), {name:"appTitleObserver",instance:observer}, {childList:true}); BDFDB.addObserver(this, document.head.querySelector("title"), {name:"appTitleObserver",instance:observer}, {childList:true});
this.changeAppTitle();
BDFDB.WebModules.forceAllUpdates(this); this.forceUpdateAll();
} }
else { else {
console.error(`%c[${this.getName()}]%c`, 'color: #3a71c1; font-weight: 700;', '', 'Fatal Error: Could not load BD functions!'); console.error(`%c[${this.getName()}]%c`, 'color: #3a71c1; font-weight: 700;', '', 'Fatal Error: Could not load BD functions!');
@ -202,10 +200,7 @@ class EditUsers {
if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) { if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
let data = BDFDB.loadAllData(this, "users"); let data = BDFDB.loadAllData(this, "users");
BDFDB.removeAllData(this, "users"); BDFDB.removeAllData(this, "users");
try { try {this.forceUpdateAll();} catch (err) {}
this.changeAppTitle();
BDFDB.WebModules.forceAllUpdates(this);
} catch (err) {}
BDFDB.saveAllData(data, this, "users"); BDFDB.saveAllData(data, this, "users");
BDFDB.removeEles(".autocompleteEditUsers", ".autocompleteEditUsersRow"); BDFDB.removeEles(".autocompleteEditUsers", ".autocompleteEditUsersRow");
@ -244,8 +239,7 @@ class EditUsers {
action: e => { action: e => {
BDFDB.closeContextMenu(menu); BDFDB.closeContextMenu(menu);
BDFDB.removeData(instance.props.user.id, this, "users"); BDFDB.removeData(instance.props.user.id, this, "users");
this.changeAppTitle(); this.forceUpdateAll();
BDFDB.WebModules.forceAllUpdates(this);
} }
}) })
] ]
@ -258,6 +252,11 @@ class EditUsers {
} }
} }
forceUpdateAll () {
this.changeAppTitle();
BDFDB.WebModules.forceAllUpdates(this);
}
showUserSettings (info) { showUserSettings (info) {
let data = BDFDB.loadData(info.id, this, "users") || {}; let data = BDFDB.loadData(info.id, this, "users") || {};
let member = BDFDB.LibraryModules.MemberStore.getMember(BDFDB.LibraryModules.LastGuildStore.getGuildId(), info.id) || {}; let member = BDFDB.LibraryModules.MemberStore.getMember(BDFDB.LibraryModules.LastGuildStore.getGuildId(), info.id) || {};
@ -292,7 +291,7 @@ class EditUsers {
}), }),
BDFDB.React.createElement(BDFDB.LibraryComponents.FormComponents.FormItem, { BDFDB.React.createElement(BDFDB.LibraryComponents.FormComponents.FormItem, {
title: this.labels.modal_useravatar_text, title: this.labels.modal_useravatar_text,
className: BDFDB.disCN.marginbottom20 + " input-useravatar", className: BDFDB.disCN.marginbottom8 + " input-useravatar",
children: [ children: [
BDFDB.React.createElement(BDFDB.LibraryComponents.TextInput, { BDFDB.React.createElement(BDFDB.LibraryComponents.TextInput, {
inputClassName: !data.removeIcon && data.url ? BDFDB.disCN.inputsuccess : null, inputClassName: !data.removeIcon && data.url ? BDFDB.disCN.inputsuccess : null,
@ -303,27 +302,7 @@ class EditUsers {
this.createNoticeTooltip(e.target); this.createNoticeTooltip(e.target);
}, },
onChange: (value, instance) => { onChange: (value, instance) => {
let input = BDFDB.React.findDOMNodeSafe(instance).firstElementChild; this.checkUrl(value, instance);
clearTimeout(instance.checkTimeout);
if (value == null || !value.trim()) {
if (input) BDFDB.removeEles(input.tooltip);
instance.props.inputClassName = null;
instance.forceUpdate();
}
else instance.checkTimeout = setTimeout(() => {
BDFDB.LibraryRequires.request(value.trim(), (error, response, result) => {
if (response && response.headers["content-type"] && response.headers["content-type"].indexOf("image") != -1) {
if (input) BDFDB.removeEles(input.tooltip);
instance.props.inputClassName = BDFDB.disCN.inputsuccess;
}
else {
this.createNoticeTooltip(input, true);
instance.props.inputClassName = BDFDB.disCN.inputerror;
}
delete instance.checkTimeout;
instance.forceUpdate();
});
}, 1000);
} }
}) })
] ]
@ -341,7 +320,7 @@ class EditUsers {
avatarinputins.forceUpdate(); avatarinputins.forceUpdate();
} }
} }
}), })
] ]
}), }),
BDFDB.React.createElement(BDFDB.LibraryComponents.ModalTabContent, { BDFDB.React.createElement(BDFDB.LibraryComponents.ModalTabContent, {
@ -416,7 +395,6 @@ class EditUsers {
click: modal => { click: modal => {
let olddata = Object.assign({}, data); let olddata = Object.assign({}, data);
let channelnameinput = modal.querySelector(".input-channelname " + BDFDB.dotCN.input);
let usernameinput = modal.querySelector(".input-username " + BDFDB.dotCN.input); let usernameinput = modal.querySelector(".input-username " + BDFDB.dotCN.input);
let usertaginput = modal.querySelector(".input-usertag " + BDFDB.dotCN.input); let usertaginput = modal.querySelector(".input-usertag " + BDFDB.dotCN.input);
let useravatarinput = modal.querySelector(".input-useravatar " + BDFDB.dotCN.input); let useravatarinput = modal.querySelector(".input-useravatar " + BDFDB.dotCN.input);
@ -425,9 +403,9 @@ class EditUsers {
data.name = usernameinput.value.trim() || null; data.name = usernameinput.value.trim() || null;
data.tag = usertaginput.value.trim() || null; data.tag = usertaginput.value.trim() || null;
data.url = (!data.removeIcon && BDFDB.containsClass(useravatarinput, BDFDB.disCN.inputsuccess) ? useravatarinput.value.trim() : null) || null;
data.removeIcon = removeiconinput.checked; data.removeIcon = removeiconinput.checked;
data.ignoreTagColor = ignoretagcolorinput.checked; data.ignoreTagColor = ignoretagcolorinput.checked;
data.url = (!data.removeIcon && BDFDB.containsClass(useravatarinput, BDFDB.disCN.inputsuccess) ? useravatarinput.value.trim() : null) || null;
data.color1 = BDFDB.getSwatchColor(modal, 1); data.color1 = BDFDB.getSwatchColor(modal, 1);
data.color2 = BDFDB.getSwatchColor(modal, 2); data.color2 = BDFDB.getSwatchColor(modal, 2);
@ -437,10 +415,7 @@ class EditUsers {
let changed = false; let changed = false;
if (Object.keys(data).every(key => data[key] == null || data[key] == false) && (changed = true)) BDFDB.removeData(info.id, this, "users"); if (Object.keys(data).every(key => data[key] == null || data[key] == false) && (changed = true)) BDFDB.removeData(info.id, this, "users");
else if (!BDFDB.equals(olddata, data) && (changed = true)) BDFDB.saveData(info.id, data, this, "users"); else if (!BDFDB.equals(olddata, data) && (changed = true)) BDFDB.saveData(info.id, data, this, "users");
if (changed) { if (changed) this.forceUpdateAll();
this.changeAppTitle();
BDFDB.WebModules.forceAllUpdates(this);
}
} }
}] }]
}); });
@ -755,11 +730,34 @@ class EditUsers {
processStandardSidebarView (instance, wrapper, returnvalue) { processStandardSidebarView (instance, wrapper, returnvalue) {
if (this.SettingsUpdated) { if (this.SettingsUpdated) {
delete this.SettingsUpdated; delete this.SettingsUpdated;
this.changeAppTitle(); this.forceUpdateAll();
BDFDB.WebModules.forceAllUpdates(this);
} }
} }
checkUrl (url, instance) {
let input = BDFDB.React.findDOMNode(instance).firstElementChild;
clearTimeout(instance.checkTimeout);
if (url == null || !url.trim()) {
if (input) BDFDB.removeEles(input.tooltip);
instance.props.inputClassName = null;
instance.forceUpdate();
}
else instance.checkTimeout = setTimeout(() => {
BDFDB.LibraryRequires.request(url.trim(), (error, response, result) => {
if (response && response.headers["content-type"] && response.headers["content-type"].indexOf("image") != -1) {
if (input) BDFDB.removeEles(input.tooltip);
instance.props.inputClassName = BDFDB.disCN.inputsuccess;
}
else {
this.createNoticeTooltip(input, true);
instance.props.inputClassName = BDFDB.disCN.inputerror;
}
delete instance.checkTimeout;
instance.forceUpdate();
});
}, 1000);
}
createNoticeTooltip (input, isinvalid = false) { createNoticeTooltip (input, isinvalid = false) {
if (!input) return; if (!input) return;
BDFDB.removeEles(input.tooltip); BDFDB.removeEles(input.tooltip);