From cf12fc3942994caa9201d07d21bdb1110d267cfb Mon Sep 17 00:00:00 2001 From: Harun CAN Date: Sat, 25 Apr 2026 14:37:34 +0200 Subject: [PATCH] main --- .../dashboard/document-to-video/page.tsx | 93 ++++++++++++++++--- src/hooks/use-api.ts | 27 ++++++ src/lib/api/api-service.ts | 36 +++++++ 3 files changed, 145 insertions(+), 11 deletions(-) diff --git a/src/app/[locale]/(dashboard)/dashboard/document-to-video/page.tsx b/src/app/[locale]/(dashboard)/dashboard/document-to-video/page.tsx index fcf5604..5f78164 100644 --- a/src/app/[locale]/(dashboard)/dashboard/document-to-video/page.tsx +++ b/src/app/[locale]/(dashboard)/dashboard/document-to-video/page.tsx @@ -3,7 +3,7 @@ import { useState } from "react"; import { useRouter } from "next/navigation"; import { cn } from "@/lib/utils"; -import { useCreateFromDocument } from "@/hooks/use-api"; +import { useExtractDocumentTopics, useCreateFromExtractedText } from "@/hooks/use-api"; import { useToast } from "@/components/ui/toast"; import { FileText, @@ -42,9 +42,13 @@ export default function DocumentToVideoPage() { const router = useRouter(); const { toast } = useToast(); - const createFromDocument = useCreateFromDocument(); + const extractDocumentTopics = useExtractDocumentTopics(); + const createFromExtractedText = useCreateFromExtractedText(); const [file, setFile] = useState(null); + const [extractedData, setExtractedData] = useState<{text: string; topics: string[]; originalFilename: string} | null>(null); + const [selectedTopic, setSelectedTopic] = useState(null); + const [style, setStyle] = useState("CINEMATIC"); const [cinematicReference, setCinematicReference] = useState(""); const [duration, setDuration] = useState(60); @@ -54,18 +58,40 @@ export default function DocumentToVideoPage() { const handleFileChange = (e: React.ChangeEvent) => { if (e.target.files && e.target.files.length > 0) { setFile(e.target.files[0]); + setExtractedData(null); + setSelectedTopic(null); } }; - const handleGenerate = async () => { + const handleExtractTopics = async () => { if (!file) { toast("error", "Lütfen bir belge seçin."); return; } try { - const result: any = await createFromDocument.mutateAsync({ - file, + const result = await extractDocumentTopics.mutateAsync({ file }); + setExtractedData(result); + if (result.topics.length > 0) { + setSelectedTopic(result.topics[0]); + } + toast("success", "Belge incelendi ve konular çıkarıldı!"); + } catch (error) { + toast("error", "Konu çıkarılırken hata oluştu. Belki belge okunamıyor veya çok büyük."); + } + }; + + const handleGenerate = async () => { + if (!extractedData || !selectedTopic) { + toast("error", "Lütfen bir belge yükleyip konu seçin."); + return; + } + + try { + const result: any = await createFromExtractedText.mutateAsync({ + text: extractedData.text, + topic: selectedTopic, + originalFilename: extractedData.originalFilename, language, aspectRatio, videoStyle: style, @@ -73,7 +99,7 @@ export default function DocumentToVideoPage() { targetDuration: duration, }); - toast("success", "Belge → Video projesi oluşturuldu!"); + toast("success", "Video projesi oluşturuldu!"); router.push(`/dashboard/projects/${result.id}`); } catch (error) { toast("error", "Proje oluşturulurken hata oluştu."); @@ -115,6 +141,51 @@ export default function DocumentToVideoPage() { /> + + {!extractedData && file && ( + + )} + + {extractedData && ( +
+

+ + Şu Konulardan Birini Seçin: +

+
+ {extractedData.topics.map((topic, i) => ( +
setSelectedTopic(topic)} + className={cn( + "p-3 rounded-lg border text-sm cursor-pointer transition-all", + selectedTopic === topic + ? "bg-blue-500/20 border-blue-500 text-blue-400" + : "bg-[var(--color-bg-surface)] border-[var(--color-border-faint)] text-[var(--color-text-secondary)] hover:border-blue-500/50" + )} + > + {topic} +
+ ))} +
+
+ )} {/* Video Settings */} @@ -235,16 +306,16 @@ export default function DocumentToVideoPage() {