`backend` 옆에 `front` 가 있을 이유가 없었다. negosium 의 negodata/front 를 그대로 베꼈고 그게 왜 front 인지는 따져보지 않았다 — 근거 없이 들여온 이름이라 바로잡는다. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019uYhHQdssRubirPirrdJJC
170 lines
6.3 KiB
TypeScript
170 lines
6.3 KiB
TypeScript
/**
|
|
* 사진 · 사진 + 영상 — 격자 갤러리 아래에 YouTube 영상을 붙인다.
|
|
* 릴스·유튜브로 이미 알려진 곳이면 사진보다 영상이 더 잘 판다.
|
|
*/
|
|
import {useState} from 'react';
|
|
import {Plus} from 'lucide-react';
|
|
import {convertYouTubeToEmbed} from '@/lib/youtube';
|
|
import {
|
|
EmptyStateNotice,
|
|
Lightbox,
|
|
PhotoTile,
|
|
SectionBody,
|
|
SectionFrame,
|
|
SectionHeading,
|
|
} from '../../primitives';
|
|
import type {SectionRenderProps} from '../../types';
|
|
import {galleryPhotos} from '../common';
|
|
import {VideoCard, type VideoItem} from './VideoCard';
|
|
|
|
export function PhotosWithVideos(props: SectionRenderProps) {
|
|
const {section, isSelected, onSelect, industryId, template, photos} = props;
|
|
const items = galleryPhotos(industryId, photos);
|
|
|
|
const [openIndex, setOpenIndex] = useState<number | null>(null);
|
|
// 영상은 사장님이 이 화면에서 직접 추가한 것만 있다 — 시연용 목록을 깔지 않는다.
|
|
const [added, setAdded] = useState<VideoItem[]>([]);
|
|
const [removedIds, setRemovedIds] = useState<string[]>([]);
|
|
const videos = added.filter((v) => !removedIds.includes(v.id));
|
|
const [playingId, setPlayingId] = useState<string | null>(null);
|
|
const [isFormOpen, setIsFormOpen] = useState(false);
|
|
const [inputTitle, setInputTitle] = useState('');
|
|
const [inputUrl, setInputUrl] = useState('');
|
|
const [errorMsg, setErrorMsg] = useState('');
|
|
|
|
const handleAddVideo = (e: React.FormEvent) => {
|
|
e.preventDefault();
|
|
setErrorMsg('');
|
|
|
|
if (!inputTitle.trim() || !inputUrl.trim()) {
|
|
setErrorMsg('제목과 YouTube URL을 모두 입력해주세요.');
|
|
return;
|
|
}
|
|
|
|
const {embedUrl, isValid} = convertYouTubeToEmbed(inputUrl);
|
|
if (!isValid || !embedUrl) {
|
|
setErrorMsg('올바른 YouTube URL 형식이 아닙니다.');
|
|
return;
|
|
}
|
|
|
|
setAdded((prev) => [
|
|
{id: `canvas-v-${Date.now()}`, title: inputTitle.trim(), videoUrl: inputUrl.trim(), embedUrl},
|
|
...prev,
|
|
]);
|
|
setInputTitle('');
|
|
setInputUrl('');
|
|
setIsFormOpen(false);
|
|
};
|
|
|
|
return (
|
|
<SectionFrame section={section} isSelected={isSelected} onSelect={onSelect} tone="paper">
|
|
<SectionBody className="space-y-8">
|
|
<div className="space-y-6">
|
|
<SectionHeading title={section.name} subtitle={section.description} colors={template.colors} />
|
|
|
|
<div className="grid grid-cols-2 gap-2.5 sm:grid-cols-3 sm:gap-3 md:grid-cols-4">
|
|
{items.map((photo, idx) => (
|
|
<PhotoTile
|
|
key={photo.id}
|
|
photo={photo}
|
|
fit="square"
|
|
onOpen={() => setOpenIndex(idx)}
|
|
/>
|
|
))}
|
|
</div>
|
|
</div>
|
|
|
|
<div className="space-y-6">
|
|
<SectionHeading
|
|
title="영상 갤러리"
|
|
subtitle="공간의 분위기를 영상으로 미리 확인해 보세요"
|
|
trailing={
|
|
<button
|
|
type="button"
|
|
title="영상 추가"
|
|
onClick={(e) => {
|
|
e.stopPropagation();
|
|
setIsFormOpen((v) => !v);
|
|
}}
|
|
className="flex size-8 cursor-pointer items-center justify-center rounded-full border border-stone-300 bg-white text-stone-700 shadow-2xs transition-colors hover:bg-stone-100 hover:text-stone-900"
|
|
>
|
|
<Plus className="size-4" />
|
|
</button>
|
|
}
|
|
colors={template.colors}
|
|
/>
|
|
|
|
{isFormOpen && (
|
|
<div
|
|
onClick={(e) => e.stopPropagation()}
|
|
role="presentation"
|
|
className="rounded-xl border border-stone-200 bg-white p-4 shadow-xs"
|
|
>
|
|
<form onSubmit={handleAddVideo} className="space-y-3">
|
|
<div className="grid grid-cols-1 gap-3 sm:grid-cols-2">
|
|
<input
|
|
type="text"
|
|
value={inputTitle}
|
|
onChange={(e) => setInputTitle(e.target.value)}
|
|
placeholder="영상 제목 (예: 스테이의 아침)"
|
|
className="rounded-lg border border-stone-200 bg-stone-50 px-3 py-2 text-xs focus:bg-white focus:outline-none"
|
|
/>
|
|
<input
|
|
type="text"
|
|
value={inputUrl}
|
|
onChange={(e) => setInputUrl(e.target.value)}
|
|
placeholder="YouTube URL (https://www.youtube.com/watch?v=...)"
|
|
className="rounded-lg border border-stone-200 bg-stone-50 px-3 py-2 text-xs focus:bg-white focus:outline-none"
|
|
/>
|
|
</div>
|
|
{errorMsg && <p className="text-[11px] text-rose-600">{errorMsg}</p>}
|
|
<div className="flex justify-end gap-2">
|
|
<button
|
|
type="button"
|
|
onClick={() => setIsFormOpen(false)}
|
|
className="cursor-pointer rounded-lg px-3 py-1.5 text-xs text-stone-500 hover:bg-stone-100"
|
|
>
|
|
취소
|
|
</button>
|
|
<button
|
|
type="submit"
|
|
className="cursor-pointer rounded-lg px-4 py-1.5 text-xs font-semibold text-white"
|
|
style={{backgroundColor: template.colors.primary}}
|
|
>
|
|
등록
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
)}
|
|
|
|
{videos.length === 0 ? (
|
|
<EmptyStateNotice>
|
|
등록된 영상이 아직 없습니다. + 버튼으로 추가할 수 있습니다.
|
|
</EmptyStateNotice>
|
|
) : (
|
|
<div className="grid grid-cols-1 gap-5 md:grid-cols-2">
|
|
{videos.map((video) => (
|
|
<VideoCard
|
|
key={video.id}
|
|
video={video}
|
|
isPlaying={playingId === video.id}
|
|
onPlay={() => setPlayingId(video.id)}
|
|
onRemove={() => setRemovedIds((prev) => [...prev, video.id])}
|
|
/>
|
|
))}
|
|
</div>
|
|
)}
|
|
</div>
|
|
</SectionBody>
|
|
|
|
<Lightbox
|
|
photos={items}
|
|
index={openIndex}
|
|
onClose={() => setOpenIndex(null)}
|
|
onMove={setOpenIndex}
|
|
/>
|
|
</SectionFrame>
|
|
);
|
|
}
|