From 5fb9842ad09e9154a4f207eb9260286c74849802 Mon Sep 17 00:00:00 2001 From: sebastjanartic <45803536-sebastjanartic@users.noreply.replit.com> Date: Tue, 2 Sep 2025 14:15:01 +0000 Subject: [PATCH] Allow admins to edit and save video details correctly Update the admin video editing interface to correctly save changes and refresh data by making cache invalidation and refetching asynchronous operations. Also, implement saving without closing the modal for AI description generation. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 2cd2c0bc-434c-4bc9-ad3f-b99d3897a0d1 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/8cc42625-c1f5-4e43-99bd-77f2c4dedee2/2cd2c0bc-434c-4bc9-ad3f-b99d3897a0d1/n7jzC7R --- client/src/pages/admin.tsx | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/client/src/pages/admin.tsx b/client/src/pages/admin.tsx index 4111cde..4a4ae93 100644 --- a/client/src/pages/admin.tsx +++ b/client/src/pages/admin.tsx @@ -253,18 +253,22 @@ function EditVideoDialog({ const updateMutation = useMutation({ mutationFn: (data: any) => apiRequest("PATCH", `/api/admin/videos/${video.id}`, data), - onSuccess: () => { + onSuccess: async () => { toast({ title: "Success", description: "Video updated successfully", }); - // Invalidate cache to refresh the video list - don't await since this function isn't async - queryClient.invalidateQueries({ queryKey: ["/api/admin/videos"] }); - queryClient.invalidateQueries({ queryKey: ["/api/videos"] }); - // Force immediate refetch - queryClient.refetchQueries({ queryKey: ["/api/admin/videos"] }); - onOpenChange(false); - onSuccess(); + // Invalidate cache to refresh the video list + await queryClient.invalidateQueries({ queryKey: ["/api/admin/videos"] }); + await queryClient.invalidateQueries({ queryKey: ["/api/videos"] }); + // Force immediate refetch to get updated data + await queryClient.refetchQueries({ queryKey: ["/api/admin/videos"] }); + + // Give some time for cache to update before closing modal + setTimeout(() => { + onOpenChange(false); + onSuccess(); + }, 100); }, onError: (error: any) => { toast({ @@ -328,7 +332,16 @@ function EditVideoDialog({ episodeNumber: newFormData.episodeNumber ? parseInt(newFormData.episodeNumber.toString()) : null, tags: Array.isArray(newFormData.tags) ? newFormData.tags : [] }; - updateMutation.mutate(processedData); + + // Save without closing modal for AI generation + try { + await apiRequest("PATCH", `/api/admin/videos/${video.id}`, processedData); + // Refresh cache after save + await queryClient.invalidateQueries({ queryKey: ["/api/admin/videos"] }); + await queryClient.refetchQueries({ queryKey: ["/api/admin/videos"] }); + } catch (error) { + console.error("Failed to save AI description:", error); + } toast({ title: "Uspeh!",