From 735dfb25e113a3767ff5979a650745c7691123c6 Mon Sep 17 00:00:00 2001 From: thororen1234 <78185467+thororen1234@users.noreply.github.com> Date: Thu, 22 Aug 2024 14:43:26 -0400 Subject: [PATCH] Fixes --- src/plugins/memberCount/MemberCount.tsx | 12 ++++++- src/plugins/memberCount/index.tsx | 4 +++ src/plugins/reviewDB/index.tsx | 44 ++++++++++++++++++++++++- src/plugins/reviewDB/style.css | 6 +--- 4 files changed, 59 insertions(+), 7 deletions(-) diff --git a/src/plugins/memberCount/MemberCount.tsx b/src/plugins/memberCount/MemberCount.tsx index 3231d01c..084e7ecc 100644 --- a/src/plugins/memberCount/MemberCount.tsx +++ b/src/plugins/memberCount/MemberCount.tsx @@ -5,9 +5,10 @@ */ import { getCurrentChannel } from "@utils/discord"; +import { isObjectEmpty } from "@utils/misc"; import { SelectedChannelStore, Tooltip, useEffect, useStateFromStores } from "@webpack/common"; -import { ChannelMemberStore, cl, GuildMemberCountStore, numberFormat } from "."; +import { ChannelMemberStore, cl, GuildMemberCountStore, numberFormat, ThreadMemberListStore } from "."; import { OnlineMemberCountStore } from "./OnlineMemberCountStore"; export function MemberCount({ isTooltip, tooltipGuildId }: { isTooltip?: true; tooltipGuildId?: string; }) { @@ -30,10 +31,19 @@ export function MemberCount({ isTooltip, tooltipGuildId }: { isTooltip?: true; t () => ChannelMemberStore.getProps(guildId, currentChannel?.id) ); + const threadGroups = useStateFromStores( + [ThreadMemberListStore], + () => ThreadMemberListStore.getMemberListSections(currentChannel.id) + ); + if (!isTooltip && (groups.length >= 1 || groups[0].id !== "unknown")) { onlineCount = groups.reduce((total, curr) => total + (curr.id === "offline" ? 0 : curr.count), 0); } + if (!isTooltip && threadGroups && !isObjectEmpty(threadGroups)) { + onlineCount = Object.values(threadGroups).reduce((total, curr) => total + (curr.sectionId === "offline" ? 0 : curr.userIds.length), 0); + } + useEffect(() => { OnlineMemberCountStore.ensureCount(guildId); }, [guildId]); diff --git a/src/plugins/memberCount/index.tsx b/src/plugins/memberCount/index.tsx index 28ecb9db..7e591357 100644 --- a/src/plugins/memberCount/index.tsx +++ b/src/plugins/memberCount/index.tsx @@ -32,6 +32,10 @@ export const GuildMemberCountStore = findStoreLazy("GuildMemberCountStore") as F export const ChannelMemberStore = findStoreLazy("ChannelMemberStore") as FluxStore & { getProps(guildId: string, channelId: string): { groups: { count: number; id: string; }[]; }; }; +export const ThreadMemberListStore = findStoreLazy("ThreadMemberListStore") as FluxStore & { + getMemberListSections(channelId: string): { [sectionId: string]: { sectionId: string; userIds: string[]; }; }; +}; + const settings = definePluginSettings({ toolTip: { diff --git a/src/plugins/reviewDB/index.tsx b/src/plugins/reviewDB/index.tsx index 30544865..fbe43a61 100644 --- a/src/plugins/reviewDB/index.tsx +++ b/src/plugins/reviewDB/index.tsx @@ -20,16 +20,18 @@ import "./style.css"; import { NavContextMenuPatchCallback } from "@api/ContextMenu"; import ErrorBoundary from "@components/ErrorBoundary"; +import { ExpandableHeader } from "@components/ExpandableHeader"; import { NotesIcon, OpenExternalIcon } from "@components/Icons"; import { Devs } from "@utils/constants"; import { classes } from "@utils/misc"; import definePlugin from "@utils/types"; import { findByPropsLazy } from "@webpack"; -import { Alerts, Button, Menu, Parser, TooltipContainer } from "@webpack/common"; +import { Alerts, Button, Menu, Parser, TooltipContainer, useState } from "@webpack/common"; import { Guild, User } from "discord-types/general"; import { Auth, initAuth, updateAuth } from "./auth"; import { openReviewsModal } from "./components/ReviewModal"; +import ReviewsView from "./components/ReviewsView"; import { NotificationType } from "./entities"; import { getCurrentUserInfo, readNotification } from "./reviewDbApi"; import { settings } from "./settings"; @@ -76,6 +78,21 @@ export default definePlugin({ }, patches: [ + { + find: "showBorder:null", + replacement: { + match: /user:(\i),setNote:\i,canDM.+?\}\)/, + replace: "$&,$self.getReviewsComponent($1)" + } + }, + { + find: /inline:!1,profileViewedAnalytics:\i}\),/, + replacement: { + match: /currentUser:\i,guild:\i}\)(?<=user:(\i),bio:null==\i\?.+?)/, + replace: "$&,$self.getReviewsComponent($1)" + }, + predicate: () => !settings.store.preferButtonOverDropdown + }, { find: ".BITE_SIZE,user:", replacement: { @@ -140,6 +157,31 @@ export default definePlugin({ }, 4000); }, + getReviewsComponent: ErrorBoundary.wrap((user: User) => { + const [reviewCount, setReviewCount] = useState(); + + return ( + openReviewsModal(user.id, user.username)} + moreTooltipText={ + reviewCount && reviewCount > 50 + ? `View all ${reviewCount} reviews` + : "Open Review Modal" + } + onDropDownClick={state => settings.store.reviewsDropdownState = !state} + defaultState={settings.store.reviewsDropdownState} + > + setReviewCount(r.reviewCount)} + showInput + /> + + ); + }, { message: "Failed to render Reviews" }), + BiteSizeReviewsButton: ErrorBoundary.wrap(({ user }: { user: User; }) => { return ( diff --git a/src/plugins/reviewDB/style.css b/src/plugins/reviewDB/style.css index 5e46b757..361db9a6 100644 --- a/src/plugins/reviewDB/style.css +++ b/src/plugins/reviewDB/style.css @@ -3,10 +3,6 @@ --vc-rdb-spacing-size: 8px; } -[class|="section"]:not([class|="lastSection"])+.vc-rdb-view { - margin-top: 12px; -} - .vc-rdb-badge { vertical-align: middle; margin-left: 4px; @@ -184,4 +180,4 @@ .vc-rdb-review:hover>.vc-rdb-buttons { opacity: 1; -} \ No newline at end of file +}