"use client"; import { useState, useEffect } from "react"; import fs from "fs"; const AVAILABLE_CATEGORIES = [ "SiteMente", "OpenClaw", "Trading", "Marketing", "Technical", "Voice AI", "Business", "Inspiration", "Personal Growth" ]; const STORAGE_FILE = "/root/.openclaw/workspace/SiteMente/data/transcripts.json"; function getTranscripts() { try { if (fs.existsSync(STORAGE_FILE)) { return JSON.parse(fs.readFileSync(STORAGE_FILE, "utf-8")); } } catch (e) {} return []; } export default function TranscriptsPage() { const [transcripts, setTranscripts] = useState([]); const [videoUrl, setVideoUrl] = useState(""); const [transcriptText, setTranscriptText] = useState(""); const [title, setTitle] = useState(""); const [selectedCategories, setSelectedCategories] = useState([]); const [filterCategory, setFilterCategory] = useState("all"); const [saving, setSaving] = useState(false); useEffect(() => { setTranscripts(getTranscripts()); }, []); const toggleCategory = (cat: string) => { setSelectedCategories(prev => prev.includes(cat) ? prev.filter(c => c !== cat) : [...prev, cat] ); }; const saveTranscript = async () => { if (!videoUrl || !transcriptText) return; setSaving(true); // Extract video ID const match = videoUrl.match(/(?:v=|\/)([0-9A-Za-z_-]{11})/); const videoId = match ? match[1] : ""; const data = { videoId, videoUrl, title: title || `Video ${videoId}`, transcript: transcriptText, categories: selectedCategories, savedAt: new Date().toISOString() }; // Save directly const current = getTranscripts(); const existing = current.findIndex(t => t.videoId === videoId); if (existing >= 0) { current[existing] = data; } else { current.unshift(data); } fs.writeFileSync(STORAGE_FILE, JSON.stringify(current, null, 2)); setTranscripts(current); setSaving(false); setVideoUrl(""); setTranscriptText(""); setTitle(""); setSelectedCategories([]); }; const filteredTranscripts = filterCategory === "all" ? transcripts : transcripts.filter(t => t.categories?.includes(filterCategory)); const allCategories = [...new Set(transcripts.flatMap(t => t.categories || []))]; return (

🎬 YouTube Transcripts

{/* Add New Transcript */}

Add Transcript

setVideoUrl(e.target.value)} placeholder="YouTube URL..." className="w-full px-4 py-2 bg-black/30 border border-white/20 rounded-lg text-white placeholder-white/50 mb-3" /> setTitle(e.target.value)} placeholder="Title..." className="w-full px-4 py-2 bg-black/30 border border-white/20 rounded-lg text-white placeholder-white/50 mb-3" />

Categories:

{AVAILABLE_CATEGORIES.map(cat => ( ))}