Fixed issues and added reset button

This commit is contained in:
Inbestigator 2024-06-09 13:47:32 -07:00
parent 3dc2eb65a1
commit 88689b304a
3 changed files with 53 additions and 43 deletions

View file

@ -1,8 +1 @@
### Create custom reasons to use in the Discord ban modal. ### Create custom reasons to use in the Discord ban modal.
![image](https://github.com/Vendicated/Vencord/assets/119569726/d0c1bd70-00b1-4786-a2f7-7db809f15ab0)
![image](https://github.com/Vendicated/Vencord/assets/119569726/411411f6-f2b7-4747-b6e7-4615116dcf22)
I do not think that we're **easily** and **non-jankily** able to add the click functionality, so I didn't implement that. If anybody gets it working, shoot me a message on Discord.
[Original plugin request](https://github.com/Vencord/plugin-requests/issues/607)

View file

@ -4,59 +4,69 @@
* SPDX-License-Identifier: GPL-3.0-or-later * SPDX-License-Identifier: GPL-3.0-or-later
*/ */
import "./styles.css";
import { definePluginSettings } from "@api/Settings"; import { definePluginSettings } from "@api/Settings";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types"; import definePlugin, { OptionType } from "@utils/types";
import { Button, Forms, TextInput, useEffect, useState } from "@webpack/common"; import { Button, Forms, TextInput } from "@webpack/common";
const defaultReasons = [
"Suspicious or spam account",
"Compromised or spam account",
"Breaking server rules",
];
function ReasonsComponent() { function ReasonsComponent() {
const { reasons } = settings.use(["reasons"]); const { reasons } = settings.use(["reasons"]);
return ( return (
<Forms.FormSection title="Reasons"> <Forms.FormSection title="Reasons">
{reasons.map((reason, index) => ( {reasons.map((reason: string, index: number) => (
<div <div
style={{ className="vc-bbr-reason-wrapper"
display: "grid",
padding: 0,
paddingBottom: "0.5rem",
gap: "0.5rem",
gridTemplateColumns: "6fr 1fr",
}}
> >
<TextInput <TextInput
style={{ flex: 1 }}
type="text" type="text"
key={index} key={index}
value={reason} value={reason}
onChange={(value: string) => { onChange={(v: string) => {
reasons[index] = value; reasons[index] = v;
setReasons([...reasons]); settings.store.reasons = [...reasons];
}} }}
placeholder="Reason" placeholder="Reason"
/> />
<Button <Button
color={Button.Colors.RED} color={Button.Colors.RED}
style={{ height: "100%" }} className="vc-bbr-remove-button"
size={Button.Sizes.MIN}
onClick={() => { onClick={() => {
reasons.splice(index, 1); reasons.splice(index, 1);
setReasons([...reasons]); settings.store.reasons = [...reasons];
}} }}
> >
Remove Remove
</Button> </Button>
</div> </div>
))} ))}
<div
className="vc-bbr-reason-wrapper"
>
<Button <Button
size={Button.Sizes.SMALL}
onClick={() => { onClick={() => {
reasons.push(""); reasons.push("");
setReasons([...reasons]); settings.store.reasons = [...reasons];
}} }}
> >
Add new Add new
</Button> </Button>
<Button
color={Button.Colors.TRANSPARENT}
onClick={() => {
settings.store.reasons = defaultReasons;
}}
>
Reset
</Button></div>
</Forms.FormSection> </Forms.FormSection>
); );
} }
@ -65,11 +75,7 @@ const settings = definePluginSettings({
reasons: { reasons: {
description: "Your custom reasons", description: "Your custom reasons",
type: OptionType.COMPONENT, type: OptionType.COMPONENT,
default: [ default: defaultReasons,
"Suspicious or spam account",
"Compromised or spam account",
"Breaking server rules",
],
component: ReasonsComponent, component: ReasonsComponent,
}, },
}); });
@ -80,12 +86,12 @@ export default definePlugin({
authors: [Devs.Inbestigator], authors: [Devs.Inbestigator],
patches: [ patches: [
{ {
find: 'username:"@".concat(_.default.getName', find: "default.Messages.BAN_MULTIPLE_CONFIRM_TITLE",
replacement: { replacement: {
match: /U=\[([\s\S]*?)\]/, match: /=\[([^\\]*?)\]/,
replace: "U=$self.getReasons()", replace: "=$self.getReasons()"
}, }
}, }
], ],
getReasons() { getReasons() {
return settings.store.reasons.map(reason => ( return settings.store.reasons.map(reason => (

View file

@ -0,0 +1,11 @@
.vc-bbr-reason-wrapper {
display: grid;
padding: 0;
padding-bottom: 0.5rem;
gap: 0.5rem;
grid-template-columns: 6fr 1fr;
}
.vc-bbr-remove-button {
height: 100%;
}