mirror of
https://github.com/Equicord/Equicord.git
synced 2025-01-30 19:23:29 -05:00
SortFriendRequests: Fix showing dates
This commit is contained in:
parent
47315b0eba
commit
8346dba324
1 changed files with 17 additions and 16 deletions
|
@ -17,11 +17,17 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { definePluginSettings } from "@api/Settings";
|
import { definePluginSettings } from "@api/Settings";
|
||||||
|
import ErrorBoundary from "@components/ErrorBoundary";
|
||||||
import { Flex } from "@components/Flex";
|
import { Flex } from "@components/Flex";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import definePlugin, { OptionType } from "@utils/types";
|
import definePlugin, { OptionType } from "@utils/types";
|
||||||
import { RelationshipStore } from "@webpack/common";
|
import { RelationshipStore, Text } from "@webpack/common";
|
||||||
import { User } from "discord-types/general";
|
import { User } from "discord-types/general";
|
||||||
|
import { PropsWithChildren } from "react";
|
||||||
|
|
||||||
|
function getSince(user: User) {
|
||||||
|
return new Date(RelationshipStore.getSince(user.id));
|
||||||
|
}
|
||||||
|
|
||||||
const settings = definePluginSettings({
|
const settings = definePluginSettings({
|
||||||
showDates: {
|
showDates: {
|
||||||
|
@ -48,28 +54,23 @@ export default definePlugin({
|
||||||
find: "#{intl::FRIEND_REQUEST_CANCEL}",
|
find: "#{intl::FRIEND_REQUEST_CANCEL}",
|
||||||
replacement: {
|
replacement: {
|
||||||
predicate: () => settings.store.showDates,
|
predicate: () => settings.store.showDates,
|
||||||
match: /subText:(\i)(?<=user:(\i).+?)/,
|
match: /(?<=\.listItemContents,children:\[)\(0,.+?(?=,\(0)(?<=user:(\i).+?)/,
|
||||||
replace: (_, subtext, user) => `subText:$self.makeSubtext(${subtext},${user})`
|
replace: (children, user) => `$self.WrapperDateComponent({user:${user},children:${children}})`
|
||||||
}
|
}
|
||||||
}],
|
}],
|
||||||
|
|
||||||
wrapSort(comparator: Function, row: any) {
|
wrapSort(comparator: Function, row: any) {
|
||||||
return row.type === 3 || row.type === 4
|
return row.type === 3 || row.type === 4
|
||||||
? -this.getSince(row.user)
|
? -getSince(row.user)
|
||||||
: comparator(row);
|
: comparator(row);
|
||||||
},
|
},
|
||||||
|
|
||||||
getSince(user: User) {
|
WrapperDateComponent: ErrorBoundary.wrap(({ user, children }: PropsWithChildren<{ user: User; }>) => {
|
||||||
return new Date(RelationshipStore.getSince(user.id));
|
const since = getSince(user);
|
||||||
},
|
|
||||||
|
|
||||||
makeSubtext(text: string, user: User) {
|
return <Flex flexDirection="row" style={{ alignItems: "center", justifyContent: "space-between", width: "100%", marginRight: "0.5em" }}>
|
||||||
const since = this.getSince(user);
|
{children}
|
||||||
return (
|
{!isNaN(since.getTime()) && <Text variant="text-xs/normal" color="text-muted">{since.toDateString()}</Text>}
|
||||||
<Flex flexDirection="column" style={{ gap: 0, flexWrap: "wrap", lineHeight: "0.9rem" }}>
|
</Flex>;
|
||||||
<span>{text}</span>
|
})
|
||||||
{!isNaN(since.getTime()) && <span>Received — {since.toDateString()}</span>}
|
|
||||||
</Flex>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue