Equicord/src/equicordplugins/showBadgesInChat/settings.tsx

199 lines
7.8 KiB
TypeScript
Raw Normal View History

2024-04-17 14:29:47 -04:00
/*
* Vencord, a Discord client mod
* Copyright (c) 2024 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { definePluginSettings } from "@api/Settings";
2025-10-11 21:50:14 -04:00
import { BaseText } from "@components/BaseText";
2024-04-17 14:29:47 -04:00
import { OptionType } from "@utils/types";
2025-10-11 21:50:14 -04:00
import { useEffect, UserStore, useState } from "@webpack/common";
2024-04-17 14:29:47 -04:00
const settings = definePluginSettings({
showEquicordDonor: {
2024-04-17 14:29:47 -04:00
type: OptionType.BOOLEAN,
2024-04-18 19:54:51 -04:00
description: "Enable to show Equicord Donor badges in chat.",
2024-04-17 14:29:47 -04:00
hidden: true,
default: true
},
EquicordDonorPosition: {
2024-04-17 14:29:47 -04:00
type: OptionType.NUMBER,
2024-04-18 19:54:51 -04:00
description: "The position of the Equicord Donor badges.",
2024-04-17 14:29:47 -04:00
hidden: true,
2024-04-18 19:31:33 -04:00
default: 0
2024-04-17 14:29:47 -04:00
},
2024-04-18 19:53:52 -04:00
showEquicordContributor: {
type: OptionType.BOOLEAN,
description: "Enable to show Equicord Contributor badges in chat.",
2024-04-18 19:53:52 -04:00
hidden: true,
default: true
},
EquicordContributorPosition: {
type: OptionType.NUMBER,
description: "The position of the Equicord Contributor badge.",
hidden: true,
default: 1
},
showVencordDonor: {
2024-04-18 19:15:01 -04:00
type: OptionType.BOOLEAN,
2024-06-01 14:32:22 -04:00
description: "Enable to show Vencord donor badges in chat.",
2024-04-18 19:15:01 -04:00
hidden: true,
default: true
},
VencordDonorPosition: {
2024-04-18 19:15:01 -04:00
type: OptionType.NUMBER,
description: "The position of the Vencord Donor badges.",
hidden: true,
default: 4
2024-04-18 19:15:01 -04:00
},
2024-04-17 14:29:47 -04:00
showVencordContributor: {
type: OptionType.BOOLEAN,
description: "Enable to show Vencord contributor badges in chat.",
2024-04-17 14:29:47 -04:00
hidden: true,
default: true
},
VencordContributorPosition: {
type: OptionType.NUMBER,
description: "The position of the Vencord Contributor badge.",
hidden: true,
default: 5
2024-04-17 14:29:47 -04:00
},
showDiscordProfile: {
type: OptionType.BOOLEAN,
description: "Enable to show Discord profile badges in chat.",
hidden: true,
default: true
},
DiscordProfilePosition: {
type: OptionType.NUMBER,
description: "The position of the Discord profile badges.",
hidden: true,
default: 6
2024-04-17 14:29:47 -04:00
},
showDiscordNitro: {
type: OptionType.BOOLEAN,
description: "Enable to show Discord Nitro badges in chat.",
hidden: true,
default: true
},
DiscordNitroPosition: {
type: OptionType.NUMBER,
description: "The position of the Discord Nitro badge.",
hidden: true,
default: 7
2024-04-17 14:29:47 -04:00
},
badgeSettings: {
type: OptionType.COMPONENT,
description: "Setup badge layout and visibility",
component: () => <BadgeSettings />
}
});
export default settings;
const BadgeSettings = () => {
const [images, setImages] = useState([
2026-01-08 14:12:43 -05:00
{ src: "https://badge.equicord.org/donor.webp", shown: settings.store.showEquicordDonor, title: "Equicord donor badges", key: "EquicordDonor", position: settings.store.EquicordDonorPosition },
2025-10-02 18:56:23 -04:00
{ src: "https://equicord.org/assets/favicon.png", shown: settings.store.showEquicordContributor, title: "Equicord contributor badge", key: "EquicordContributer", position: settings.store.EquicordContributorPosition },
{ src: "https://cdn.discordapp.com/emojis/1026533070955872337.png", shown: settings.store.showVencordDonor, title: "Vencord donor badges", key: "VencordDonor", position: settings.store.VencordDonorPosition },
{ src: "https://cdn.discordapp.com/emojis/1092089799109775453.png", shown: settings.store.showVencordContributor, title: "Vencord contributor badge", key: "VencordContributer", position: settings.store.VencordContributorPosition },
{ src: "https://cdn.discordapp.com/badge-icons/bf01d1073931f921909045f3a39fd264.png", shown: settings.store.showDiscordProfile, title: "Discord profile badges (HypeSquad, Discord Staff, Early Supporter, etc.)", key: "DiscordProfile", position: settings.store.DiscordProfilePosition },
2024-04-17 14:29:47 -04:00
{ src: "https://cdn.discordapp.com/badge-icons/2ba85e8026a8614b640c2837bcdfe21b.png", shown: settings.store.showDiscordNitro, title: "Nitro badge", key: "DiscordNitro", position: settings.store.DiscordNitroPosition }
]);
useEffect(() => {
images.forEach(image => {
switch (image.key) {
2024-04-18 21:28:20 -04:00
case "EquicordDonor":
2024-04-18 19:15:01 -04:00
settings.store.EquicordDonorPosition = image.position;
settings.store.showEquicordDonor = image.shown;
break;
2024-04-18 21:28:20 -04:00
case "EquicordContributer":
2024-04-18 19:53:52 -04:00
settings.store.EquicordContributorPosition = image.position;
settings.store.showEquicordContributor = image.shown;
break;
case "VencordDonor":
settings.store.VencordDonorPosition = image.position;
settings.store.showVencordDonor = image.shown;
break;
2024-04-17 14:29:47 -04:00
case "VencordContributer":
settings.store.VencordContributorPosition = image.position;
settings.store.showVencordContributor = image.shown;
break;
case "DiscordProfile":
settings.store.DiscordProfilePosition = image.position;
settings.store.showDiscordProfile = image.shown;
break;
case "DiscordNitro":
settings.store.DiscordNitroPosition = image.position;
settings.store.showDiscordNitro = image.shown;
break;
default:
break;
}
});
}, [images]);
const handleDragStart = (e: any, index: number) => {
if (!images[index].shown) {
e.preventDefault();
} else {
e.dataTransfer.setData("index", index);
}
};
const handleDragOver = e => {
e.preventDefault();
};
const handleDrop = (e: any, dropIndex: number) => {
const dragIndex = e.dataTransfer.getData("index");
const newImages = [...images];
const draggedImage = newImages[dragIndex];
newImages.splice(dragIndex, 1);
newImages.splice(dropIndex, 0, draggedImage);
newImages.forEach((image, index) => {
image.position = index;
});
setImages(newImages);
};
const toggleDisable = (index: number) => {
const newImages = [...images];
newImages[index].shown = !newImages[index].shown;
setImages(newImages);
};
return (
<>
2025-10-11 21:50:14 -04:00
<BaseText>Drag the badges to reorder them, you can click to enable/disable a specific badge type.</BaseText>
2024-06-01 14:32:22 -04:00
<div className="vc-sbic-badge-settings">
<img className="vc-sbic-settings-avatar" src={UserStore.getCurrentUser().getAvatarURL()}></img>
2025-10-11 21:50:14 -04:00
<BaseText className="vc-sbic-settings-username">{(UserStore.getCurrentUser() as any).globalName}</BaseText>
2024-04-17 14:29:47 -04:00
{images
.sort((a, b) => a.position - b.position)
.map((image, index) => (
<div
key={image.key}
2024-06-01 14:32:22 -04:00
className={`vc-sbic-image-container ${!image.shown ? "vc-sbic-disabled" : ""}`}
2024-04-17 14:29:47 -04:00
onDragOver={e => handleDragOver(e)}
onDrop={e => handleDrop(e, index)}
onClick={() => toggleDisable(index)}
>
<img
src={image.src}
draggable={image.shown}
onDragStart={e => handleDragStart(e, index)}
title={image.title}
/>
</div>
))
}
</div>
</>
);
};