From 4af765c16a0951651c87b825daf749ae31547a77 Mon Sep 17 00:00:00 2001 From: MathMan05 Date: Thu, 10 Apr 2025 14:38:03 -0500 Subject: [PATCH] add rules channel and move settings arround --- src/webpage/channel.ts | 15 +++++++- src/webpage/direct.ts | 1 + src/webpage/guild.ts | 73 ++++++++++++++++++++++++++++--------- src/webpage/icons/rules.svg | 1 + src/webpage/settings.ts | 39 +++++++++++++------- src/webpage/style.css | 4 ++ translations/en.json | 2 + 7 files changed, 101 insertions(+), 34 deletions(-) create mode 100644 src/webpage/icons/rules.svg diff --git a/src/webpage/channel.ts b/src/webpage/channel.ts index 1ec188a..add643e 100644 --- a/src/webpage/channel.ts +++ b/src/webpage/channel.ts @@ -656,7 +656,15 @@ class Channel extends SnowFlake { if (this.type === 0) { const decoration = document.createElement("span"); button.appendChild(decoration); - decoration.classList.add("space", "svgicon", this.nsfw ? "svg-channelnsfw" : "svg-channel"); + if (this.guild.properties.rules_channel_id === this.id) { + decoration.classList.add("space", "svgicon", "svg-rules"); + } else { + decoration.classList.add( + "space", + "svgicon", + this.nsfw ? "svg-channelnsfw" : "svg-channel", + ); + } } else if (this.type === 2) { // const decoration = document.createElement("span"); @@ -1038,7 +1046,10 @@ class Channel extends SnowFlake { d.options.addHTMLArea(new MarkDown(this.topic, this).makeHTML()); d.show(); }; - } else channelTopic.setAttribute("hidden", ""); + } else { + channelTopic.setAttribute("hidden", ""); + channelTopic.onclick = () => {}; + } if (this.guild !== this.localuser.lookingguild) { this.guild.loadGuild(); } diff --git a/src/webpage/direct.ts b/src/webpage/direct.ts index 9231c0d..f9fb95a 100644 --- a/src/webpage/direct.ts +++ b/src/webpage/direct.ts @@ -85,6 +85,7 @@ class Direct extends Guild { const channelTopic = document.getElementById("channelTopic") as HTMLSpanElement; channelTopic.removeAttribute("hidden"); channelTopic.textContent = ""; + channelTopic.onclick = () => {}; const loading = document.getElementById("loadingdiv") as HTMLDivElement; loading.classList.remove("loading"); diff --git a/src/webpage/guild.ts b/src/webpage/guild.ts index e9f5eea..63c4775 100644 --- a/src/webpage/guild.ts +++ b/src/webpage/guild.ts @@ -150,36 +150,21 @@ class Guild extends SnowFlake { form.addTextInput(I18n.getTranslation("guild.name:"), "name", { initText: this.properties.name, }); - form.addMDInput(I18n.getTranslation("guild.description:"), "description", { - initText: this.properties.description, - }); form.addFileInput(I18n.getTranslation("guild.banner:"), "banner", {clear: true}); form.addFileInput(I18n.getTranslation("guild.icon:"), "icon", {clear: true}); form.addHR(); - const sysmap = [null, ...textChannels.map((e) => e.id)]; - form.addSelect( - I18n.getTranslation("guild.systemSelect:"), - "system_channel_id", - ["No system messages", ...textChannels.map((e) => e.name)], - {defaultIndex: sysmap.indexOf(this.properties.system_channel_id)}, - sysmap, - ); console.log(textChannels, this.channels); - const options: ["DISCOVERABLE", "COMMUNITY", "INVITES_DISABLED"] = [ - "DISCOVERABLE", - "COMMUNITY", - "INVITES_DISABLED", - ]; + const options = ["DISCOVERABLE", "COMMUNITY", "INVITES_DISABLED"] as const; const defaultIndex = options.findIndex((_) => this.properties.features.includes(_)); form.addSelect( I18n.guild.howJoin(), "features", options.map((_) => I18n.guild[_]()), { - defaultIndex: defaultIndex == -1 ? 1 : defaultIndex, + defaultIndex: defaultIndex == -1 ? 2 : defaultIndex, }, options, ); @@ -211,8 +196,16 @@ class Guild extends SnowFlake { console.log([...temp]); //@ts-ignore temp = temp.filter((_) => !options.includes(_)); - console.log(temp, options); temp.push(e.features); + if (e.features === "DISCOVERABLE") { + temp.push("COMMUNITY"); + } + if (temp.includes("COMMUNITY")) { + if (!com) { + this.addCommunity(settings, textChannels); + com = true; + } + } e.features = temp; }); @@ -348,8 +341,52 @@ class Guild extends SnowFlake { })(); const webhooks = settings.addButton(I18n.webhooks.base()); webhookMenu(this, this.info.api + `/guilds/${this.id}/webhooks`, webhooks); + console.log(this.properties.features, this.properties.features.includes("COMMUNITY")); + let com = false; + if (this.properties.features.includes("COMMUNITY")) { + this.addCommunity(settings, textChannels); + com = true; + } settings.show(); } + addCommunity(settings: Settings, textChannels: Channel[]) { + const com = settings.addButton(I18n.guild.community()).addForm("", () => {}, { + fetchURL: this.info.api + "/guilds/" + this.id, + method: "PATCH", + headers: this.headers, + traditionalSubmit: true, + }); + { + com.addMDInput(I18n.getTranslation("guild.description:"), "description", { + initText: this.properties.description, + }); + } + { + let defaultIndex = textChannels.findIndex((_) => this.properties.rules_channel_id == _.id); + if (defaultIndex === -1) { + defaultIndex = textChannels.length; + } + com.addSelect( + I18n.guild.ruleId(), + "rules_channel_id", + [...textChannels.map((_) => _.name), "none"], + { + defaultIndex, + }, + [...textChannels.map((_) => _.id), undefined], + ); + } + { + const sysmap = [null, ...textChannels.map((e) => e.id)]; + com.addSelect( + I18n.getTranslation("guild.systemSelect:"), + "system_channel_id", + ["No system messages", ...textChannels.map((e) => e.name)], + {defaultIndex: sysmap.indexOf(this.properties.system_channel_id)}, + sysmap, + ); + } + } makeInviteMenu(options: Options, valid: void | Channel[]) { if (!valid) { valid = this.channels.filter((e) => { diff --git a/src/webpage/icons/rules.svg b/src/webpage/icons/rules.svg new file mode 100644 index 0000000..3af5d73 --- /dev/null +++ b/src/webpage/icons/rules.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/webpage/settings.ts b/src/webpage/settings.ts index af4db84..42d3cc8 100644 --- a/src/webpage/settings.ts +++ b/src/webpage/settings.ts @@ -24,9 +24,15 @@ export class Buttons implements OptionsElement { if (!thing) { thing = new Options(name, this); } - this.buttons.push([name, thing]); + const button = [name, thing] as [string, string | Options]; + this.buttons.push(button); + const htmlarea = this.htmlarea.deref(); + const buttonTable = this.buttonTable.deref(); + if (buttonTable && htmlarea) buttonTable.append(this.makeButtonHTML(button, htmlarea)); return thing; } + htmlarea = new WeakRef(document.createElement("div")); + buttonTable = new WeakRef(document.createElement("div")); generateHTML() { const buttonList = document.createElement("div"); buttonList.classList.add("Buttons"); @@ -40,8 +46,22 @@ export class Buttons implements OptionsElement { } buttonList.append(buttonTable); buttonList.append(htmlarea); + this.htmlarea = new WeakRef(htmlarea); + this.buttonTable = new WeakRef(buttonTable); return buttonList; } + makeButtonHTML(buttond: [string, string | Options], optionsArea: HTMLElement) { + const button = document.createElement("button"); + button.classList.add("SettingsButton"); + button.textContent = buttond[0]; + button.onclick = (_) => { + this.generateHTMLArea(buttond[1], optionsArea); + if (this.warndiv) { + this.warndiv.remove(); + } + }; + return button; + } generateButtons(optionsArea: HTMLElement) { const buttonTable = document.createElement("div"); buttonTable.classList.add("settingbuttons"); @@ -49,16 +69,7 @@ export class Buttons implements OptionsElement { buttonTable.classList.add("flexltr"); } for (const thing of this.buttons) { - const button = document.createElement("button"); - button.classList.add("SettingsButton"); - button.textContent = thing[0]; - button.onclick = (_) => { - this.generateHTMLArea(thing[1], optionsArea); - if (this.warndiv) { - this.warndiv.remove(); - } - }; - buttonTable.append(button); + buttonTable.append(this.makeButtonHTML(thing, optionsArea)); } return buttonTable; } @@ -1082,13 +1093,13 @@ class Form implements OptionsElement { (this.button.deref() as HTMLElement).hidden = false; } } - selectMap = new WeakMap(); + selectMap = new WeakMap(); addSelect( label: string, formName: string, selections: string[], {defaultIndex = 0, required = false, radio = false} = {}, - correct: (string | number | null)[] = selections, + correct: readonly (string | number | null | undefined)[] = selections, ) { const select = this.options.addSelect(label, (_) => {}, selections, { defaultIndex, @@ -1219,7 +1230,7 @@ class Form implements OptionsElement { addPreprocessor(func: (obj: Object) => void) { this.preprocessor = func; } - onFormError = (f: FormError) => {}; + onFormError = (_: FormError) => {}; async submit() { if (this.options.subOptions) { this.options.subOptions.submit(); diff --git a/src/webpage/style.css b/src/webpage/style.css index 95e80f9..2c6abc3 100644 --- a/src/webpage/style.css +++ b/src/webpage/style.css @@ -404,6 +404,10 @@ textarea { mask: url(/icons/pin.svg); mask-size: cover; } +.svg-rules { + mask: url(/icons/rules.svg); + mask-size: cover; +} .svg-unspoiler { mask: url(/icons/unspoiler.svg); } diff --git a/translations/en.json b/translations/en.json index bfdc3cf..95db398 100644 --- a/translations/en.json +++ b/translations/en.json @@ -245,6 +245,8 @@ "nevermind": "Nevermind", "submit": "submit", "guild": { + "ruleId": "Rules Channel:", + "community": "Community", "creating": "Creating guild", "copyId": "Copy guild id", "markRead": "Mark as read",