mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 14:51:12 -05:00
feat: Implement optimistic stats updates
This commit is contained in:
@@ -18,6 +18,12 @@ import { useModerationQueue } from "@/hooks/useModerationQueue";
|
||||
|
||||
import type { ModerationItem, EntityFilter, StatusFilter, LoadingState } from "@/types/moderation";
|
||||
|
||||
interface ModerationStats {
|
||||
pendingSubmissions: number;
|
||||
openReports: number;
|
||||
flaggedContent: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configuration for useModerationQueueManager
|
||||
*/
|
||||
@@ -26,6 +32,7 @@ export interface ModerationQueueManagerConfig {
|
||||
isAdmin: boolean;
|
||||
isSuperuser: boolean;
|
||||
toast: ReturnType<typeof useToast>["toast"];
|
||||
optimisticallyUpdateStats?: (delta: Partial<ModerationStats>) => void;
|
||||
settings: {
|
||||
refreshMode: "auto" | "manual";
|
||||
pollInterval: number;
|
||||
@@ -81,7 +88,7 @@ export function useModerationQueueManager(config: ModerationQueueManagerConfig):
|
||||
timestamp: new Date().toISOString()
|
||||
});
|
||||
|
||||
const { user, isAdmin, isSuperuser, toast, settings } = config;
|
||||
const { user, isAdmin, isSuperuser, toast, optimisticallyUpdateStats, settings } = config;
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
// Initialize sub-hooks
|
||||
@@ -279,6 +286,18 @@ export function useModerationQueueManager(config: ModerationQueueManagerConfig):
|
||||
return;
|
||||
}
|
||||
|
||||
// Calculate stat delta for optimistic update
|
||||
const statDelta: Partial<ModerationStats> = {};
|
||||
|
||||
if (action === 'approved' || action === 'rejected') {
|
||||
statDelta.pendingSubmissions = -1;
|
||||
}
|
||||
|
||||
// Optimistically update stats IMMEDIATELY
|
||||
if (optimisticallyUpdateStats) {
|
||||
optimisticallyUpdateStats(statDelta);
|
||||
}
|
||||
|
||||
// Optimistic update
|
||||
const shouldRemove =
|
||||
(filters.statusFilter === "pending" || filters.statusFilter === "flagged") &&
|
||||
|
||||
Reference in New Issue
Block a user