| // src/components/social/VideoNoteRecorder.tsx | |
| import { useState } from "react"; | |
| import { useVideoNoteRecorder } from "@/hooks/useVideoNoteRecorder"; | |
| import { | |
| Video, VideoOff, Mic, MicOff, Play, Pause, Square, | |
| Send, Trash2, Clock, AlertTriangle, Loader2, | |
| } from "lucide-react"; | |
| interface VideoNoteRecorderProps { | |
| onSend: (blob: Blob, duration: number, mode: "video" | "audio") => void; | |
| onCancel: () => void; | |
| } | |
| export function VideoNoteRecorder({ onSend, onCancel }: VideoNoteRecorderProps) { | |
| const { | |
| status, mode, duration, blob, url, error, | |
| startRecording, stopRecording, pauseRecording, resumeRecording, cancelRecording, reset, | |
| } = useVideoNoteRecorder(); | |
| const [started, setStarted] = useState(false); | |
| const formatDuration = (sec: number) => { | |
| const m = Math.floor(sec / 60); | |
| const s = Math.floor(sec % 60); | |
| return `${m}:${s.toString().padStart(2, "0")}`; | |
| }; | |
| // Idle: show mode picker | |
| if (status === "idle" && !blob && !started) { | |
| return ( | |
| <div className="bg-white dark:bg-gray-800 rounded-2xl p-4 border border-gray-200 dark:border-gray-700 w-full max-w-sm mx-auto"> | |
| <h4 className="font-semibold text-center mb-3">Record a Note</h4> | |
| <div className="flex gap-3 mb-4"> | |
| <button | |
| onClick={() => { | |
| startRecording("video"); | |
| setStarted(true); | |
| }} | |
| className="flex-1 flex flex-col items-center gap-2 p-4 rounded-xl bg-blue-50 dark:bg-blue-900/20 hover:bg-blue-100 dark:hover:bg-blue-900/30 transition" | |
| > | |
| <Video className="w-8 h-8 text-blue-600" /> | |
| <span className="text-sm font-medium">Video</span> | |
| </button> | |
| <button | |
| onClick={() => { | |
| startRecording("audio"); | |
| setStarted(true); | |
| }} | |
| className="flex-1 flex flex-col items-center gap-2 p-4 rounded-xl bg-green-50 dark:bg-green-900/20 hover:bg-green-100 dark:hover:bg-green-900/30 transition" | |
| > | |
| <Mic className="w-8 h-8 text-green-600" /> | |
| <span className="text-sm font-medium">Audio</span> | |
| </button> | |
| </div> | |
| {error && <p className="text-xs text-red-500 mb-3 text-center">{error}</p>} | |
| <button onClick={onCancel} className="btn btn-ghost btn-sm w-full">Cancel</button> | |
| </div> | |
| ); | |
| } | |
| // Recording / Paused | |
| if (status === "recording" || status === "paused") { | |
| return ( | |
| <div className="bg-white dark:bg-gray-800 rounded-2xl p-4 border border-gray-200 dark:border-gray-700 w-full max-w-sm mx-auto"> | |
| <div className="flex items-center justify-between mb-3"> | |
| <span className="flex items-center gap-2 text-sm font-semibold"> | |
| <span className={`w-3 h-3 rounded-full ${status === "recording" ? "bg-red-500 animate-pulse" : "bg-yellow-500"}`} /> | |
| {status === "recording" ? "Recording" : "Paused"} ({mode}) | |
| </span> | |
| <span className="text-sm font-mono text-gray-500">{formatDuration(duration)}</span> | |
| </div> | |
| <div className="flex justify-center gap-3"> | |
| {status === "recording" ? ( | |
| <button onClick={pauseRecording} className="p-3 bg-gray-100 dark:bg-gray-700 rounded-full hover:bg-gray-200"> | |
| <Pause className="w-5 h-5" /> | |
| </button> | |
| ) : ( | |
| <button onClick={resumeRecording} className="p-3 bg-gray-100 dark:bg-gray-700 rounded-full hover:bg-gray-200"> | |
| <Play className="w-5 h-5" /> | |
| </button> | |
| )} | |
| <button onClick={stopRecording} className="p-3 bg-red-500 text-white rounded-full hover:bg-red-600"> | |
| <Square className="w-5 h-5" /> | |
| </button> | |
| <button onClick={cancelRecording} className="p-3 bg-gray-100 dark:bg-gray-700 rounded-full hover:bg-gray-200 text-red-500"> | |
| <Trash2 className="w-5 h-5" /> | |
| </button> | |
| </div> | |
| </div> | |
| ); | |
| } | |
| // Preview after recording | |
| if (blob && url) { | |
| return ( | |
| <div className="bg-white dark:bg-gray-800 rounded-2xl p-4 border border-gray-200 dark:border-gray-700 w-full max-w-sm mx-auto"> | |
| <div className="mb-3 flex items-center justify-between"> | |
| <span className="text-sm font-semibold">Preview ({formatDuration(duration)})</span> | |
| <button onClick={reset} className="text-gray-400 hover:text-red-500" aria-label="Button"><Trash2 className="w-4 h-4"/></button> | |
| </div> | |
| {mode === "video" ? ( | |
| <video src={url} controls className="w-full rounded-xl mb-3" /> | |
| ) : ( | |
| <audio src={url} controls className="w-full mb-3" /> | |
| )} | |
| <div className="flex gap-2"> | |
| <button | |
| onClick={() => onSend(blob, duration, mode)} | |
| className="btn btn-primary flex-1 gap-2" | |
| > | |
| <Send className="w-4 h-4"/> Send | |
| </button> | |
| <button onClick={reset} className="btn btn-secondary flex-1 gap-2"> | |
| <Trash2 className="w-4 h-4"/> Discard | |
| </button> | |
| </div> | |
| </div> | |
| ); | |
| } | |
| return null; | |
| } |
Xet Storage Details
- Size:
- 5.11 kB
- Xet hash:
- 522fb4198d041676d2a5a179eb74fabffd685f08d90fb42cb5abcf2a43dd0fa3
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.