From b8eb1642e9fde420200aa94caa5db1fb02bb7c39 Mon Sep 17 00:00:00 2001 From: sebastjanartic <45803536-sebastjanartic@users.noreply.replit.com> Date: Tue, 2 Sep 2025 13:12:32 +0000 Subject: [PATCH] Update video editing form to reflect changes automatically Add a useEffect hook to the EditVideoDialog component to automatically update the form state when the `video` prop changes, and force immediate refetch of video data after successful updates. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 170e18f0-0f13-4eca-8643-546bba1dd8cc Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/8cc42625-c1f5-4e43-99bd-77f2c4dedee2/170e18f0-0f13-4eca-8643-546bba1dd8cc/LY6xmBI --- client/src/pages/admin.tsx | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/client/src/pages/admin.tsx b/client/src/pages/admin.tsx index 0507f49..8e29f98 100644 --- a/client/src/pages/admin.tsx +++ b/client/src/pages/admin.tsx @@ -1,4 +1,4 @@ -import { useState } from "react"; +import { useState, useEffect } from "react"; import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query"; import { useAuth } from "@/hooks/useAuth"; import { Button } from "@/components/ui/button"; @@ -217,6 +217,17 @@ function EditVideoDialog({ genre: video.genre, customThumbnailUrl: video.customThumbnailUrl || "", }); + + // Update form data when video prop changes + useEffect(() => { + setFormData({ + title: video.title, + description: video.description, + contentType: video.contentType, + genre: video.genre, + customThumbnailUrl: video.customThumbnailUrl || "", + }); + }, [video]); const [isGeneratingAI, setIsGeneratingAI] = useState(false); const updateMutation = useMutation({ @@ -226,9 +237,11 @@ function EditVideoDialog({ title: "Success", description: "Video updated successfully", }); - // Invalidate cache to refresh the video list + // 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(); },