Skip to content

Create professional demos and 3D mockups in seconds, directly in your browser

feat: implement pending export functionality for user authentication flow in editor

CristianOlivera110782912d79c
diff --git a/app/[locale]/(editor)/editor/page.tsx b/app/[locale]/(editor)/editor/page.tsx
index 2bff889..dbf9ea2 100644
--- a/app/[locale]/(editor)/editor/page.tsx
+++ b/app/[locale]/(editor)/editor/page.tsx
@@ -40,10 +40,13 @@ import { LoadingSpinner } from "@/components/ui/LoadingSpinner";
import { TimelineSkeleton } from "@/app/components/ui/Skeleton";
import { AudioTrimModal } from "@/app/components/ui/editor/AudioTrimModal";
import { useMockup3dContext } from "@/app/contexts/Mockup3dContext";
+import { useAuth } from "@/app/contexts/useAuth";
+import { usePathname, useRouter } from "@/navigation";
+import { savePendingExport, readPendingExport, clearPendingExport } from "@/lib/pending-export";
import Image from "next/image";
import Link from "next/link";
import { TooltipAction } from "@/components/ui/tooltip-action";
-import { useTranslations } from "next-intl";
+import { useLocale, useTranslations } from "next-intl";
import { useCanvasElements } from "@/hooks/useCanvasElements";
import { useEditorSelection } from "@/hooks/useEditorSelection";
import { useImageExport } from "@/hooks/useImageExport";
@@ -1014,7 +1017,20 @@ export default function Editor() {
prevImageExportStatusRef.current = imageExportProgress.status;
}, [imageExportProgress.status]);
+ const { user: authUser, loading: authLoading } = useAuth();
+ const locale = useLocale();
+ const pathname = usePathname();
+ const router = useRouter();
+
const handleExport = useCallback((quality: ExportQuality) => {
+ if (!authUser) {
+ savePendingExport(quality);
+ router.replace({
+ pathname: "/login",
+ query: { redirectedFrom: `/${locale}${pathname}` },
+ });
+ return;
+ }
isExportingRef.current = true;
for (const audioEl of audioElementsRef.current.values()) {
audioEl.pause();
@@ -1053,7 +1069,51 @@ export default function Editor() {
}).finally(() => {
isExportingRef.current = false;
});
- }, [videoBlob, selectedWallpaper, trimRange, muteOriginalAudio, videoHasAudioTrack, audioTracks, uploadedAudios, masterVolume, videoClips, globalSpeed, exportVideo, setIsPlaying]);
+ }, [videoBlob, selectedWallpaper, trimRange, muteOriginalAudio, videoHasAudioTrack, audioTracks, uploadedAudios, masterVolume, videoClips, globalSpeed, exportVideo, setIsPlaying, authUser, router, locale, pathname]);
+
+ const handleExportRef = useRef(handleExport);
+ useEffect(() => {
+ handleExportRef.current = handleExport;
+ }, [handleExport]);
+
+ // Reanuda una exportación pendiente tras iniciar sesión (redirect login → editor)
+ useEffect(() => {
+ if (!isVideoMode || authLoading || !authUser) return;
+
+ let timer: ReturnType<typeof setInterval> | null = null;
+ let attempts = 0;
+
+ const tick = () => {
+ const pendingQuality = readPendingExport();
+ if (!pendingQuality) {
+ if (timer) clearInterval(timer);
+ return;
+ }
+ // Esperar a que el proyecto termine de restaurarse desde IndexedDB
+ if (isRestoringProjectRef.current) return;
+
+ const hasContent = videoClipsRef.current.length > 0 || !!videoBlob;
+ if (!hasContent) {
+ attempts++;
+ // ~30s sin contenido: no hay nada que exportar, se descarta
+ if (attempts > 120) {
+ clearPendingExport();
+ if (timer) clearInterval(timer);
+ }
+ return;
+ }
+
+ clearPendingExport();
+ if (timer) clearInterval(timer);
+ handleExportRef.current(pendingQuality);
+ };
+
+ tick();
+ timer = setInterval(tick, 250);
+ return () => {
+ if (timer) clearInterval(timer);
+ };
+ }, [isVideoMode, authLoading, authUser]);
const showNewVideosBadge = useCallback((count: number) => {
if (newVideosBadgeTimeoutRef.current) {
diff --git a/lib/pending-export.ts b/lib/pending-export.ts
new file mode 100644
index 0000000..8b6621e
--- /dev/null
+++ b/lib/pending-export.ts
@@ -0,0 +1,26 @@
+import type { ExportQuality } from "@/types";
+
+const PENDING_EXPORT_KEY = "openvid:pendingExport";
+
+export function savePendingExport(quality: ExportQuality): void {
+ try {
+ sessionStorage.setItem(PENDING_EXPORT_KEY, quality);
+ } catch {
+ }
+}
+
+export function readPendingExport(): ExportQuality | null {
+ try {
+ const value = sessionStorage.getItem(PENDING_EXPORT_KEY);
+ return value !== null ? (value as ExportQuality) : null;
+ } catch {
+ return null;
+ }
+}
+
+export function clearPendingExport(): void {
+ try {
+ sessionStorage.removeItem(PENDING_EXPORT_KEY);
+ } catch {
+ }
+}