feat(Decor): Enforce guidelines more (#2035)

This commit is contained in:
nexpid 2024-01-03 13:49:03 +01:00 committed by GitHub
parent a963a19bdc
commit 1eb2510353
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 242 additions and 139 deletions

View file

@ -6,21 +6,17 @@
import "./ui/styles.css"; import "./ui/styles.css";
import { definePluginSettings } from "@api/Settings";
import ErrorBoundary from "@components/ErrorBoundary"; import ErrorBoundary from "@components/ErrorBoundary";
import { Link } from "@components/Link";
import { Devs } from "@utils/constants"; import { Devs } from "@utils/constants";
import { Margins } from "@utils/margins"; import definePlugin from "@utils/types";
import { classes } from "@utils/misc";
import { closeAllModals } from "@utils/modal";
import definePlugin, { OptionType } from "@utils/types";
import { findByPropsLazy } from "@webpack"; import { findByPropsLazy } from "@webpack";
import { FluxDispatcher, Forms, UserStore } from "@webpack/common"; import { UserStore } from "@webpack/common";
import { CDN_URL, RAW_SKU_ID, SKU_ID } from "./lib/constants"; import { CDN_URL, RAW_SKU_ID, SKU_ID } from "./lib/constants";
import { useAuthorizationStore } from "./lib/stores/AuthorizationStore"; import { useAuthorizationStore } from "./lib/stores/AuthorizationStore";
import { useCurrentUserDecorationsStore } from "./lib/stores/CurrentUserDecorationsStore"; import { useCurrentUserDecorationsStore } from "./lib/stores/CurrentUserDecorationsStore";
import { useUserDecorAvatarDecoration, useUsersDecorationsStore } from "./lib/stores/UsersDecorationsStore"; import { useUserDecorAvatarDecoration, useUsersDecorationsStore } from "./lib/stores/UsersDecorationsStore";
import { settings } from "./settings";
import { setDecorationGridDecoration, setDecorationGridItem } from "./ui/components"; import { setDecorationGridDecoration, setDecorationGridItem } from "./ui/components";
import DecorSection from "./ui/components/DecorSection"; import DecorSection from "./ui/components/DecorSection";
@ -30,27 +26,6 @@ export interface AvatarDecoration {
skuId: string; skuId: string;
} }
const settings = definePluginSettings({
changeDecoration: {
type: OptionType.COMPONENT,
description: "Change your avatar decoration",
component() {
return <div>
<DecorSection hideTitle hideDivider noMargin />
<Forms.FormText type="description" className={classes(Margins.top8, Margins.bottom8)}>
You can also access Decor decorations from the <Link
href="/settings/profile-customization"
onClick={e => {
e.preventDefault();
closeAllModals();
FluxDispatcher.dispatch({ type: "USER_SETTINGS_MODAL_SET_SECTION", section: "Profile Customization" });
}}
>Profiles</Link> page.
</Forms.FormText>
</div>;
}
}
});
export default definePlugin({ export default definePlugin({
name: "Decor", name: "Decor",
description: "Create and use your own custom avatar decorations, or pick your favorite from the presets.", description: "Create and use your own custom avatar decorations, or pick your favorite from the presets.",

View file

@ -0,0 +1,47 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2023 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { definePluginSettings } from "@api/Settings";
import { Link } from "@components/Link";
import { Margins } from "@utils/margins";
import { classes } from "@utils/misc";
import { closeAllModals } from "@utils/modal";
import { OptionType } from "@utils/types";
import { FluxDispatcher, Forms } from "@webpack/common";
import DecorSection from "./ui/components/DecorSection";
export const settings = definePluginSettings({
changeDecoration: {
type: OptionType.COMPONENT,
description: "Change your avatar decoration",
component() {
if (!Vencord.Plugins.plugins.Decor.started) return <Forms.FormText>
Enable Decor and restart your client to change your avatar decoration.
</Forms.FormText>;
return <div>
<DecorSection hideTitle hideDivider noMargin />
<Forms.FormText type="description" className={classes(Margins.top8, Margins.bottom8)}>
You can also access Decor decorations from the <Link
href="/settings/profile-customization"
onClick={e => {
e.preventDefault();
closeAllModals();
FluxDispatcher.dispatch({ type: "USER_SETTINGS_MODAL_SET_SECTION", section: "Profile Customization" });
}}
>Profiles</Link> page.
</Forms.FormText>
</div>;
}
},
agreedToGuidelines: {
type: OptionType.BOOLEAN,
description: "Agreed to guidelines",
hidden: true,
default: false
}
});

View file

@ -4,11 +4,12 @@
* SPDX-License-Identifier: GPL-3.0-or-later * SPDX-License-Identifier: GPL-3.0-or-later
*/ */
import ErrorBoundary from "@components/ErrorBoundary";
import { Flex } from "@components/Flex"; import { Flex } from "@components/Flex";
import { openInviteModal } from "@utils/discord"; import { openInviteModal } from "@utils/discord";
import { Margins } from "@utils/margins"; import { Margins } from "@utils/margins";
import { classes } from "@utils/misc"; import { classes } from "@utils/misc";
import { closeAllModals, ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalRoot, ModalSize, openModal } from "@utils/modal"; import { closeAllModals, ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalProps, ModalRoot, ModalSize, openModal } from "@utils/modal";
import { findByPropsLazy, findComponentByCodeLazy } from "@webpack"; import { findByPropsLazy, findComponentByCodeLazy } from "@webpack";
import { Alerts, Button, FluxDispatcher, Forms, GuildStore, NavigationRouter, Parser, Text, Tooltip, useEffect, UserStore, UserUtils, useState } from "@webpack/common"; import { Alerts, Button, FluxDispatcher, Forms, GuildStore, NavigationRouter, Parser, Text, Tooltip, useEffect, UserStore, UserUtils, useState } from "@webpack/common";
import { User } from "discord-types/general"; import { User } from "discord-types/general";
@ -18,6 +19,7 @@ import { GUILD_ID, INVITE_KEY } from "../../lib/constants";
import { useAuthorizationStore } from "../../lib/stores/AuthorizationStore"; import { useAuthorizationStore } from "../../lib/stores/AuthorizationStore";
import { useCurrentUserDecorationsStore } from "../../lib/stores/CurrentUserDecorationsStore"; import { useCurrentUserDecorationsStore } from "../../lib/stores/CurrentUserDecorationsStore";
import { decorationToAvatarDecoration } from "../../lib/utils/decoration"; import { decorationToAvatarDecoration } from "../../lib/utils/decoration";
import { settings } from "../../settings";
import { cl, requireAvatarDecorationModal } from "../"; import { cl, requireAvatarDecorationModal } from "../";
import { AvatarDecorationModalPreview } from "../components"; import { AvatarDecorationModalPreview } from "../components";
import DecorationGridCreate from "../components/DecorationGridCreate"; import DecorationGridCreate from "../components/DecorationGridCreate";
@ -25,6 +27,7 @@ import DecorationGridNone from "../components/DecorationGridNone";
import DecorDecorationGridDecoration from "../components/DecorDecorationGridDecoration"; import DecorDecorationGridDecoration from "../components/DecorDecorationGridDecoration";
import SectionedGridList from "../components/SectionedGridList"; import SectionedGridList from "../components/SectionedGridList";
import { openCreateDecorationModal } from "./CreateDecorationModal"; import { openCreateDecorationModal } from "./CreateDecorationModal";
import { openGuidelinesModal } from "./GuidelinesModal";
const UserSummaryItem = findComponentByCodeLazy("defaultRenderUser", "showDefaultAvatarsForNullUsers"); const UserSummaryItem = findComponentByCodeLazy("defaultRenderUser", "showDefaultAvatarsForNullUsers");
const DecorationModalStyles = findByPropsLazy("modalFooterShopButton"); const DecorationModalStyles = findByPropsLazy("modalFooterShopButton");
@ -83,7 +86,7 @@ function SectionHeader({ section }: { section: Section; }) {
</div>; </div>;
} }
export default function ChangeDecorationModal(props: any) { function ChangeDecorationModal(props: ModalProps) {
// undefined = not trying, null = none, Decoration = selected // undefined = not trying, null = none, Decoration = selected
const [tryingDecoration, setTryingDecoration] = useState<Decoration | null | undefined>(undefined); const [tryingDecoration, setTryingDecoration] = useState<Decoration | null | undefined>(undefined);
const isTryingDecoration = typeof tryingDecoration !== "undefined"; const isTryingDecoration = typeof tryingDecoration !== "undefined";
@ -116,6 +119,7 @@ export default function ChangeDecorationModal(props: any) {
const data = [ const data = [
{ {
title: "Your Decorations", title: "Your Decorations",
subtitle: "You can delete your own decorations by right clicking on them.",
sectionKey: "ownDecorations", sectionKey: "ownDecorations",
items: ["none", ...ownDecorations, "create"] items: ["none", ...ownDecorations, "create"]
}, },
@ -148,6 +152,7 @@ export default function ChangeDecorationModal(props: any) {
className={cl("change-decoration-modal-content")} className={cl("change-decoration-modal-content")}
scrollbarType="none" scrollbarType="none"
> >
<ErrorBoundary>
<SectionedGridList <SectionedGridList
renderItem={item => { renderItem={item => {
if (typeof item === "string") { if (typeof item === "string") {
@ -163,7 +168,7 @@ export default function ChangeDecorationModal(props: any) {
{tooltipProps => <DecorationGridCreate {tooltipProps => <DecorationGridCreate
className={cl("change-decoration-modal-decoration")} className={cl("change-decoration-modal-decoration")}
{...tooltipProps} {...tooltipProps}
onSelect={!hasDecorationPendingReview ? openCreateDecorationModal : () => { }} onSelect={!hasDecorationPendingReview ? (settings.store.agreedToGuidelines ? openCreateDecorationModal : openGuidelinesModal) : () => { }}
/>} />}
</Tooltip>; </Tooltip>;
} }
@ -202,6 +207,7 @@ export default function ChangeDecorationModal(props: any) {
} }
{activeDecorationHasAuthor && <Text key={`createdBy-${activeSelectedDecoration.authorId}`}>Created by {Parser.parse(`<@${activeSelectedDecoration.authorId}>`)}</Text>} {activeDecorationHasAuthor && <Text key={`createdBy-${activeSelectedDecoration.authorId}`}>Created by {Parser.parse(`<@${activeSelectedDecoration.authorId}>`)}</Text>}
</div> </div>
</ErrorBoundary>
</ModalContent> </ModalContent>
<ModalFooter className={classes(cl("change-decoration-modal-footer", cl("modal-footer")))}> <ModalFooter className={classes(cl("change-decoration-modal-footer", cl("modal-footer")))}>
<div className={cl("change-decoration-modal-footer-btn-container")}> <div className={cl("change-decoration-modal-footer-btn-container")}>

View file

@ -4,10 +4,11 @@
* SPDX-License-Identifier: GPL-3.0-or-later * SPDX-License-Identifier: GPL-3.0-or-later
*/ */
import ErrorBoundary from "@components/ErrorBoundary";
import { Link } from "@components/Link"; import { Link } from "@components/Link";
import { openInviteModal } from "@utils/discord"; import { openInviteModal } from "@utils/discord";
import { Margins } from "@utils/margins"; import { Margins } from "@utils/margins";
import { closeAllModals, ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalRoot, ModalSize, openModal } from "@utils/modal"; import { closeAllModals, ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalProps, ModalRoot, ModalSize, openModal } from "@utils/modal";
import { findByPropsLazy, findComponentByCodeLazy } from "@webpack"; import { findByPropsLazy, findComponentByCodeLazy } from "@webpack";
import { Button, FluxDispatcher, Forms, GuildStore, NavigationRouter, Text, TextInput, useEffect, useMemo, UserStore, useState } from "@webpack/common"; import { Button, FluxDispatcher, Forms, GuildStore, NavigationRouter, Text, TextInput, useEffect, useMemo, UserStore, useState } from "@webpack/common";
@ -21,6 +22,8 @@ const DecorationModalStyles = findByPropsLazy("modalFooterShopButton");
const FileUpload = findComponentByCodeLazy("fileUploadInput,"); const FileUpload = findComponentByCodeLazy("fileUploadInput,");
const { default: HelpMessage, HelpMessageTypes } = findByPropsLazy("HelpMessageTypes");
function useObjectURL(object: Blob | MediaSource | null) { function useObjectURL(object: Blob | MediaSource | null) {
const [url, setUrl] = useState<string | null>(null); const [url, setUrl] = useState<string | null>(null);
@ -39,7 +42,7 @@ function useObjectURL(object: Blob | MediaSource | null) {
return url; return url;
} }
export default function CreateDecorationModal(props) { function CreateDecorationModal(props: ModalProps) {
const [name, setName] = useState(""); const [name, setName] = useState("");
const [file, setFile] = useState<File | null>(null); const [file, setFile] = useState<File | null>(null);
const [submitting, setSubmitting] = useState(false); const [submitting, setSubmitting] = useState(false);
@ -75,6 +78,14 @@ export default function CreateDecorationModal(props) {
className={cl("create-decoration-modal-content")} className={cl("create-decoration-modal-content")}
scrollbarType="none" scrollbarType="none"
> >
<ErrorBoundary>
<HelpMessage messageType={HelpMessageTypes.WARNING}>
Make sure your decoration does not violate <Link
href="https://github.com/decor-discord/.github/blob/main/GUIDELINES.md"
>
the guidelines
</Link> before submitting it.
</HelpMessage>
<div className={cl("create-decoration-modal-form-preview-container")}> <div className={cl("create-decoration-modal-form-preview-container")}>
<div className={cl("create-decoration-modal-form")}> <div className={cl("create-decoration-modal-form")}>
{error !== null && <Text color="text-danger" variant="text-xs/normal">{error.message}</Text>} {error !== null && <Text color="text-danger" variant="text-xs/normal">{error.message}</Text>}
@ -109,11 +120,6 @@ export default function CreateDecorationModal(props) {
</div> </div>
</div> </div>
<Forms.FormText type="description" className={Margins.bottom16}> <Forms.FormText type="description" className={Margins.bottom16}>
Make sure your decoration does not violate <Link
href="https://github.com/decor-discord/.github/blob/main/GUIDELINES.md"
>
the guidelines
</Link> before creating your decoration.
<br />You can receive updates on your decoration's review by joining <Link <br />You can receive updates on your decoration's review by joining <Link
href={`https://discord.gg/${INVITE_KEY}`} href={`https://discord.gg/${INVITE_KEY}`}
onClick={async e => { onClick={async e => {
@ -134,6 +140,7 @@ export default function CreateDecorationModal(props) {
Decor's Discord server Decor's Discord server
</Link>. </Link>.
</Forms.FormText> </Forms.FormText>
</ErrorBoundary>
</ModalContent> </ModalContent>
<ModalFooter className={cl("modal-footer")}> <ModalFooter className={cl("modal-footer")}>
<Button <Button
@ -145,7 +152,7 @@ export default function CreateDecorationModal(props) {
disabled={!file || !name} disabled={!file || !name}
submitting={submitting} submitting={submitting}
> >
Create Submit for Review
</Button> </Button>
<Button <Button
onClick={props.onClose} onClick={props.onClose}

View file

@ -0,0 +1,68 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2023 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { Link } from "@components/Link";
import { ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalProps, ModalRoot, ModalSize, openModal } from "@utils/modal";
import { findByPropsLazy } from "@webpack";
import { Button, Forms, Text } from "@webpack/common";
import { settings } from "../../settings";
import { cl, requireAvatarDecorationModal } from "../";
import { openCreateDecorationModal } from "./CreateDecorationModal";
const DecorationModalStyles = findByPropsLazy("modalFooterShopButton");
function GuidelinesModal(props: ModalProps) {
return <ModalRoot
{...props}
size={ModalSize.SMALL}
className={DecorationModalStyles.modal}
>
<ModalHeader separator={false} className={cl("modal-header")}>
<Text
color="header-primary"
variant="heading-lg/semibold"
tag="h1"
style={{ flexGrow: 1 }}
>
Hold on
</Text>
<ModalCloseButton onClick={props.onClose} />
</ModalHeader>
<ModalContent
scrollbarType="none"
>
<Forms.FormText>
By submitting a decoration, you agree to <Link
href="https://github.com/decor-discord/.github/blob/main/GUIDELINES.md"
>
the guidelines
</Link>. Not reading these guidelines may get your account suspended from creating more decorations in the future.
</Forms.FormText>
</ModalContent>
<ModalFooter className={cl("modal-footer")}>
<Button
onClick={() => {
settings.store.agreedToGuidelines = true;
props.onClose();
openCreateDecorationModal();
}}
>
Continue
</Button>
<Button
onClick={props.onClose}
color={Button.Colors.PRIMARY}
look={Button.Looks.LINK}
>
Go Back
</Button>
</ModalFooter>
</ModalRoot>;
}
export const openGuidelinesModal = () =>
requireAvatarDecorationModal().then(() => openModal(props => <GuidelinesModal {...props} />));

View file

@ -8,7 +8,7 @@
display: flex; display: flex;
border-radius: 5px 5px 0 0; border-radius: 5px 5px 0 0;
padding: 0 16px; padding: 0 16px;
gap: 4px gap: 4px;
} }
.vc-decor-change-decoration-modal-preview { .vc-decor-change-decoration-modal-preview {
@ -72,7 +72,7 @@
.vc-decor-sectioned-grid-list-grid { .vc-decor-sectioned-grid-list-grid {
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
gap: 8px gap: 8px;
} }
.vc-decor-section-remove-margin { .vc-decor-section-remove-margin {