모바일 일정 상세 페이지 구현 (유튜브 섹션)

- 모바일 일정 상세 페이지 기본 구조 구현
- 유튜브 섹션: 일반 영상/숏츠 구분 렌더링
- 전체화면 시 가로 회전 (숏츠 제외)
- 일정 목록에서 상세 페이지로 이동 클릭 이벤트 추가
- mobile-layout 클래스 시스템으로 스크롤바 숨김 처리
- zustand store로 날짜 상태 유지

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
caadiq 2026-01-15 20:57:55 +09:00
parent f51a3f754a
commit e4859471ba
2 changed files with 305 additions and 26 deletions

View file

@ -8,6 +8,7 @@ import { useVirtualizer } from '@tanstack/react-virtual';
import confetti from 'canvas-confetti';
import { getTodayKST } from '../../../utils/date';
import { getSchedules, getCategories, searchSchedules } from '../../../api/public/schedules';
import useScheduleStore from '../../../stores/useScheduleStore';
//
const fireBirthdayConfetti = () => {
@ -121,7 +122,17 @@ function MobileBirthdayCard({ schedule, onClick, delay = 0 }) {
//
function MobileSchedule() {
const navigate = useNavigate();
const [selectedDate, setSelectedDate] = useState(new Date());
// zustand store
const {
selectedDate: storedSelectedDate,
setSelectedDate: setStoredSelectedDate,
} = useScheduleStore();
// (store )
const selectedDate = storedSelectedDate || new Date();
const setSelectedDate = (date) => setStoredSelectedDate(date);
const [isSearchMode, setIsSearchMode] = useState(false);
const [searchInput, setSearchInput] = useState(''); //
const [searchTerm, setSearchTerm] = useState(''); //
@ -442,19 +453,20 @@ function MobileSchedule() {
// ref
const dateScrollRef = useRef(null);
// +
//
useEffect(() => {
//
window.scrollTo(0, 0);
if (dateScrollRef.current) {
//
if (!isSearchMode && dateScrollRef.current) {
const selectedDay = selectedDate.getDate();
const buttons = dateScrollRef.current.querySelectorAll('button');
if (buttons[selectedDay - 1]) {
// (DOM )
setTimeout(() => {
buttons[selectedDay - 1].scrollIntoView({ behavior: 'smooth', inline: 'center', block: 'nearest' });
}, 50);
}
}
}, [selectedDate]);
}, [selectedDate, isSearchMode]);
return (
<>
@ -827,6 +839,7 @@ function MobileSchedule() {
schedule={schedule}
categoryColor={getCategoryColor(schedule.category_id)}
categories={categories}
onClick={() => navigate(`/schedule/${schedule.id}`)}
/>
</div>
</div>
@ -879,6 +892,7 @@ function MobileSchedule() {
categoryColor={getCategoryColor(schedule.category_id)}
categories={categories}
delay={index * 0.05}
onClick={() => navigate(`/schedule/${schedule.id}`)}
/>
);
})}
@ -891,7 +905,7 @@ function MobileSchedule() {
}
// () -
function ScheduleCard({ schedule, categoryColor, categories, delay = 0 }) {
function ScheduleCard({ schedule, categoryColor, categories, delay = 0, onClick }) {
const categoryName = categories.find(c => c.id === schedule.category_id)?.name || '미분류';
const memberNames = schedule.member_names || schedule.members?.map(m => m.name).join(',') || '';
const memberList = memberNames.split(',').filter(name => name.trim());
@ -917,9 +931,11 @@ function ScheduleCard({ schedule, categoryColor, categories, delay = 0 }) {
initial={{ opacity: 0, y: 10 }}
animate={{ opacity: 1, y: 0 }}
transition={{ delay, type: "spring", stiffness: 300, damping: 30 }}
onClick={onClick}
className="cursor-pointer"
>
{/* 카드 본체 */}
<div className="relative bg-white rounded-md shadow-[0_2px_12px_rgba(0,0,0,0.06)] border border-gray-100/50 overflow-hidden">
<div className="relative bg-white rounded-md shadow-[0_2px_12px_rgba(0,0,0,0.06)] border border-gray-100/50 overflow-hidden active:bg-gray-50 transition-colors">
<div className="flex">
{/* 왼쪽 날짜 영역 */}
{dateInfo && (
@ -999,7 +1015,7 @@ function ScheduleCard({ schedule, categoryColor, categories, delay = 0 }) {
}
// -
function TimelineScheduleCard({ schedule, categoryColor, categories, delay = 0 }) {
function TimelineScheduleCard({ schedule, categoryColor, categories, delay = 0, onClick }) {
const categoryName = categories.find(c => c.id === schedule.category_id)?.name || '미분류';
const memberNames = schedule.member_names || schedule.members?.map(m => m.name).join(',') || '';
const memberList = memberNames.split(',').filter(name => name.trim());
@ -1009,9 +1025,11 @@ function TimelineScheduleCard({ schedule, categoryColor, categories, delay = 0 }
initial={{ opacity: 0, x: -10 }}
animate={{ opacity: 1, x: 0 }}
transition={{ delay, type: "spring", stiffness: 300, damping: 30 }}
onClick={onClick}
className="cursor-pointer"
>
{/* 카드 본체 */}
<div className="relative bg-white rounded-md shadow-[0_2px_12px_rgba(0,0,0,0.06)] border border-gray-100/50 overflow-hidden">
<div className="relative bg-white rounded-md shadow-[0_2px_12px_rgba(0,0,0,0.06)] border border-gray-100/50 overflow-hidden active:bg-gray-50 transition-colors">
<div className="p-4">
{/* 시간 뱃지 */}

View file

@ -1,12 +1,238 @@
import { useParams, Link } from 'react-router-dom';
import { useQuery } from '@tanstack/react-query';
import { useEffect } from 'react';
import { motion } from 'framer-motion';
import { Calendar, ChevronLeft } from 'lucide-react';
import { getSchedule } from '../../../api/public/schedules';
import { Calendar, Clock, ChevronLeft, Link2 } from 'lucide-react';
import { getSchedule, getXProfile } from '../../../api/public/schedules';
import '../../../mobile.css';
// ( )
function useFullscreenOrientation(isShorts) {
useEffect(() => {
//
if (isShorts) return;
const handleFullscreenChange = async () => {
const isFullscreen = !!document.fullscreenElement;
if (isFullscreen) {
//
try {
if (screen.orientation && screen.orientation.lock) {
await screen.orientation.lock('landscape');
}
} catch (e) {
//
}
} else {
//
try {
if (screen.orientation && screen.orientation.unlock) {
screen.orientation.unlock();
}
} catch (e) {
//
}
}
};
document.addEventListener('fullscreenchange', handleFullscreenChange);
document.addEventListener('webkitfullscreenchange', handleFullscreenChange);
return () => {
document.removeEventListener('fullscreenchange', handleFullscreenChange);
document.removeEventListener('webkitfullscreenchange', handleFullscreenChange);
};
}, [isShorts]);
}
// ID
const CATEGORY_ID = {
YOUTUBE: 2,
X: 3,
ALBUM: 4,
FANSIGN: 5,
CONCERT: 6,
TICKET: 7,
};
// HTML
const decodeHtmlEntities = (text) => {
if (!text) return '';
const textarea = document.createElement('textarea');
textarea.innerHTML = text;
return textarea.value;
};
// ID
const extractYoutubeVideoId = (url) => {
if (!url) return null;
const shortMatch = url.match(/youtu\.be\/([a-zA-Z0-9_-]{11})/);
if (shortMatch) return shortMatch[1];
const watchMatch = url.match(/youtube\.com\/watch\?v=([a-zA-Z0-9_-]{11})/);
if (watchMatch) return watchMatch[1];
const shortsMatch = url.match(/youtube\.com\/shorts\/([a-zA-Z0-9_-]{11})/);
if (shortsMatch) return shortsMatch[1];
return null;
};
//
const formatFullDate = (dateStr) => {
if (!dateStr) return '';
const date = new Date(dateStr);
const dayNames = ['일', '월', '화', '수', '목', '금', '토'];
return `${date.getFullYear()}. ${date.getMonth() + 1}. ${date.getDate()}. (${dayNames[date.getDay()]})`;
};
//
const formatTime = (timeStr) => {
if (!timeStr) return null;
return timeStr.slice(0, 5);
};
//
function YoutubeSection({ schedule }) {
const videoId = extractYoutubeVideoId(schedule.source_url);
const isShorts = schedule.source_url?.includes('/shorts/');
// ( )
useFullscreenOrientation(isShorts);
const members = schedule.members || [];
const isFullGroup = members.length === 5;
if (!videoId) return null;
return (
<div className="space-y-4">
{/* 영상 임베드 */}
<motion.div
initial={{ opacity: 0, scale: 0.98 }}
animate={{ opacity: 1, scale: 1 }}
transition={{ delay: 0.1 }}
>
<div
className={`relative bg-gray-900 rounded-xl overflow-hidden shadow-lg ${
isShorts ? 'aspect-[9/16] max-w-[280px] mx-auto' : 'aspect-video'
}`}
>
<iframe
src={`https://www.youtube.com/embed/${videoId}?rel=0`}
title={schedule.title}
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; fullscreen; web-share"
allowFullScreen
className="absolute inset-0 w-full h-full"
/>
</div>
</motion.div>
{/* 영상 정보 카드 */}
<motion.div
initial={{ opacity: 0, y: 10 }}
animate={{ opacity: 1, y: 0 }}
transition={{ delay: 0.2 }}
className="bg-white rounded-xl p-4 shadow-sm"
>
{/* 제목 */}
<h1 className="font-bold text-gray-900 text-base leading-relaxed mb-3">
{decodeHtmlEntities(schedule.title)}
</h1>
{/* 메타 정보 */}
<div className="flex flex-wrap items-center gap-3 text-xs text-gray-500 mb-3">
<div className="flex items-center gap-1">
<Calendar size={12} />
<span>{formatFullDate(schedule.date)}</span>
</div>
{schedule.time && (
<div className="flex items-center gap-1">
<Clock size={12} />
<span>{formatTime(schedule.time)}</span>
</div>
)}
{schedule.source_name && (
<div className="flex items-center gap-1">
<Link2 size={12} />
<span>{schedule.source_name}</span>
</div>
)}
</div>
{/* 멤버 목록 */}
{members.length > 0 && (
<div className="flex flex-wrap gap-1.5 mb-4">
{isFullGroup ? (
<span className="px-2.5 py-1 bg-primary/10 text-primary text-xs font-medium rounded-full">
프로미스나인
</span>
) : (
members.map((member) => (
<span
key={member.id}
className="px-2.5 py-1 bg-primary/10 text-primary text-xs font-medium rounded-full"
>
{member.name}
</span>
))
)}
</div>
)}
{/* 유튜브에서 보기 버튼 */}
<a
href={schedule.source_url}
target="_blank"
rel="noopener noreferrer"
className="flex items-center justify-center gap-2 w-full py-3 bg-red-500 active:bg-red-600 text-white rounded-xl font-medium transition-colors"
>
<svg className="w-5 h-5" viewBox="0 0 24 24" fill="currentColor">
<path d="M23.498 6.186a3.016 3.016 0 0 0-2.122-2.136C19.505 3.545 12 3.545 12 3.545s-7.505 0-9.377.505A3.017 3.017 0 0 0 .502 6.186C0 8.07 0 12 0 12s0 3.93.502 5.814a3.016 3.016 0 0 0 2.122 2.136c1.871.505 9.376.505 9.376.505s7.505 0 9.377-.505a3.015 3.015 0 0 0 2.122-2.136C24 15.93 24 12 24 12s0-3.93-.502-5.814zM9.545 15.568V8.432L15.818 12l-6.273 3.568z"/>
</svg>
YouTube에서 보기
</a>
</motion.div>
</div>
);
}
// ( - )
function DefaultSection({ schedule }) {
return (
<div className="bg-white rounded-xl p-4 shadow-sm">
<h1 className="font-bold text-gray-900 text-base mb-3">
{decodeHtmlEntities(schedule.title)}
</h1>
<div className="flex items-center gap-3 text-xs text-gray-500">
<div className="flex items-center gap-1">
<Calendar size={12} />
<span>{formatFullDate(schedule.date)}</span>
</div>
{schedule.time && (
<div className="flex items-center gap-1">
<Clock size={12} />
<span>{formatTime(schedule.time)}</span>
</div>
)}
</div>
{schedule.description && (
<p className="mt-3 text-sm text-gray-600 whitespace-pre-wrap">
{decodeHtmlEntities(schedule.description)}
</p>
)}
</div>
);
}
function MobileScheduleDetail() {
const { id } = useParams();
//
useEffect(() => {
document.documentElement.classList.add('mobile-layout');
return () => {
document.documentElement.classList.remove('mobile-layout');
};
}, []);
const { data: schedule, isLoading, error } = useQuery({
queryKey: ['schedule', id],
queryFn: () => getSchedule(id),
@ -15,15 +241,18 @@ function MobileScheduleDetail() {
if (isLoading) {
return (
<div className="min-h-screen flex items-center justify-center bg-gray-50">
<div className="mobile-layout-container bg-gray-50">
<div className="mobile-content flex items-center justify-center">
<div className="w-8 h-8 border-2 border-primary border-t-transparent rounded-full animate-spin" />
</div>
</div>
);
}
if (error || !schedule) {
return (
<div className="min-h-screen flex items-center justify-center bg-gradient-to-br from-gray-50 to-gray-100 px-6">
<div className="mobile-layout-container bg-gradient-to-br from-gray-50 to-gray-100">
<div className="mobile-content flex items-center justify-center px-6">
<div className="text-center">
{/* 아이콘 */}
<motion.div
@ -103,14 +332,46 @@ function MobileScheduleDetail() {
</motion.div>
</div>
</div>
</div>
);
}
// TODO:
//
const renderCategorySection = () => {
switch (schedule.category_id) {
case CATEGORY_ID.YOUTUBE:
return <YoutubeSection schedule={schedule} />;
default:
return <DefaultSection schedule={schedule} />;
}
};
return (
<div className="min-h-screen bg-gray-50 p-4">
<div className="text-center py-8 text-gray-500">
일정 상세 페이지 준비
<div className="mobile-layout-container bg-gray-50">
{/* 헤더 */}
<div className="flex-shrink-0 bg-white border-b border-gray-100">
<div className="flex items-center h-14 px-4">
<button
onClick={() => window.history.back()}
className="p-2 -ml-2 rounded-lg active:bg-gray-100"
>
<ChevronLeft size={24} />
</button>
<div className="flex-1 text-center">
<span
className="text-sm font-medium"
style={{ color: schedule.category_color }}
>
{schedule.category_name}
</span>
</div>
<div className="w-10" />
</div>
</div>
{/* 메인 컨텐츠 */}
<div className="mobile-content p-4">
{renderCategorySection()}
</div>
</div>
);