feat: 콘서트 상세 페이지 개선

- 같은 제목의 콘서트 일정을 모아서 회차별로 표시
- 현재 보고 있는 회차 강조 표시
- 카카오맵 SDK 키 수정 및 에러 처리 개선
- 길찾기 버튼 추가
- 회차 전환 시 부드러운 데이터 로딩 (keepPreviousData)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
caadiq 2026-01-15 17:05:33 +09:00
parent 79f3816cec
commit 611a20a8f0
3 changed files with 243 additions and 131 deletions

View file

@ -155,15 +155,29 @@ router.get("/:id", async (req, res) => {
return res.status(404).json({ error: "일정을 찾을 수 없습니다." }); return res.status(404).json({ error: "일정을 찾을 수 없습니다." });
} }
const schedule = schedules[0];
// 이미지 조회 // 이미지 조회
const [images] = await pool.query( const [images] = await pool.query(
`SELECT image_url FROM schedule_images WHERE schedule_id = ? ORDER BY sort_order ASC`, `SELECT image_url FROM schedule_images WHERE schedule_id = ? ORDER BY sort_order ASC`,
[id] [id]
); );
const schedule = schedules[0];
schedule.images = images.map((img) => img.image_url); schedule.images = images.map((img) => img.image_url);
// 콘서트 카테고리(id=6)인 경우 같은 제목의 관련 일정들도 조회
if (schedule.category_id === 6) {
const [relatedSchedules] = await pool.query(
`
SELECT id, date, time
FROM schedules
WHERE title = ? AND category_id = 6
ORDER BY date ASC, time ASC
`,
[schedule.title]
);
schedule.related_dates = relatedSchedules;
}
res.json(schedule); res.json(schedule);
} catch (error) { } catch (error) {
console.error("일정 조회 오류:", error); console.error("일정 조회 오류:", error);

View file

@ -1,2 +1,2 @@
VITE_KAKAO_JS_KEY=5a626e19fbafb33b1eea26f162038ccb VITE_KAKAO_JS_KEY=84b3c657c3de7d1ca89e1fa33455b8da
VITE_KAKAO_REST_KEY=e7a5516bf6cb1b398857789ee2ea6eea VITE_KAKAO_REST_KEY=e7a5516bf6cb1b398857789ee2ea6eea

View file

@ -1,12 +1,12 @@
import { useParams, Link } from 'react-router-dom'; import { useParams, Link } from 'react-router-dom';
import { useQuery } from '@tanstack/react-query'; import { useQuery, keepPreviousData } from '@tanstack/react-query';
import { useEffect, useRef, useState } from 'react'; import { useEffect, useRef, useState } from 'react';
import { motion } from 'framer-motion'; import { motion } from 'framer-motion';
import { Clock, Calendar, ExternalLink, ChevronRight, Link2, MapPin, Navigation } from 'lucide-react'; import { Clock, Calendar, ExternalLink, ChevronRight, Link2, MapPin, Navigation } from 'lucide-react';
import { getSchedule, getXProfile } from '../../../api/public/schedules'; import { getSchedule, getXProfile } from '../../../api/public/schedules';
// SDK // SDK
const KAKAO_MAP_KEY = import.meta.env.VITE_KAKAO_MAP_KEY; const KAKAO_MAP_KEY = import.meta.env.VITE_KAKAO_JS_KEY;
// ID // ID
const CATEGORY_ID = { const CATEGORY_ID = {
@ -317,8 +317,15 @@ function XSection({ schedule }) {
function KakaoMap({ lat, lng, name }) { function KakaoMap({ lat, lng, name }) {
const mapRef = useRef(null); const mapRef = useRef(null);
const [mapLoaded, setMapLoaded] = useState(false); const [mapLoaded, setMapLoaded] = useState(false);
const [mapError, setMapError] = useState(false);
useEffect(() => { useEffect(() => {
// API
if (!KAKAO_MAP_KEY) {
setMapError(true);
return;
}
// SDK // SDK
if (!window.kakao?.maps) { if (!window.kakao?.maps) {
const script = document.createElement('script'); const script = document.createElement('script');
@ -326,6 +333,7 @@ function KakaoMap({ lat, lng, name }) {
script.onload = () => { script.onload = () => {
window.kakao.maps.load(() => setMapLoaded(true)); window.kakao.maps.load(() => setMapLoaded(true));
}; };
script.onerror = () => setMapError(true);
document.head.appendChild(script); document.head.appendChild(script);
} else { } else {
setMapLoaded(true); setMapLoaded(true);
@ -333,8 +341,9 @@ function KakaoMap({ lat, lng, name }) {
}, []); }, []);
useEffect(() => { useEffect(() => {
if (!mapLoaded || !mapRef.current) return; if (!mapLoaded || !mapRef.current || mapError) return;
try {
const position = new window.kakao.maps.LatLng(lat, lng); const position = new window.kakao.maps.LatLng(lat, lng);
const map = new window.kakao.maps.Map(mapRef.current, { const map = new window.kakao.maps.Map(mapRef.current, {
center: position, center: position,
@ -350,16 +359,37 @@ function KakaoMap({ lat, lng, name }) {
// //
if (name) { if (name) {
const infowindow = new window.kakao.maps.InfoWindow({ const infowindow = new window.kakao.maps.InfoWindow({
content: `<div style="padding:5px 10px;font-size:12px;">${name}</div>`, content: `<div style="padding:8px 12px;font-size:13px;font-weight:500;">${name}</div>`,
}); });
infowindow.open(map, marker); infowindow.open(map, marker);
} }
}, [mapLoaded, lat, lng, name]); } catch (e) {
setMapError(true);
}
}, [mapLoaded, lat, lng, name, mapError]);
//
if (mapError) {
return (
<a
href={`https://map.kakao.com/link/to/${encodeURIComponent(name)},${lat},${lng}`}
target="_blank"
rel="noopener noreferrer"
className="block w-full h-80 rounded-2xl bg-gradient-to-br from-gray-100 to-gray-200 flex items-center justify-center hover:from-gray-200 hover:to-gray-300 transition-all group"
>
<div className="text-center">
<Navigation size={32} className="mx-auto text-gray-400 group-hover:text-blue-500 transition-colors mb-2" />
<p className="text-gray-600 font-medium">{name}</p>
<p className="text-sm text-gray-400 mt-1">클릭하여 길찾기</p>
</div>
</a>
);
}
return ( return (
<div <div
ref={mapRef} ref={mapRef}
className="w-full h-64 rounded-xl overflow-hidden" className="w-full h-80 rounded-2xl overflow-hidden shadow-inner"
/> />
); );
} }
@ -367,75 +397,113 @@ function KakaoMap({ lat, lng, name }) {
// //
function ConcertSection({ schedule }) { function ConcertSection({ schedule }) {
const hasLocation = schedule.location_lat && schedule.location_lng; const hasLocation = schedule.location_lat && schedule.location_lng;
const hasPoster = schedule.images?.length > 0;
const relatedDates = schedule.related_dates || [];
const hasMultipleDates = relatedDates.length > 1;
// //
const formatDateRange = () => { const formatSingleDate = (dateStr, timeStr) => {
const start = formatFullDate(schedule.date); const date = new Date(dateStr);
if (schedule.end_date && schedule.end_date !== schedule.date) { const dayNames = ['일', '월', '화', '수', '목', '금', '토'];
const end = formatFullDate(schedule.end_date); const month = date.getMonth() + 1;
return `${start} ~ ${end}`; const day = date.getDate();
const weekday = dayNames[date.getDay()];
let result = `${month}${day}일 (${weekday})`;
if (timeStr) {
result += ` ${timeStr.slice(0, 5)}`;
} }
return start; return result;
}; };
return ( return (
<div className="space-y-6"> <div className="space-y-8">
{/* 상단: 포스터 + 정보 카드 (가로 배치) */}
<div className={`flex gap-8 ${hasPoster ? '' : 'justify-center'}`}>
{/* 포스터 이미지 */} {/* 포스터 이미지 */}
{schedule.images?.length > 0 && ( {hasPoster && (
<motion.div <motion.div
initial={{ opacity: 0, scale: 0.98 }} initial={{ opacity: 0, x: -20 }}
animate={{ opacity: 1, scale: 1 }} animate={{ opacity: 1, x: 0 }}
transition={{ delay: 0.1 }} transition={{ delay: 0.1 }}
className="flex justify-center" className="flex-shrink-0"
> >
<div className="relative group">
<img <img
src={schedule.images[0]} src={schedule.images[0]}
alt={schedule.title} alt={schedule.title}
className="max-w-md w-full rounded-2xl shadow-lg" className="w-80 rounded-2xl shadow-2xl shadow-black/20"
/> />
<div className="absolute inset-0 bg-black/0 group-hover:bg-black/10 rounded-2xl transition-colors" />
</div>
</motion.div> </motion.div>
)} )}
{/* 콘서트 정보 카드 */} {/* 정보 카드 */}
<motion.div <motion.div
initial={{ opacity: 0, y: 10 }} initial={{ opacity: 0, x: hasPoster ? 20 : 0, y: hasPoster ? 0 : 20 }}
animate={{ opacity: 1, y: 0 }} animate={{ opacity: 1, x: 0, y: 0 }}
transition={{ delay: 0.2 }} transition={{ delay: 0.2 }}
className="bg-white rounded-2xl border border-gray-200 overflow-hidden" className={`flex-1 ${hasPoster ? '' : 'max-w-xl'}`}
> >
{/* 제목 */} <div className="bg-white rounded-3xl shadow-xl shadow-black/5 overflow-hidden h-full flex flex-col">
<div className="p-6 border-b border-gray-100"> {/* 헤더 */}
<h1 className="text-2xl font-bold text-gray-900"> <div className="bg-gradient-to-r from-primary to-primary/80 p-6 text-white">
<h1 className="text-2xl font-bold leading-tight">
{decodeHtmlEntities(schedule.title)} {decodeHtmlEntities(schedule.title)}
</h1> </h1>
</div> </div>
{/* 정보 목록 */} {/* 정보 목록 */}
<div className="p-6 space-y-4"> <div className="p-6 space-y-5 flex-1">
{/* 날짜 */} {/* 공연 일정 목록 */}
<div className="flex items-start gap-3"> <div className="flex items-start gap-4">
<Calendar size={20} className="text-gray-400 mt-0.5 flex-shrink-0" /> <div className="w-12 h-12 rounded-2xl bg-primary/10 flex items-center justify-center flex-shrink-0">
<Calendar size={22} className="text-primary" />
</div>
<div className="flex-1">
{hasMultipleDates ? (
<div className="space-y-2">
{relatedDates.map((item, index) => {
const isCurrentDate = item.id === schedule.id;
return (
<Link
key={item.id}
to={`/schedule/${item.id}`}
className={`block px-4 py-2.5 rounded-xl transition-all ${
isCurrentDate
? 'bg-primary text-white font-bold shadow-lg shadow-primary/20'
: 'bg-gray-50 hover:bg-gray-100 text-gray-700'
}`}
>
<span className="text-sm opacity-60 mr-2">
{index + 1}회차
</span>
{formatSingleDate(item.date, item.time)}
</Link>
);
})}
</div>
) : (
<div> <div>
<p className="text-sm text-gray-500">일시</p> <p className="text-gray-900 font-bold text-lg">
<p className="text-gray-900 font-medium">{formatDateRange()}</p> {formatSingleDate(schedule.date, schedule.time)}
{schedule.time && ( </p>
<p className="text-gray-600">{formatTime(schedule.time)} 시작</p> </div>
)} )}
</div> </div>
</div> </div>
{/* 장소 */} {/* 장소 */}
{schedule.location_name && ( {schedule.location_name && (
<div className="flex items-start gap-3"> <div className="flex items-center gap-4">
<MapPin size={20} className="text-gray-400 mt-0.5 flex-shrink-0" /> <div className="w-12 h-12 rounded-2xl bg-rose-50 flex items-center justify-center flex-shrink-0">
<div> <MapPin size={22} className="text-rose-500" />
<p className="text-sm text-gray-500">장소</p> </div>
<p className="text-gray-900 font-medium">{schedule.location_name}</p> <div className="flex-1 min-w-0">
<p className="text-gray-900 font-bold text-lg truncate">{schedule.location_name}</p>
{schedule.location_address && ( {schedule.location_address && (
<p className="text-gray-600 text-sm">{schedule.location_address}</p> <p className="text-gray-500 text-sm truncate">{schedule.location_address}</p>
)}
{schedule.location_detail && (
<p className="text-gray-500 text-sm">{schedule.location_detail}</p>
)} )}
</div> </div>
</div> </div>
@ -444,60 +512,89 @@ function ConcertSection({ schedule }) {
{/* 설명 */} {/* 설명 */}
{schedule.description && ( {schedule.description && (
<div className="pt-4 border-t border-gray-100"> <div className="pt-4 border-t border-gray-100">
<p className="text-gray-700 whitespace-pre-wrap leading-relaxed"> <p className="text-gray-600 text-sm leading-relaxed line-clamp-4">
{decodeHtmlEntities(schedule.description)} {decodeHtmlEntities(schedule.description)}
</p> </p>
</div> </div>
)} )}
</div> </div>
{/* 카카오맵 또는 장소 정보 */} {/* 버튼 영역 */}
{schedule.location_name && ( {schedule.source_url && (
<div className="border-t border-gray-100"> <div className="p-6 pt-0">
{hasLocation ? ( <a
<div className="p-4"> href={schedule.source_url}
target="_blank"
rel="noopener noreferrer"
className="w-full inline-flex items-center justify-center gap-2 px-6 py-3.5 bg-gray-900 hover:bg-black text-white rounded-2xl font-semibold transition-all hover:shadow-lg"
>
<ExternalLink size={18} />
상세 정보 보기
</a>
</div>
)}
</div>
</motion.div>
</div>
{/* 하단: 지도 */}
{schedule.location_name && hasLocation && (
<motion.div
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
transition={{ delay: 0.3 }}
className="bg-white rounded-3xl shadow-xl shadow-black/5 overflow-hidden"
>
<div className="p-5 border-b border-gray-100 flex items-center justify-between">
<div className="flex items-center gap-3">
<div className="w-10 h-10 rounded-xl bg-blue-50 flex items-center justify-center">
<Navigation size={18} className="text-blue-500" />
</div>
<div>
<h3 className="font-bold text-gray-900">위치 안내</h3>
<p className="text-sm text-gray-500">{schedule.location_name}</p>
</div>
</div>
<a
href={`https://map.kakao.com/link/to/${encodeURIComponent(schedule.location_name)},${schedule.location_lat},${schedule.location_lng}`}
target="_blank"
rel="noopener noreferrer"
className="inline-flex items-center gap-2 px-4 py-2 text-sm font-medium text-white bg-blue-500 hover:bg-blue-600 rounded-xl transition-colors"
>
<Navigation size={14} />
길찾기
</a>
</div>
<div className="p-5">
<KakaoMap <KakaoMap
lat={parseFloat(schedule.location_lat)} lat={parseFloat(schedule.location_lat)}
lng={parseFloat(schedule.location_lng)} lng={parseFloat(schedule.location_lng)}
name={schedule.location_name} name={schedule.location_name}
/> />
<a
href={`https://map.kakao.com/link/map/${encodeURIComponent(schedule.location_name)},${schedule.location_lat},${schedule.location_lng}`}
target="_blank"
rel="noopener noreferrer"
className="mt-3 inline-flex items-center gap-2 text-sm text-blue-600 hover:text-blue-700"
>
<Navigation size={14} />
카카오맵에서 길찾기
</a>
</div>
) : (
<div className="p-6 bg-gray-50 text-center">
<MapPin size={24} className="mx-auto text-gray-400 mb-2" />
<p className="text-gray-600">{schedule.location_name}</p>
{schedule.location_address && (
<p className="text-sm text-gray-500">{schedule.location_address}</p>
)}
</div>
)}
</div> </div>
</motion.div>
)} )}
{/* 원본 링크 */} {/* 해외 공연 등 좌표 없는 경우 */}
{schedule.source_url && ( {schedule.location_name && !hasLocation && (
<div className="p-6 border-t border-gray-100 bg-gray-50/50"> <motion.div
<a initial={{ opacity: 0, y: 20 }}
href={schedule.source_url} animate={{ opacity: 1, y: 0 }}
target="_blank" transition={{ delay: 0.3 }}
rel="noopener noreferrer" className="bg-gradient-to-br from-gray-50 to-gray-100 rounded-3xl p-8 text-center"
className="inline-flex items-center gap-2 px-5 py-2.5 bg-primary hover:bg-primary-dark text-white rounded-xl font-medium transition-colors"
> >
<ExternalLink size={16} /> <div className="w-16 h-16 rounded-full bg-white shadow-lg mx-auto mb-4 flex items-center justify-center">
상세 정보 보기 <MapPin size={28} className="text-gray-400" />
</a>
</div> </div>
<p className="text-xl font-bold text-gray-800 mb-1">{schedule.location_name}</p>
{schedule.location_address && (
<p className="text-gray-500">{schedule.location_address}</p>
)}
{schedule.location_detail && (
<p className="text-sm text-gray-400 mt-2">{schedule.location_detail}</p>
)} )}
</motion.div> </motion.div>
)}
</div> </div>
); );
} }
@ -553,9 +650,10 @@ function DefaultSection({ schedule }) {
function ScheduleDetail() { function ScheduleDetail() {
const { id } = useParams(); const { id } = useParams();
const { data: schedule, isLoading, error } = useQuery({ const { data: schedule, isLoading, error, isFetching } = useQuery({
queryKey: ['schedule', id], queryKey: ['schedule', id],
queryFn: () => getSchedule(id), queryFn: () => getSchedule(id),
placeholderData: keepPreviousData,
}); });
if (isLoading) { if (isLoading) {
@ -604,7 +702,7 @@ function ScheduleDetail() {
return ( return (
<div className="min-h-[calc(100vh-64px)] bg-gray-50"> <div className="min-h-[calc(100vh-64px)] bg-gray-50">
<div className={`${isYoutube ? 'max-w-5xl' : 'max-w-3xl'} mx-auto px-6 py-8`}> <div className={`${isYoutube || isConcert ? 'max-w-5xl' : 'max-w-3xl'} mx-auto px-6 py-8`}>
{/* 브레드크럼 네비게이션 */} {/* 브레드크럼 네비게이션 */}
<motion.div <motion.div
initial={{ opacity: 0, y: -10 }} initial={{ opacity: 0, y: -10 }}