/* media.jsx — Video Wishes + Gallery (upload, masonry, slideshow) */ const { useState: useStateMed, useRef: useRefMed } = React; function MediaUploader({ kind, accept, cta, hint }) { const [file, setFile] = useStateMed(null); const [preview, setPreview] = useStateMed(null); const [name, setName] = useStateMed(''); const [caption, setCaption] = useStateMed(''); const [busy, setBusy] = useStateMed(false); const [drag, setDrag] = useStateMed(false); const inputRef = useRefMed(null); const take = (f) => { if (!f) return; if (!f.type.startsWith('image/')) { window.R50UI && window.R50UI.toast('Please choose a photo file.'); return; } if (f.size > 2 * 1024 * 1024) { window.R50UI && window.R50UI.toast('That photo is over 2MB — please choose a smaller one.'); return; } setFile(f); setPreview(URL.createObjectURL(f)); }; const post = async () => { if (!file) return; setBusy(true); await R50.addMedia({ kind, name: name.trim(), file, caption: caption.trim() }); bumpMedia(); setBusy(false); setFile(null); setPreview(null); setName(''); setCaption(''); window.R50UI && window.R50UI.toast(kind === 'wish' ? 'Your video wish is posted 💛' : 'Added to the gallery 💛'); }; return (
{!file ? (
inputRef.current.click()} onDragOver={(e) => { e.preventDefault(); setDrag(true); }} onDragLeave={() => setDrag(false)} onDrop={(e) => { e.preventDefault(); setDrag(false); take(e.dataTransfer.files[0]); }} >
{kind === 'wish' ? '🎬' : '📷'}
{cta}
{hint}
take(e.target.files[0])} />
) : (
preview
setName(e.target.value)} placeholder="Who's this from?" />
setCaption(e.target.value)} placeholder={kind === 'wish' ? 'Happy 50th, Rajshree!' : 'Say something about this moment…'} />
)}
); } function Gallery() { const media = useMediaList(); const photos = media.filter((m) => m.type === 'image' && m.src); return ( ); } Object.assign(window, { Gallery });