From 5caa7c059ff9894603a60ded01881ff147cb8629 Mon Sep 17 00:00:00 2001
From: Fafa <87046111+Faf4a@users.noreply.github.com>
Date: Fri, 3 Jan 2025 04:32:13 +0100
Subject: [PATCH 1/5] update theme library (#115)
* Merge branch 'dev'
* update theme library
* update author to use equicord constants
* Delete Dev Stuff For Merge
---
.../components/LikesComponent.tsx | 19 +-
.../themeLibrary/components/ThemeCard.tsx | 14 +-
.../themeLibrary/components/ThemeTab.tsx | 667 +-----------------
.../themeLibrary/components/styles.css | 146 ++--
src/equicordplugins/themeLibrary/index.tsx | 6 +-
src/equicordplugins/themeLibrary/native.ts | 4 +-
src/equicordplugins/themeLibrary/types.ts | 3 +-
.../themeLibrary/utils/auth.tsx | 14 +-
8 files changed, 133 insertions(+), 740 deletions(-)
diff --git a/src/equicordplugins/themeLibrary/components/LikesComponent.tsx b/src/equicordplugins/themeLibrary/components/LikesComponent.tsx
index 14e3de26..c4a03029 100644
--- a/src/equicordplugins/themeLibrary/components/LikesComponent.tsx
+++ b/src/equicordplugins/themeLibrary/components/LikesComponent.tsx
@@ -5,8 +5,7 @@
*/
import * as DataStore from "@api/DataStore";
-import { Button, useEffect, useRef, UserStore, useState } from "@webpack/common";
-import type { User } from "discord-types/general";
+import { Button, useEffect, useRef, useState } from "@webpack/common";
import type { Theme, ThemeLikeProps } from "../types";
import { isAuthorized } from "../utils/auth";
@@ -25,14 +24,13 @@ export const LikesComponent = ({ themeId, likedThemes: initialLikedThemes }: { t
function getThemeLikes(themeId: Theme["id"]): number {
const themeLike = likedThemes?.likes.find(like => like.themeId === themeId as unknown as Number);
- return themeLike ? themeLike.userIds.length : 0;
+ return themeLike ? themeLike.likes : 0;
}
const handleLikeClick = async (themeId: Theme["id"]) => {
if (!isAuthorized()) return;
const theme = likedThemes?.likes.find(like => like.themeId === themeId as unknown as Number);
- const currentUser: User = UserStore.getCurrentUser();
- const hasLiked: boolean = (theme?.userIds.includes(currentUser.id) || themeId === "preview") ?? false;
+ const hasLiked: boolean = theme?.hasLiked ?? false;
const endpoint = hasLiked ? "/likes/remove" : "/likes/add";
const token = await DataStore.get("ThemeLibrary_uniqueToken");
@@ -46,9 +44,9 @@ export const LikesComponent = ({ themeId, likedThemes: initialLikedThemes }: { t
method: "POST",
headers: {
"Content-Type": "application/json",
+ "Authorization": `Bearer ${token}`,
},
body: JSON.stringify({
- token,
themeId: themeId,
}),
});
@@ -57,7 +55,12 @@ export const LikesComponent = ({ themeId, likedThemes: initialLikedThemes }: { t
const fetchLikes = async () => {
try {
- const response = await themeRequest("/likes/get");
+ const token = await DataStore.get("ThemeLibrary_uniqueToken");
+ const response = await themeRequest("/likes/get", {
+ headers: {
+ "Authorization": `Bearer ${token}`,
+ },
+ });
const data = await response.json();
setLikedThemes(data);
} catch (err) {
@@ -72,7 +75,7 @@ export const LikesComponent = ({ themeId, likedThemes: initialLikedThemes }: { t
debounce.current = false;
};
- const hasLiked = likedThemes?.likes.some(like => like.themeId === themeId as unknown as Number && like.userIds.includes(UserStore.getCurrentUser().id)) ?? false;
+ const hasLiked = likedThemes?.likes.some(like => like.themeId === themeId as unknown as Number && like?.hasLiked === true) ?? false;
return (
diff --git a/src/equicordplugins/themeLibrary/components/ThemeCard.tsx b/src/equicordplugins/themeLibrary/components/ThemeCard.tsx
index e2f85424..28da1769 100644
--- a/src/equicordplugins/themeLibrary/components/ThemeCard.tsx
+++ b/src/equicordplugins/themeLibrary/components/ThemeCard.tsx
@@ -49,9 +49,9 @@ export const ThemeCard: React.FC
= ({ theme, themeLinks, likedTh
const getUser = (id: string, username: string) => UserUtils.getUser(id) ?? makeDummyUser({ username, id });
const handleAddRemoveTheme = () => {
- const onlineThemeLinks = themeLinks.includes(`${apiUrl}/${theme.name}`)
- ? themeLinks.filter(link => link !== `${apiUrl}/${theme.name}`)
- : [...themeLinks, `${apiUrl}/${theme.name}`];
+ const onlineThemeLinks = themeLinks.includes(`${apiUrl}/${theme.id}`)
+ ? themeLinks.filter(link => link !== `${apiUrl}/${theme.id}`)
+ : [...themeLinks, `${apiUrl}/${theme.id}`];
setThemeLinks(onlineThemeLinks);
Vencord.Settings.themeLinks = onlineThemeLinks;
@@ -108,7 +108,7 @@ export const ThemeCard: React.FC = ({ theme, themeLinks, likedTh
if (source) {
VencordNative.native.openExternal(source);
} else {
- VencordNative.native.openExternal(`${apiUrl}/${theme.name}`);
+ VencordNative.native.openExternal(`${apiUrl}/${theme.id}`);
}
};
@@ -135,16 +135,16 @@ export const ThemeCard: React.FC = ({ theme, themeLinks, likedTh
)}
{!removeButtons && (
- < div style={{ marginTop: "8px", display: "flex", flexDirection: "row" }}>
+
-