/* * Vencord, a Discord client mod * Copyright (c) 2024 Vendicated and contributors * SPDX-License-Identifier: GPL-3.0-or-later */ import { generateId } from "@api/Commands"; import { Settings } from "@api/Settings"; import { OpenExternalIcon } from "@components/Icons"; import { proxyLazy } from "@utils/lazy"; import { Margins } from "@utils/margins"; import { ModalContent, ModalFooter, ModalHeader, ModalRoot, ModalSize, openModal } from "@utils/modal"; import { User } from "@vencord/discord-types"; import { Button, Card, FluxDispatcher, Forms, Parser, React, UserStore, UserUtils } from "@webpack/common"; import { Constructor } from "type-fest"; import type { Theme, ThemeLikeProps } from "../types"; import { LikesComponent } from "./LikesComponent"; import { ThemeInfoModal } from "./ThemeInfoModal"; import { apiUrl } from "./ThemeTab"; interface ThemeCardProps { theme: Theme; themeLinks: string[]; likedThemes?: ThemeLikeProps; setThemeLinks: (links: string[]) => void; removePreview?: boolean; removeButtons?: boolean; } const UserRecord: Constructor> = proxyLazy(() => UserStore.getCurrentUser().constructor) as any; function makeDummyUser(user: { username: string; id?: string; avatar?: string; }) { const newUser = new UserRecord({ username: user.username, id: user.id ?? generateId(), avatar: user.avatar, bot: true, }); FluxDispatcher.dispatch({ type: "USER_UPDATE", user: newUser, }); return newUser; } export const ThemeCard: React.FC = ({ theme, themeLinks, likedThemes, setThemeLinks, removeButtons, removePreview }) => { const getUser = (id: string, username: string) => UserUtils.getUser(id) ?? makeDummyUser({ username, id }); const handleAddRemoveTheme = () => { const onlineThemeLinks = themeLinks.includes(`${apiUrl}/${theme.id}`) ? themeLinks.filter(link => link !== `${apiUrl}/${theme.id}`) : [...themeLinks, `${apiUrl}/${theme.id}`]; setThemeLinks(onlineThemeLinks); Vencord.Settings.themeLinks = onlineThemeLinks; }; const handleThemeAttributesCheck = () => { const requiresThemeAttributes = theme.requiresThemeAttributes ?? false; if (requiresThemeAttributes && !Settings.plugins.ThemeAttributes.enabled) { openModal(modalProps => ( Hold on!

This theme requires the ThemeAttributes plugin to work properly!

Do you want to enable it?

)); } else { handleAddRemoveTheme(); } }; const handleViewSource = () => { const content = window.atob(theme.content); const metadata = content.match(/\/\*\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g)?.[0] || ""; const source = metadata.match(/@source\s+(.+)/)?.[1] || ""; if (source) { VencordNative.native.openExternal(source); } else { VencordNative.native.openExternal(`${apiUrl}/${theme.id}`); } }; return ( {theme.name} {Parser.parse(theme.description)} {!removePreview && ( {theme.name} )}
{theme.tags && ( {theme.tags.map(tag => ( {tag} ))} )} {!removeButtons && (
)}
); };