From 8346dba324b81672b120e1397ce1c70b18127abd Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Wed, 22 Jan 2025 15:07:33 -0300 Subject: [PATCH] SortFriendRequests: Fix showing dates --- src/plugins/sortFriendRequests/index.tsx | 33 ++++++++++++------------ 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/plugins/sortFriendRequests/index.tsx b/src/plugins/sortFriendRequests/index.tsx index 6ce1af14d..1bd382ba8 100644 --- a/src/plugins/sortFriendRequests/index.tsx +++ b/src/plugins/sortFriendRequests/index.tsx @@ -17,11 +17,17 @@ */ import { definePluginSettings } from "@api/Settings"; +import ErrorBoundary from "@components/ErrorBoundary"; import { Flex } from "@components/Flex"; import { Devs } from "@utils/constants"; import definePlugin, { OptionType } from "@utils/types"; -import { RelationshipStore } from "@webpack/common"; +import { RelationshipStore, Text } from "@webpack/common"; import { User } from "discord-types/general"; +import { PropsWithChildren } from "react"; + +function getSince(user: User) { + return new Date(RelationshipStore.getSince(user.id)); +} const settings = definePluginSettings({ showDates: { @@ -48,28 +54,23 @@ export default definePlugin({ find: "#{intl::FRIEND_REQUEST_CANCEL}", replacement: { predicate: () => settings.store.showDates, - match: /subText:(\i)(?<=user:(\i).+?)/, - replace: (_, subtext, user) => `subText:$self.makeSubtext(${subtext},${user})` + match: /(?<=\.listItemContents,children:\[)\(0,.+?(?=,\(0)(?<=user:(\i).+?)/, + replace: (children, user) => `$self.WrapperDateComponent({user:${user},children:${children}})` } }], wrapSort(comparator: Function, row: any) { return row.type === 3 || row.type === 4 - ? -this.getSince(row.user) + ? -getSince(row.user) : comparator(row); }, - getSince(user: User) { - return new Date(RelationshipStore.getSince(user.id)); - }, + WrapperDateComponent: ErrorBoundary.wrap(({ user, children }: PropsWithChildren<{ user: User; }>) => { + const since = getSince(user); - makeSubtext(text: string, user: User) { - const since = this.getSince(user); - return ( - - {text} - {!isNaN(since.getTime()) && Received — {since.toDateString()}} - - ); - } + return + {children} + {!isNaN(since.getTime()) && {since.toDateString()}} + ; + }) });