From a08f59ea31a14cdb79b633933469deb4fd3b21ba Mon Sep 17 00:00:00 2001 From: Supertiger Date: Tue, 14 Jan 2025 16:12:11 +0000 Subject: [PATCH] Implement scheduled deletion feature for servers in moderation pane --- src/chat-api/RawData.ts | 3 ++ src/common/GlobalEvents.ts | 6 +-- .../moderation-pane/DeleteServersModal.tsx | 3 +- .../moderation-pane/ModerationPane.tsx | 26 ++++++++--- src/components/moderation-pane/ServerPage.tsx | 45 ++++++++++++++++++- 5 files changed, 72 insertions(+), 11 deletions(-) diff --git a/src/chat-api/RawData.ts b/src/chat-api/RawData.ts index 152d5698..53cbf6d5 100644 --- a/src/chat-api/RawData.ts +++ b/src/chat-api/RawData.ts @@ -14,6 +14,9 @@ export interface RawServer { _count?: { welcomeQuestions: number; }; + scheduledForDeletion: { + scheduledAt: number; + } } export interface RawVoice { diff --git a/src/common/GlobalEvents.ts b/src/common/GlobalEvents.ts index 487ed81c..a82c5563 100644 --- a/src/common/GlobalEvents.ts +++ b/src/common/GlobalEvents.ts @@ -31,8 +31,8 @@ export function useModerationShowMessages() { ); } -export function emitModerationServerDeleted() { - EE.emit("moderationServerDeleted", {}); +export function emitModerationServerDeleted(servers: any[]) { + EE.emit("moderationServerDeleted", servers); } export function emitModerationUserSuspended(payload: ModerationSuspension) { EE.emit("moderationUserSuspended", payload); @@ -47,7 +47,7 @@ export function useModerationUserSuspendedListener() { } export function useModerationServerDeletedListener() { - return useEventListen("moderationServerDeleted"); + return useEventListen("moderationServerDeleted"); } export function useEventListen( diff --git a/src/components/moderation-pane/DeleteServersModal.tsx b/src/components/moderation-pane/DeleteServersModal.tsx index 475ddcb2..a28d9e79 100644 --- a/src/components/moderation-pane/DeleteServersModal.tsx +++ b/src/components/moderation-pane/DeleteServersModal.tsx @@ -14,6 +14,7 @@ import Text from "../ui/Text"; import useStore from "@/chat-api/store/useStore"; import { useCustomPortal } from "../ui/custom-portal/CustomPortal"; import Checkbox from "../ui/Checkbox"; +import { emitModerationServerDeleted } from "@/common/GlobalEvents"; const Container = styled("div")` min-width: 260px; @@ -70,7 +71,6 @@ export default function DeleteServersModal(props: Props) { }; const onSuspendClicked = async () => { - console.log(constructedReason()); if (!constructedReason().trim()) { setError({ message: "Please provide a reason." }); return; @@ -110,6 +110,7 @@ export default function DeleteServersModal(props: Props) { "Some servers could not be deleted due to an error. Please try again." ); } + emitModerationServerDeleted(props.servers); props.done(); props.close(); }; diff --git a/src/components/moderation-pane/ModerationPane.tsx b/src/components/moderation-pane/ModerationPane.tsx index 26b7b3c6..a287c79b 100644 --- a/src/components/moderation-pane/ModerationPane.tsx +++ b/src/components/moderation-pane/ModerationPane.tsx @@ -274,7 +274,6 @@ function SelectedServerActions() { const { createPortal } = useCustomPortal(); const onDeleted = () => { - emitModerationServerDeleted(); setSelectedServers([]); }; @@ -450,11 +449,12 @@ function ServersPane() { const moderationServerDeletedListener = useModerationServerDeletedListener(); - moderationServerDeletedListener(() => { + moderationServerDeletedListener((deletedServers) => { setServers( - servers().filter((u) => { - const wasSuspended = selectedServers().find((su) => su.id === u.id); - return !wasSuspended; + servers().map((u) => { + const wasSuspended = deletedServers.find((su) => su.id === u.id); + if (!wasSuspended) return u; + return {...u, scheduledForDeletion: {scheduledAt: Date.now()}}; }) ); }); @@ -695,6 +695,22 @@ export function Server(props: { server: any }) { + +
+ + Scheduled Deletion + +
+
); diff --git a/src/components/moderation-pane/ServerPage.tsx b/src/components/moderation-pane/ServerPage.tsx index 471bcb7a..a99a4853 100644 --- a/src/components/moderation-pane/ServerPage.tsx +++ b/src/components/moderation-pane/ServerPage.tsx @@ -21,6 +21,7 @@ import { FlexColumn, FlexRow } from "../ui/Flexbox"; import { UsersPane } from "./UsersPane"; import { UsersAuditLogsPane } from "./UsersAuditLogsPane"; import DeleteServersModal from "./DeleteServersModal"; +import { formatTimestamp } from "@/common/date"; export default function ServerPage() { const params = useParams<{ serverId: string }>(); @@ -117,6 +118,16 @@ export default function ServerPage() { /> + + + + + + + + + + - @@ -223,7 +233,7 @@ const DeleteServerBlock = (props: { serverId: string }) => { }; return ( - +