Skip to content

Commit d2dab89

Browse files
committed
Preserve generate sidebar state across jobs
1 parent e32c685 commit d2dab89

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

src/components/right-panel.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
XIcon,
2525
} from "lucide-react";
2626
import type { KeyboardEvent } from "react";
27-
import { useCallback } from "react";
27+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
2828
import { MediaItemRow } from "./media-panel";
2929
import {
3030
Accordion,
@@ -52,7 +52,6 @@ import {
5252
resolveMediaUrl,
5353
} from "@/lib/utils";
5454
import { useMutation, useQueryClient } from "@tanstack/react-query";
55-
import { useEffect, useMemo, useState } from "react";
5655
import CameraMovement from "./camera-control";
5756
import { VoiceSelector } from "./playht/voice-selector";
5857
import { LoadingIcon } from "./ui/icons";
@@ -170,11 +169,15 @@ export default function RightPanel({
170169
);
171170
const queryClient = useQueryClient();
172171

172+
const generateDialogOpenRef = useRef(generateDialogOpen);
173+
const shouldReopenOnSuccessRef = useRef(false);
174+
173175
const handleOnOpenChange = useCallback(
174176
(isOpen: boolean) => {
175177
if (!isOpen) {
176178
closeGenerateDialog();
177179
resetGenerateData();
180+
shouldReopenOnSuccessRef.current = false;
178181
return;
179182
}
180183
onOpenChange?.(isOpen);
@@ -334,8 +337,15 @@ export default function RightPanel({
334337
},
335338
});
336339

340+
useEffect(() => {
341+
generateDialogOpenRef.current = generateDialogOpen;
342+
}, [generateDialogOpen]);
343+
337344
const handleOnGenerate = useCallback(
338345
async () => {
346+
shouldReopenOnSuccessRef.current = generateDialogOpenRef.current;
347+
setTab("generation");
348+
339349
createJob.mutate(
340350
{} as unknown as Parameters<typeof createJob.mutate>[0],
341351
{
@@ -357,6 +367,13 @@ export default function RightPanel({
357367
videoProjectStore.onGenerate = handleOnGenerate;
358368
}, [handleOnGenerate, videoProjectStore]);
359369

370+
useEffect(() => {
371+
if (createJob.isSuccess && shouldReopenOnSuccessRef.current) {
372+
openGenerateDialog();
373+
shouldReopenOnSuccessRef.current = false;
374+
}
375+
}, [createJob.isSuccess, openGenerateDialog]);
376+
360377
const handleKeyDown = useCallback(
361378
(event: KeyboardEvent<HTMLElement>) => {
362379
if (event.key === "Enter" && (event.ctrlKey || event.metaKey)) {

0 commit comments

Comments
 (0)