File size: 20,819 Bytes
11f4e50 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 | import { useState, useCallback } from 'react';
import { useParams, useNavigate } from 'react-router-dom';
import { useDispatch } from 'react-redux';
import { motion, AnimatePresence } from 'framer-motion';
import { AppDispatch } from '../store';
import { createVideo } from '../store/videosSlice';
import AITerminal from '../components/AITerminal';
const STEPS = [
{ num: 1, title: 'Script', desc: 'Paste or write your video script' },
{ num: 2, title: 'Voice', desc: 'Choose voice settings' },
{ num: 3, title: 'Music', desc: 'Select background music' },
{ num: 4, title: 'Style', desc: 'Set visual preferences' },
{ num: 5, title: 'Assets', desc: 'Upload media files' },
];
export default function VideoCreate() {
const { projectId } = useParams<{ projectId: string }>();
const dispatch = useDispatch<AppDispatch>();
const navigate = useNavigate();
const [step, setStep] = useState(1);
const [showTerminal, setShowTerminal] = useState(false);
const [submitting, setSubmitting] = useState(false);
// Form state
const [script, setScript] = useState('');
const [voice, setVoice] = useState({
type: 'neutral',
language: 'en',
tone: 'professional',
speed: 1.0,
});
const [music, setMusic] = useState('');
const [style, setStyle] = useState({
fonts: { primary: 'Playfair Display', secondary: 'Montserrat' },
colors: { primary: '#1A1A1A', secondary: '#F5F5F5', accent: '#D4AF37' },
transitions: 'fade',
videoStyle: 'minimal',
});
const [files, setFiles] = useState<File[]>([]);
const next = () => setStep((s) => Math.min(s + 1, 5));
const prev = () => setStep((s) => Math.max(s - 1, 1));
const handleFileChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
if (e.target.files) {
setFiles(Array.from(e.target.files));
}
}, []);
const handleGenerate = async () => {
if (!projectId || !script.trim()) return;
setSubmitting(true);
const videoData = {
script,
voice,
music: { filePath: music },
assets: files.map((f) => ({ type: 'clip' as const, path: f.name })),
};
const result = await dispatch(createVideo({ projectId, data: videoData }));
setSubmitting(false);
if (createVideo.fulfilled.match(result)) {
navigate(`/video/${result.payload._id}/preview`);
}
};
return (
<div className="min-h-screen pt-20 pb-12 px-6">
<div className="max-w-4xl mx-auto">
{/* Stepper */}
<div className="flex items-center justify-between mb-12 relative">
<div className="absolute top-5 left-0 right-0 h-px bg-dark-400/30" />
{STEPS.map((s) => (
<div
key={s.num}
className="relative flex flex-col items-center cursor-pointer z-10"
onClick={() => setStep(s.num)}
>
<div className={`w-10 h-10 rounded-full flex items-center justify-center font-body font-semibold text-sm transition-all duration-300 ${step === s.num
? 'bg-gold-500 text-dark-900 shadow-gold'
: step > s.num
? 'bg-gold-500/20 text-gold-500 border border-gold-500/40'
: 'bg-dark-600 text-light-500 border border-dark-400/30'
}`}>
{step > s.num ? (
<svg className="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 13l4 4L19 7" />
</svg>
) : s.num}
</div>
<span className={`mt-2 text-xs font-body transition-colors ${step === s.num ? 'text-gold-500' : 'text-light-500'
}`}>
{s.title}
</span>
</div>
))}
</div>
{/* Step Content */}
<AnimatePresence mode="wait">
<motion.div
key={step}
initial={{ opacity: 0, x: 20 }}
animate={{ opacity: 1, x: 0 }}
exit={{ opacity: 0, x: -20 }}
transition={{ duration: 0.3 }}
className="glass-panel p-8 mb-8"
>
{step === 1 && (
<div>
<h2 className="font-display text-2xl font-bold text-light-100 mb-2">Your Script</h2>
<p className="text-light-500 mb-6">Paste your video script or write it directly. This will be used for voiceover and subtitles.</p>
<textarea
value={script}
onChange={(e) => setScript(e.target.value)}
className="input-field h-48 resize-none"
placeholder="Paste your video script here... Example: Did you know that 90% of successful content creators use faceless videos? Here is why this strategy works and how you can start today..."
id="script-input"
/>
<p className="mt-2 text-xs text-light-500/60">{script.length} characters</p>
</div>
)}
{step === 2 && (
<div>
<h2 className="font-display text-2xl font-bold text-light-100 mb-2">Voice Settings</h2>
<p className="text-light-500 mb-6">Configure the AI voiceover for your video.</p>
<div className="grid sm:grid-cols-2 gap-5">
<div>
<label className="block text-sm text-light-400 mb-2">Voice Type</label>
<select value={voice.type} onChange={(e) => setVoice({ ...voice, type: e.target.value })} className="input-field" id="voice-type">
<option value="neutral">Neutral</option>
<option value="male">Male</option>
<option value="female">Female</option>
<option value="deep">Deep</option>
<option value="energetic">Energetic</option>
</select>
</div>
<div>
<label className="block text-sm text-light-400 mb-2">Language</label>
<select value={voice.language} onChange={(e) => setVoice({ ...voice, language: e.target.value })} className="input-field" id="voice-language">
<option value="en">English</option>
<option value="es">Spanish</option>
<option value="fr">French</option>
<option value="de">German</option>
<option value="pt">Portuguese</option>
<option value="ja">Japanese</option>
</select>
</div>
<div>
<label className="block text-sm text-light-400 mb-2">Tone</label>
<select value={voice.tone} onChange={(e) => setVoice({ ...voice, tone: e.target.value })} className="input-field" id="voice-tone">
<option value="professional">Professional</option>
<option value="casual">Casual</option>
<option value="dramatic">Dramatic</option>
<option value="upbeat">Upbeat</option>
<option value="calm">Calm</option>
</select>
</div>
<div>
<label className="block text-sm text-light-400 mb-2">Speed: {voice.speed}x</label>
<input
type="range"
min="0.5"
max="2.0"
step="0.1"
value={voice.speed}
onChange={(e) => setVoice({ ...voice, speed: parseFloat(e.target.value) })}
className="w-full accent-gold-500"
id="voice-speed"
/>
</div>
</div>
</div>
)}
{step === 3 && (
<div>
<h2 className="font-display text-2xl font-bold text-light-100 mb-2">Background Music</h2>
<p className="text-light-500 mb-6">Choose music for your video or upload your own track.</p>
<div className="space-y-3">
{['None', 'Ambient Calm', 'Upbeat Energy', 'Corporate', 'Cinematic', 'Lo-Fi Chill'].map((track) => (
<label
key={track}
className={`card-static flex items-center gap-4 cursor-pointer transition-all ${music === track ? 'border-gold-500/40 shadow-gold' : ''
}`}
>
<input
type="radio"
name="music"
value={track}
checked={music === track}
onChange={(e) => setMusic(e.target.value)}
className="accent-gold-500"
/>
<span className="text-light-300">{track}</span>
</label>
))}
</div>
</div>
)}
{step === 4 && (
<div>
<h2 className="font-display text-2xl font-bold text-light-100 mb-2">Visual Style</h2>
<p className="text-light-500 mb-6">Customize the look and feel of your video.</p>
<div className="grid sm:grid-cols-2 gap-5">
<div>
<label className="block text-sm text-light-400 mb-2">Video Style</label>
<select
value={style.videoStyle}
onChange={(e) => setStyle({ ...style, videoStyle: e.target.value })}
className="input-field"
id="video-style"
>
<option value="minimal">Minimal</option>
<option value="dynamic">Dynamic</option>
<option value="cinematic">Cinematic</option>
<option value="bold">Bold</option>
<option value="elegant">Elegant</option>
</select>
</div>
<div>
<label className="block text-sm text-light-400 mb-2">Transitions</label>
<select
value={style.transitions}
onChange={(e) => setStyle({ ...style, transitions: e.target.value })}
className="input-field"
id="transitions"
>
<option value="fade">Fade</option>
<option value="slide">Slide</option>
<option value="zoom">Zoom</option>
<option value="dissolve">Dissolve</option>
<option value="none">None</option>
</select>
</div>
<div>
<label className="block text-sm text-light-400 mb-2">Accent Color</label>
<div className="flex items-center gap-3">
<input
type="color"
value={style.colors.accent}
onChange={(e) => setStyle({ ...style, colors: { ...style.colors, accent: e.target.value } })}
className="w-10 h-10 rounded border border-dark-400/30 cursor-pointer"
/>
<span className="text-sm text-light-500 font-mono">{style.colors.accent}</span>
</div>
</div>
<div>
<label className="block text-sm text-light-400 mb-2">Headline Font</label>
<select
value={style.fonts.primary}
onChange={(e) => setStyle({ ...style, fonts: { ...style.fonts, primary: e.target.value } })}
className="input-field"
>
<option value="Playfair Display">Playfair Display</option>
<option value="Montserrat">Montserrat</option>
<option value="Inter">Inter</option>
<option value="Roboto">Roboto</option>
<option value="Lora">Lora</option>
</select>
</div>
</div>
</div>
)}
{step === 5 && (
<div>
<h2 className="font-display text-2xl font-bold text-light-100 mb-2">Upload Assets</h2>
<p className="text-light-500 mb-6">Add clips, images, or logos to include in your video.</p>
<div className="border-2 border-dashed border-dark-400/50 rounded-xl p-8 text-center hover:border-gold-500/40 transition-colors">
<input
type="file"
multiple
onChange={handleFileChange}
className="hidden"
id="asset-upload"
accept="image/*,video/*,audio/*"
/>
<label htmlFor="asset-upload" className="cursor-pointer">
<div className="w-12 h-12 bg-gold-500/10 border border-gold-500/20 rounded-xl flex items-center justify-center mx-auto mb-4">
<span className="text-gold-500 text-2xl">+</span>
</div>
<p className="text-light-300 font-medium mb-1">Drag and drop or click to upload</p>
<p className="text-sm text-light-500">Images, videos, logos, and audio (max 100MB each)</p>
</label>
</div>
{files.length > 0 && (
<div className="mt-4 space-y-2">
{files.map((file, i) => (
<div key={i} className="flex items-center justify-between card-static py-3">
<span className="text-sm text-light-300">{file.name}</span>
<span className="text-xs text-light-500">{(file.size / 1024 / 1024).toFixed(1)} MB</span>
</div>
))}
</div>
)}
</div>
)}
</motion.div>
</AnimatePresence>
{/* Navigation + Terminal Toggle */}
<div className="flex items-center justify-between">
<button
onClick={prev}
disabled={step === 1}
className="btn-ghost disabled:opacity-30"
>
Previous
</button>
<button
onClick={() => setShowTerminal(!showTerminal)}
className="btn-ghost text-sm"
>
<span className="mr-1 font-mono">>_</span> Terminal
</button>
{step < 5 ? (
<button onClick={next} className="btn-primary">
Next Step
</button>
) : (
<button
onClick={handleGenerate}
disabled={submitting || !script.trim()}
className="btn-primary px-10"
id="generate-btn"
>
{submitting ? 'Generating...' : 'Generate Preview'}
</button>
)}
</div>
{/* Terminal Panel */}
{showTerminal && (
<motion.div
initial={{ opacity: 0, height: 0 }}
animate={{ opacity: 1, height: 'auto' }}
className="mt-8 overflow-hidden"
>
<AITerminal />
</motion.div>
)}
</div>
</div>
);
}
|