일정 상세 페이지에서 콘서트 섹션 제거
- PC: ConcertSection.jsx, KakaoMap.jsx 삭제 - 모바일: ConcertSection, KakaoMap 컴포넌트 제거 - CATEGORY_ID에서 콘서트 관련 상수 제거 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
9eb49929c7
commit
2b24bfe0a7
6 changed files with 3 additions and 909 deletions
|
|
@ -2,90 +2,12 @@ import { useParams, Link } from 'react-router-dom';
|
||||||
import { useQuery, keepPreviousData } from '@tanstack/react-query';
|
import { useQuery, keepPreviousData } from '@tanstack/react-query';
|
||||||
import { useEffect, useState, useRef } from 'react';
|
import { useEffect, useState, useRef } from 'react';
|
||||||
import { motion, AnimatePresence } from 'framer-motion';
|
import { motion, AnimatePresence } from 'framer-motion';
|
||||||
import { Calendar, Clock, ChevronLeft, Check, Link2, MapPin, Navigation, ExternalLink, X, ChevronRight } from 'lucide-react';
|
import { Calendar, Clock, ChevronLeft, Link2, X, ChevronRight } from 'lucide-react';
|
||||||
import Linkify from 'react-linkify';
|
import Linkify from 'react-linkify';
|
||||||
import { getSchedule } from '../../../api/public/schedules';
|
import { getSchedule } from '../../../api/public/schedules';
|
||||||
import { formatXDateTime } from '../../../utils/date';
|
import { formatXDateTime } from '../../../utils/date';
|
||||||
import '../../../mobile.css';
|
import '../../../mobile.css';
|
||||||
|
|
||||||
// 카카오맵 SDK 키
|
|
||||||
const KAKAO_MAP_KEY = import.meta.env.VITE_KAKAO_JS_KEY;
|
|
||||||
|
|
||||||
// 카카오맵 컴포넌트
|
|
||||||
function KakaoMap({ lat, lng, name }) {
|
|
||||||
const mapRef = useRef(null);
|
|
||||||
const [mapLoaded, setMapLoaded] = useState(false);
|
|
||||||
const [mapError, setMapError] = useState(false);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!KAKAO_MAP_KEY) {
|
|
||||||
setMapError(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!window.kakao?.maps) {
|
|
||||||
const script = document.createElement('script');
|
|
||||||
script.src = `//dapi.kakao.com/v2/maps/sdk.js?appkey=${KAKAO_MAP_KEY}&autoload=false`;
|
|
||||||
script.onload = () => {
|
|
||||||
window.kakao.maps.load(() => setMapLoaded(true));
|
|
||||||
};
|
|
||||||
script.onerror = () => setMapError(true);
|
|
||||||
document.head.appendChild(script);
|
|
||||||
} else {
|
|
||||||
setMapLoaded(true);
|
|
||||||
}
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!mapLoaded || !mapRef.current || mapError) return;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const position = new window.kakao.maps.LatLng(lat, lng);
|
|
||||||
const map = new window.kakao.maps.Map(mapRef.current, {
|
|
||||||
center: position,
|
|
||||||
level: 3,
|
|
||||||
});
|
|
||||||
|
|
||||||
const marker = new window.kakao.maps.Marker({
|
|
||||||
position,
|
|
||||||
map,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (name) {
|
|
||||||
const infowindow = new window.kakao.maps.InfoWindow({
|
|
||||||
content: `<div style="padding:6px 10px;font-size:12px;font-weight:500;">${name}</div>`,
|
|
||||||
});
|
|
||||||
infowindow.open(map, marker);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
setMapError(true);
|
|
||||||
}
|
|
||||||
}, [mapLoaded, lat, lng, name, mapError]);
|
|
||||||
|
|
||||||
if (mapError) {
|
|
||||||
return (
|
|
||||||
<a
|
|
||||||
href={`https://map.kakao.com/link/map/${encodeURIComponent(name)},${lat},${lng}`}
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
className="block w-full h-40 rounded-xl bg-gray-100 flex items-center justify-center active:bg-gray-200 transition-colors"
|
|
||||||
>
|
|
||||||
<div className="text-center">
|
|
||||||
<Navigation size={24} className="mx-auto text-gray-400 mb-1" />
|
|
||||||
<p className="text-xs text-gray-500">지도에서 보기</p>
|
|
||||||
</div>
|
|
||||||
</a>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
ref={mapRef}
|
|
||||||
className="w-full h-40 rounded-xl overflow-hidden"
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 전체화면 시 자동 가로 회전 훅 (숏츠가 아닐 때만)
|
// 전체화면 시 자동 가로 회전 훅 (숏츠가 아닐 때만)
|
||||||
function useFullscreenOrientation(isShorts) {
|
function useFullscreenOrientation(isShorts) {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -130,10 +52,6 @@ function useFullscreenOrientation(isShorts) {
|
||||||
const CATEGORY_ID = {
|
const CATEGORY_ID = {
|
||||||
YOUTUBE: 2,
|
YOUTUBE: 2,
|
||||||
X: 3,
|
X: 3,
|
||||||
ALBUM: 4,
|
|
||||||
FANSIGN: 5,
|
|
||||||
CONCERT: 6,
|
|
||||||
TICKET: 7,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// HTML 엔티티 디코딩 함수
|
// HTML 엔티티 디코딩 함수
|
||||||
|
|
@ -158,13 +76,6 @@ const formatTime = (timeStr) => {
|
||||||
return timeStr.slice(0, 5);
|
return timeStr.slice(0, 5);
|
||||||
};
|
};
|
||||||
|
|
||||||
// X URL에서 username 추출
|
|
||||||
const extractXUsername = (url) => {
|
|
||||||
if (!url) return null;
|
|
||||||
const match = url.match(/(?:twitter\.com|x\.com)\/([^/]+)/);
|
|
||||||
return match ? match[1] : null;
|
|
||||||
};
|
|
||||||
|
|
||||||
// 유튜브 섹션 컴포넌트
|
// 유튜브 섹션 컴포넌트
|
||||||
function YoutubeSection({ schedule }) {
|
function YoutubeSection({ schedule }) {
|
||||||
const videoId = schedule.videoId;
|
const videoId = schedule.videoId;
|
||||||
|
|
@ -511,334 +422,6 @@ function XSection({ schedule }) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 콘서트 섹션 컴포넌트
|
|
||||||
function ConcertSection({ schedule }) {
|
|
||||||
// 현재 선택된 회차 ID (내부 state로 관리 - URL 변경 없음)
|
|
||||||
const [selectedDateId, setSelectedDateId] = useState(schedule.id);
|
|
||||||
// 다이얼로그 열림 상태
|
|
||||||
const [isDialogOpen, setIsDialogOpen] = useState(false);
|
|
||||||
// 다이얼로그 목록 ref (자동 스크롤용)
|
|
||||||
const listRef = useRef(null);
|
|
||||||
const selectedItemRef = useRef(null);
|
|
||||||
|
|
||||||
// 표시할 데이터 state (변경된 부분만 업데이트)
|
|
||||||
const [displayData, setDisplayData] = useState({
|
|
||||||
posterUrl: schedule.images?.[0] || null,
|
|
||||||
title: schedule.title,
|
|
||||||
date: schedule.date,
|
|
||||||
time: schedule.time,
|
|
||||||
locationName: schedule.location_name,
|
|
||||||
locationAddress: schedule.location_address,
|
|
||||||
locationLat: schedule.location_lat,
|
|
||||||
locationLng: schedule.location_lng,
|
|
||||||
description: schedule.description,
|
|
||||||
sourceUrl: schedule.source?.url,
|
|
||||||
});
|
|
||||||
|
|
||||||
// 선택된 회차 데이터 조회
|
|
||||||
const { data: selectedSchedule } = useQuery({
|
|
||||||
queryKey: ['schedule', selectedDateId],
|
|
||||||
queryFn: () => getSchedule(selectedDateId),
|
|
||||||
placeholderData: keepPreviousData,
|
|
||||||
enabled: selectedDateId !== schedule.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
// 데이터 비교 후 변경된 부분만 업데이트
|
|
||||||
useEffect(() => {
|
|
||||||
const newData = selectedDateId === schedule.id ? schedule : selectedSchedule;
|
|
||||||
if (!newData) return;
|
|
||||||
|
|
||||||
setDisplayData(prev => {
|
|
||||||
const updates = {};
|
|
||||||
const newPosterUrl = newData.images?.[0] || null;
|
|
||||||
|
|
||||||
if (prev.posterUrl !== newPosterUrl) updates.posterUrl = newPosterUrl;
|
|
||||||
if (prev.title !== newData.title) updates.title = newData.title;
|
|
||||||
if (prev.date !== newData.date) updates.date = newData.date;
|
|
||||||
if (prev.time !== newData.time) updates.time = newData.time;
|
|
||||||
if (prev.locationName !== newData.location_name) updates.locationName = newData.location_name;
|
|
||||||
if (prev.locationAddress !== newData.location_address) updates.locationAddress = newData.location_address;
|
|
||||||
if (prev.locationLat !== newData.location_lat) updates.locationLat = newData.location_lat;
|
|
||||||
if (prev.locationLng !== newData.location_lng) updates.locationLng = newData.location_lng;
|
|
||||||
if (prev.description !== newData.description) updates.description = newData.description;
|
|
||||||
if (prev.sourceUrl !== newData.source?.url) updates.sourceUrl = newData.source?.url;
|
|
||||||
|
|
||||||
// 변경된 것이 있을 때만 업데이트
|
|
||||||
if (Object.keys(updates).length > 0) {
|
|
||||||
return { ...prev, ...updates };
|
|
||||||
}
|
|
||||||
return prev;
|
|
||||||
});
|
|
||||||
}, [selectedDateId, schedule, selectedSchedule]);
|
|
||||||
|
|
||||||
// 다이얼로그 열릴 때 선택된 항목으로 스크롤
|
|
||||||
useEffect(() => {
|
|
||||||
if (isDialogOpen && selectedItemRef.current) {
|
|
||||||
setTimeout(() => {
|
|
||||||
selectedItemRef.current?.scrollIntoView({ block: 'center', behavior: 'instant' });
|
|
||||||
}, 50);
|
|
||||||
}
|
|
||||||
}, [isDialogOpen]);
|
|
||||||
|
|
||||||
const relatedDates = schedule.related_dates || [];
|
|
||||||
const hasMultipleDates = relatedDates.length > 1;
|
|
||||||
const hasLocation = displayData.locationLat && displayData.locationLng;
|
|
||||||
|
|
||||||
// 현재 선택된 회차 인덱스
|
|
||||||
const selectedIndex = relatedDates.findIndex(d => d.id === selectedDateId);
|
|
||||||
|
|
||||||
// 회차 선택 핸들러
|
|
||||||
const handleSelectDate = (id) => {
|
|
||||||
setSelectedDateId(id);
|
|
||||||
setIsDialogOpen(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
// 개별 날짜 포맷팅
|
|
||||||
const formatSingleDate = (dateStr, timeStr) => {
|
|
||||||
const date = new Date(dateStr);
|
|
||||||
const dayNames = ['일', '월', '화', '수', '목', '금', '토'];
|
|
||||||
const month = date.getMonth() + 1;
|
|
||||||
const day = date.getDate();
|
|
||||||
const weekday = dayNames[date.getDay()];
|
|
||||||
|
|
||||||
let result = `${month}월 ${day}일 (${weekday})`;
|
|
||||||
if (timeStr) {
|
|
||||||
result += ` ${timeStr.slice(0, 5)}`;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<div className="-mx-4 -mt-4">
|
|
||||||
{/* 히어로 헤더 */}
|
|
||||||
<div className="relative overflow-hidden">
|
|
||||||
{/* 배경 블러 이미지 */}
|
|
||||||
{displayData.posterUrl ? (
|
|
||||||
<div className="absolute inset-0 scale-110 overflow-hidden">
|
|
||||||
<img
|
|
||||||
src={displayData.posterUrl}
|
|
||||||
alt=""
|
|
||||||
className="w-full h-full object-cover blur-[24px]"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<div className="absolute inset-0 bg-gradient-to-br from-primary via-primary/90 to-primary/70" />
|
|
||||||
)}
|
|
||||||
{/* 오버레이 그라디언트 */}
|
|
||||||
<div className="absolute inset-0 bg-gradient-to-b from-black/40 via-black/50 to-black/70" />
|
|
||||||
|
|
||||||
{/* 콘텐츠 */}
|
|
||||||
<div className="relative px-5 pt-6 pb-8">
|
|
||||||
<div className="flex flex-col items-center text-center">
|
|
||||||
{/* 포스터 */}
|
|
||||||
{displayData.posterUrl && (
|
|
||||||
<div className="mb-4 rounded-xl overflow-hidden shadow-2xl ring-1 ring-white/20">
|
|
||||||
<img
|
|
||||||
src={displayData.posterUrl}
|
|
||||||
alt={displayData.title}
|
|
||||||
className="w-32 h-44 object-cover"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
{/* 제목 */}
|
|
||||||
<h1 className="text-white font-bold text-lg leading-snug drop-shadow-lg max-w-xs">
|
|
||||||
{decodeHtmlEntities(displayData.title)}
|
|
||||||
</h1>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* 카드 섹션 */}
|
|
||||||
<div className="px-4 pt-4 space-y-4">
|
|
||||||
{/* 공연 일정 카드 */}
|
|
||||||
<motion.div
|
|
||||||
initial={{ opacity: 0, y: 10 }}
|
|
||||||
animate={{ opacity: 1, y: 0 }}
|
|
||||||
transition={{ delay: 0.1 }}
|
|
||||||
className="bg-white rounded-xl p-4 shadow-sm"
|
|
||||||
>
|
|
||||||
<div className="flex items-center gap-2 text-xs text-gray-500 mb-3">
|
|
||||||
<Calendar size={14} />
|
|
||||||
<span>공연 일정</span>
|
|
||||||
</div>
|
|
||||||
{/* 현재 회차 표시 */}
|
|
||||||
<div className="px-4 py-3 bg-primary/10 rounded-lg">
|
|
||||||
<p className="text-primary font-medium text-sm">
|
|
||||||
{hasMultipleDates && <span className="mr-1">{selectedIndex + 1}회차 ·</span>}
|
|
||||||
{formatSingleDate(displayData.date, displayData.time)}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
{/* 다른 회차 선택 버튼 */}
|
|
||||||
{hasMultipleDates && (
|
|
||||||
<button
|
|
||||||
onClick={() => setIsDialogOpen(true)}
|
|
||||||
className="w-full mt-2 py-2.5 text-sm text-gray-500 font-medium active:bg-gray-50 rounded-lg transition-colors"
|
|
||||||
>
|
|
||||||
다른 회차 선택
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
</motion.div>
|
|
||||||
|
|
||||||
{/* 장소 카드 */}
|
|
||||||
{displayData.locationName && (
|
|
||||||
<motion.div
|
|
||||||
initial={{ opacity: 0, y: 10 }}
|
|
||||||
animate={{ opacity: 1, y: 0 }}
|
|
||||||
transition={{ delay: 0.15 }}
|
|
||||||
className="bg-white rounded-xl p-4 shadow-sm"
|
|
||||||
>
|
|
||||||
<div className="flex items-center gap-2 text-xs text-gray-500 mb-2">
|
|
||||||
<MapPin size={14} />
|
|
||||||
<span>장소</span>
|
|
||||||
</div>
|
|
||||||
<p className="text-gray-900 font-medium">{displayData.locationName}</p>
|
|
||||||
{displayData.locationAddress && (
|
|
||||||
<p className="text-gray-500 text-sm mt-0.5">{displayData.locationAddress}</p>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* 지도 - 좌표가 있으면 카카오맵, 없으면 구글맵 */}
|
|
||||||
{hasLocation ? (
|
|
||||||
<div className="mt-3 rounded-xl overflow-hidden">
|
|
||||||
<KakaoMap
|
|
||||||
lat={parseFloat(displayData.locationLat)}
|
|
||||||
lng={parseFloat(displayData.locationLng)}
|
|
||||||
name={displayData.locationName}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<div className="mt-3 rounded-xl overflow-hidden">
|
|
||||||
<iframe
|
|
||||||
src={`https://maps.google.com/maps?q=${encodeURIComponent(displayData.locationAddress || displayData.locationName)}&output=embed&hl=ko`}
|
|
||||||
className="w-full h-40 border-0"
|
|
||||||
loading="lazy"
|
|
||||||
referrerPolicy="no-referrer-when-downgrade"
|
|
||||||
title="Google Maps"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</motion.div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* 설명 */}
|
|
||||||
{displayData.description && (
|
|
||||||
<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"
|
|
||||||
>
|
|
||||||
<p className="text-gray-600 text-sm leading-relaxed">
|
|
||||||
{decodeHtmlEntities(displayData.description)}
|
|
||||||
</p>
|
|
||||||
</motion.div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* 버튼 영역 */}
|
|
||||||
<motion.div
|
|
||||||
initial={{ opacity: 0, y: 10 }}
|
|
||||||
animate={{ opacity: 1, y: 0 }}
|
|
||||||
transition={{ delay: 0.25 }}
|
|
||||||
className="space-y-2"
|
|
||||||
>
|
|
||||||
{displayData.locationName && (
|
|
||||||
<a
|
|
||||||
href={hasLocation
|
|
||||||
? `https://map.kakao.com/link/to/${encodeURIComponent(displayData.locationName)},${displayData.locationLat},${displayData.locationLng}`
|
|
||||||
: `https://www.google.com/maps/dir/?api=1&destination=${encodeURIComponent(displayData.locationAddress || displayData.locationName)}`
|
|
||||||
}
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
className={`flex items-center justify-center gap-2 w-full py-3.5 text-white rounded-xl font-medium transition-colors ${
|
|
||||||
hasLocation
|
|
||||||
? 'bg-blue-500 active:bg-blue-600'
|
|
||||||
: 'bg-[#4285F4] active:bg-[#3367D6]'
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
<Navigation size={18} />
|
|
||||||
길찾기
|
|
||||||
</a>
|
|
||||||
)}
|
|
||||||
{displayData.sourceUrl && (
|
|
||||||
<a
|
|
||||||
href={displayData.sourceUrl}
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
className="flex items-center justify-center gap-2 w-full py-3.5 bg-gray-100 active:bg-gray-200 text-gray-900 rounded-xl font-medium transition-colors"
|
|
||||||
>
|
|
||||||
<ExternalLink size={18} />
|
|
||||||
상세 정보
|
|
||||||
</a>
|
|
||||||
)}
|
|
||||||
</motion.div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* 회차 선택 다이얼로그 */}
|
|
||||||
<AnimatePresence>
|
|
||||||
{isDialogOpen && (
|
|
||||||
<div className="fixed inset-0 z-50 flex items-center justify-center p-4">
|
|
||||||
{/* 백드롭 */}
|
|
||||||
<motion.div
|
|
||||||
initial={{ opacity: 0 }}
|
|
||||||
animate={{ opacity: 1 }}
|
|
||||||
exit={{ opacity: 0 }}
|
|
||||||
transition={{ duration: 0.2 }}
|
|
||||||
className="absolute inset-0 bg-black/50"
|
|
||||||
onClick={() => setIsDialogOpen(false)}
|
|
||||||
/>
|
|
||||||
{/* 다이얼로그 */}
|
|
||||||
<motion.div
|
|
||||||
initial={{ opacity: 0, scale: 0.95 }}
|
|
||||||
animate={{ opacity: 1, scale: 1 }}
|
|
||||||
exit={{ opacity: 0, scale: 0.95 }}
|
|
||||||
transition={{ duration: 0.2 }}
|
|
||||||
className="relative bg-white rounded-2xl w-full max-w-sm overflow-hidden shadow-xl"
|
|
||||||
>
|
|
||||||
{/* 헤더 */}
|
|
||||||
<div className="px-5 py-4 border-b border-gray-100">
|
|
||||||
<h3 className="text-base font-bold text-gray-900">회차 선택</h3>
|
|
||||||
</div>
|
|
||||||
{/* 회차 목록 */}
|
|
||||||
<div ref={listRef} className="max-h-72 overflow-y-auto">
|
|
||||||
{relatedDates.map((item, index) => {
|
|
||||||
const isSelected = item.id === selectedDateId;
|
|
||||||
return (
|
|
||||||
<button
|
|
||||||
key={item.id}
|
|
||||||
ref={isSelected ? selectedItemRef : null}
|
|
||||||
onClick={() => handleSelectDate(item.id)}
|
|
||||||
className={`w-full flex items-center justify-between px-5 py-3.5 text-sm transition-colors ${
|
|
||||||
isSelected
|
|
||||||
? 'bg-primary/10'
|
|
||||||
: 'active:bg-gray-50'
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
<span className={isSelected ? 'text-primary font-medium' : 'text-gray-700'}>
|
|
||||||
{index + 1}회차 · {formatSingleDate(item.date, item.time)}
|
|
||||||
</span>
|
|
||||||
{isSelected && <Check size={18} className="text-primary" />}
|
|
||||||
</button>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
{/* 닫기 버튼 */}
|
|
||||||
<div className="px-5 py-4 border-t border-gray-100">
|
|
||||||
<button
|
|
||||||
onClick={() => setIsDialogOpen(false)}
|
|
||||||
className="w-full py-3 bg-gray-100 active:bg-gray-200 text-gray-700 rounded-xl font-medium transition-colors"
|
|
||||||
>
|
|
||||||
닫기
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</motion.div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</AnimatePresence>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 기본 섹션 컴포넌트 (다른 카테고리용 - 임시)
|
// 기본 섹션 컴포넌트 (다른 카테고리용 - 임시)
|
||||||
function DefaultSection({ schedule }) {
|
function DefaultSection({ schedule }) {
|
||||||
return (
|
return (
|
||||||
|
|
@ -991,8 +574,6 @@ function MobileScheduleDetail() {
|
||||||
return <YoutubeSection schedule={schedule} />;
|
return <YoutubeSection schedule={schedule} />;
|
||||||
case CATEGORY_ID.X:
|
case CATEGORY_ID.X:
|
||||||
return <XSection schedule={schedule} />;
|
return <XSection schedule={schedule} />;
|
||||||
case CATEGORY_ID.CONCERT:
|
|
||||||
return <ConcertSection schedule={schedule} />;
|
|
||||||
default:
|
default:
|
||||||
return <DefaultSection schedule={schedule} />;
|
return <DefaultSection schedule={schedule} />;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ import { getSchedule } from '../../../api/public/schedules';
|
||||||
import {
|
import {
|
||||||
YoutubeSection,
|
YoutubeSection,
|
||||||
XSection,
|
XSection,
|
||||||
ConcertSection,
|
|
||||||
DefaultSection,
|
DefaultSection,
|
||||||
CATEGORY_ID,
|
CATEGORY_ID,
|
||||||
decodeHtmlEntities,
|
decodeHtmlEntities,
|
||||||
|
|
@ -125,8 +124,6 @@ function ScheduleDetail() {
|
||||||
return <YoutubeSection schedule={schedule} />;
|
return <YoutubeSection schedule={schedule} />;
|
||||||
case CATEGORY_ID.X:
|
case CATEGORY_ID.X:
|
||||||
return <XSection schedule={schedule} />;
|
return <XSection schedule={schedule} />;
|
||||||
case CATEGORY_ID.CONCERT:
|
|
||||||
return <ConcertSection schedule={schedule} />;
|
|
||||||
default:
|
default:
|
||||||
return <DefaultSection schedule={schedule} />;
|
return <DefaultSection schedule={schedule} />;
|
||||||
}
|
}
|
||||||
|
|
@ -134,12 +131,11 @@ function ScheduleDetail() {
|
||||||
|
|
||||||
const isYoutube = categoryId === CATEGORY_ID.YOUTUBE;
|
const isYoutube = categoryId === CATEGORY_ID.YOUTUBE;
|
||||||
const isX = categoryId === CATEGORY_ID.X;
|
const isX = categoryId === CATEGORY_ID.X;
|
||||||
const isConcert = categoryId === CATEGORY_ID.CONCERT;
|
const hasCustomLayout = isYoutube || isX;
|
||||||
const hasCustomLayout = isYoutube || isX || isConcert;
|
|
||||||
|
|
||||||
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' : isConcert ? 'max-w-4xl' : 'max-w-3xl'} mx-auto px-6 py-8`}>
|
<div className={`${isYoutube ? '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 }}
|
||||||
|
|
|
||||||
|
|
@ -1,389 +0,0 @@
|
||||||
import { useEffect, useRef, useState } from 'react';
|
|
||||||
import { useQuery, keepPreviousData } from '@tanstack/react-query';
|
|
||||||
import { motion, AnimatePresence } from 'framer-motion';
|
|
||||||
import { ExternalLink, ChevronDown, Check, MapPin, Navigation } from 'lucide-react';
|
|
||||||
import { getSchedule } from '../../../../api/public/schedules';
|
|
||||||
import { decodeHtmlEntities } from './utils';
|
|
||||||
import KakaoMap from './KakaoMap';
|
|
||||||
|
|
||||||
// 콘서트 섹션 컴포넌트
|
|
||||||
function ConcertSection({ schedule }) {
|
|
||||||
// 현재 선택된 회차 ID (내부 state로 관리 - URL 변경 없음)
|
|
||||||
const [selectedDateId, setSelectedDateId] = useState(schedule.id);
|
|
||||||
const [isDropdownOpen, setIsDropdownOpen] = useState(false);
|
|
||||||
const dropdownRef = useRef(null);
|
|
||||||
const dropdownListRef = useRef(null);
|
|
||||||
|
|
||||||
// 표시할 데이터 state (변경된 부분만 업데이트)
|
|
||||||
const [displayData, setDisplayData] = useState({
|
|
||||||
posterUrl: schedule.images?.[0] || null,
|
|
||||||
title: schedule.title,
|
|
||||||
date: schedule.date,
|
|
||||||
time: schedule.time,
|
|
||||||
locationName: schedule.location_name,
|
|
||||||
locationAddress: schedule.location_address,
|
|
||||||
locationLat: schedule.location_lat,
|
|
||||||
locationLng: schedule.location_lng,
|
|
||||||
description: schedule.description,
|
|
||||||
sourceUrl: schedule.source?.url,
|
|
||||||
});
|
|
||||||
|
|
||||||
// 선택된 회차 데이터 조회
|
|
||||||
const { data: selectedSchedule } = useQuery({
|
|
||||||
queryKey: ['schedule', selectedDateId],
|
|
||||||
queryFn: () => getSchedule(selectedDateId),
|
|
||||||
placeholderData: keepPreviousData,
|
|
||||||
enabled: selectedDateId !== schedule.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
// 데이터 비교 후 변경된 부분만 업데이트
|
|
||||||
useEffect(() => {
|
|
||||||
const newData = selectedDateId === schedule.id ? schedule : selectedSchedule;
|
|
||||||
if (!newData) return;
|
|
||||||
|
|
||||||
setDisplayData(prev => {
|
|
||||||
const updates = {};
|
|
||||||
const newPosterUrl = newData.images?.[0] || null;
|
|
||||||
|
|
||||||
if (prev.posterUrl !== newPosterUrl) updates.posterUrl = newPosterUrl;
|
|
||||||
if (prev.title !== newData.title) updates.title = newData.title;
|
|
||||||
if (prev.date !== newData.date) updates.date = newData.date;
|
|
||||||
if (prev.time !== newData.time) updates.time = newData.time;
|
|
||||||
if (prev.locationName !== newData.location_name) updates.locationName = newData.location_name;
|
|
||||||
if (prev.locationAddress !== newData.location_address) updates.locationAddress = newData.location_address;
|
|
||||||
if (prev.locationLat !== newData.location_lat) updates.locationLat = newData.location_lat;
|
|
||||||
if (prev.locationLng !== newData.location_lng) updates.locationLng = newData.location_lng;
|
|
||||||
if (prev.description !== newData.description) updates.description = newData.description;
|
|
||||||
if (prev.sourceUrl !== newData.source?.url) updates.sourceUrl = newData.source?.url;
|
|
||||||
|
|
||||||
if (Object.keys(updates).length > 0) {
|
|
||||||
return { ...prev, ...updates };
|
|
||||||
}
|
|
||||||
return prev;
|
|
||||||
});
|
|
||||||
}, [selectedDateId, schedule, selectedSchedule]);
|
|
||||||
|
|
||||||
// 드롭다운 외부 클릭 감지
|
|
||||||
useEffect(() => {
|
|
||||||
const handleClickOutside = (event) => {
|
|
||||||
if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
|
|
||||||
setIsDropdownOpen(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
document.addEventListener('mousedown', handleClickOutside);
|
|
||||||
return () => document.removeEventListener('mousedown', handleClickOutside);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
// 드롭다운 열릴 때 선택된 항목으로 자동 스크롤
|
|
||||||
useEffect(() => {
|
|
||||||
if (isDropdownOpen && dropdownListRef.current) {
|
|
||||||
const selectedElement = dropdownListRef.current.querySelector('[data-selected="true"]');
|
|
||||||
if (selectedElement) {
|
|
||||||
// 약간의 지연 후 스크롤 (애니메이션 후)
|
|
||||||
setTimeout(() => {
|
|
||||||
selectedElement.scrollIntoView({ block: 'center', behavior: 'smooth' });
|
|
||||||
}, 50);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, [isDropdownOpen]);
|
|
||||||
|
|
||||||
const relatedDates = schedule.related_dates || [];
|
|
||||||
const hasMultipleDates = relatedDates.length > 1;
|
|
||||||
const hasLocation = displayData.locationLat && displayData.locationLng;
|
|
||||||
const hasPoster = !!displayData.posterUrl;
|
|
||||||
const hasDescription = !!displayData.description;
|
|
||||||
|
|
||||||
// 현재 선택된 회차 인덱스
|
|
||||||
const selectedIndex = relatedDates.findIndex(d => d.id === selectedDateId);
|
|
||||||
const selectedDisplayIndex = selectedIndex >= 0 ? selectedIndex + 1 : 1;
|
|
||||||
|
|
||||||
// 회차 선택 핸들러
|
|
||||||
const handleSelectDate = (id) => {
|
|
||||||
setSelectedDateId(id);
|
|
||||||
setIsDropdownOpen(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
// 짧은 날짜 포맷팅 (회차 목록용)
|
|
||||||
const formatShortDate = (dateStr, timeStr) => {
|
|
||||||
const date = new Date(dateStr);
|
|
||||||
const dayNames = ['일', '월', '화', '수', '목', '금', '토'];
|
|
||||||
const month = date.getMonth() + 1;
|
|
||||||
const day = date.getDate();
|
|
||||||
const weekday = dayNames[date.getDay()];
|
|
||||||
|
|
||||||
let result = `${month}/${day} (${weekday})`;
|
|
||||||
if (timeStr) {
|
|
||||||
result += ` ${timeStr.slice(0, 5)}`;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="space-y-6">
|
|
||||||
{/* ========== 히어로 섹션 ========== */}
|
|
||||||
<motion.section
|
|
||||||
initial={{ opacity: 0 }}
|
|
||||||
animate={{ opacity: 1 }}
|
|
||||||
className="relative rounded-3xl overflow-visible"
|
|
||||||
>
|
|
||||||
{/* 배경 레이어 - 포스터 확대 + 블러 */}
|
|
||||||
<div className="absolute inset-0 rounded-3xl overflow-hidden">
|
|
||||||
{hasPoster ? (
|
|
||||||
<>
|
|
||||||
<img
|
|
||||||
src={displayData.posterUrl}
|
|
||||||
alt=""
|
|
||||||
className="w-full h-full object-cover scale-125 blur-xl"
|
|
||||||
/>
|
|
||||||
<div className="absolute inset-0 bg-gradient-to-t from-black/70 via-black/50 to-black/30" />
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<div className="absolute inset-0 bg-gradient-to-br from-primary via-primary/90 to-primary/70" />
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* 메인 콘텐츠 */}
|
|
||||||
<div className="relative z-10 p-10">
|
|
||||||
<div className="flex items-start gap-10">
|
|
||||||
{/* 포스터 */}
|
|
||||||
{hasPoster && (
|
|
||||||
<motion.div
|
|
||||||
initial={{ opacity: 0, y: 20 }}
|
|
||||||
animate={{ opacity: 1, y: 0 }}
|
|
||||||
transition={{ duration: 0.5 }}
|
|
||||||
className="flex-shrink-0"
|
|
||||||
>
|
|
||||||
<img
|
|
||||||
src={displayData.posterUrl}
|
|
||||||
alt={displayData.title}
|
|
||||||
className="w-52 h-72 object-cover rounded-2xl shadow-2xl"
|
|
||||||
/>
|
|
||||||
</motion.div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* 제목 및 회차 선택 */}
|
|
||||||
<div className="flex-1 min-w-0 pt-4">
|
|
||||||
{/* 제목 */}
|
|
||||||
<motion.h1
|
|
||||||
initial={{ opacity: 0, y: 20 }}
|
|
||||||
animate={{ opacity: 1, y: 0 }}
|
|
||||||
transition={{ delay: 0.1 }}
|
|
||||||
className="text-3xl font-bold text-white leading-tight mb-6"
|
|
||||||
>
|
|
||||||
{decodeHtmlEntities(displayData.title)}
|
|
||||||
</motion.h1>
|
|
||||||
|
|
||||||
{/* 회차 선택 드롭다운 */}
|
|
||||||
{hasMultipleDates && (
|
|
||||||
<motion.div
|
|
||||||
initial={{ opacity: 0, y: 10 }}
|
|
||||||
animate={{ opacity: 1, y: 0 }}
|
|
||||||
transition={{ delay: 0.2 }}
|
|
||||||
ref={dropdownRef}
|
|
||||||
className="relative inline-block"
|
|
||||||
>
|
|
||||||
<button
|
|
||||||
onClick={() => setIsDropdownOpen(!isDropdownOpen)}
|
|
||||||
className="group flex items-center gap-4 px-5 py-3.5 bg-white rounded-2xl shadow-lg hover:shadow-xl transition-all border border-gray-100"
|
|
||||||
>
|
|
||||||
{/* 회차 뱃지 */}
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<div className="w-8 h-8 bg-primary rounded-lg flex items-center justify-center">
|
|
||||||
<span className="text-xs font-bold text-white">{selectedDisplayIndex}</span>
|
|
||||||
</div>
|
|
||||||
<span className="text-xs font-medium text-gray-400">회차</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* 구분선 */}
|
|
||||||
<div className="w-px h-6 bg-gray-200" />
|
|
||||||
|
|
||||||
{/* 날짜 정보 */}
|
|
||||||
<div className="text-left">
|
|
||||||
<div className="text-sm font-semibold text-gray-800">
|
|
||||||
{formatShortDate(displayData.date, displayData.time)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<ChevronDown
|
|
||||||
size={18}
|
|
||||||
className={`text-gray-400 transition-transform duration-200 ${isDropdownOpen ? 'rotate-180' : ''}`}
|
|
||||||
/>
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<AnimatePresence>
|
|
||||||
{isDropdownOpen && (
|
|
||||||
<motion.div
|
|
||||||
initial={{ opacity: 0, y: -10, scale: 0.95 }}
|
|
||||||
animate={{ opacity: 1, y: 0, scale: 1 }}
|
|
||||||
exit={{ opacity: 0, y: -10, scale: 0.95 }}
|
|
||||||
transition={{ duration: 0.2, ease: 'easeOut' }}
|
|
||||||
className="absolute top-full left-0 mt-3 bg-white rounded-2xl shadow-2xl z-[100] w-80 overflow-hidden border border-gray-100"
|
|
||||||
>
|
|
||||||
{/* 드롭다운 헤더 */}
|
|
||||||
<div className="px-4 py-3 bg-gray-50 border-b border-gray-100">
|
|
||||||
<span className="text-sm font-semibold text-gray-600">공연 일정 선택</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div ref={dropdownListRef} className="py-2 max-h-72 overflow-y-auto">
|
|
||||||
{relatedDates.map((item, index) => {
|
|
||||||
const isSelected = item.id === selectedDateId;
|
|
||||||
return (
|
|
||||||
<button
|
|
||||||
key={item.id}
|
|
||||||
data-selected={isSelected}
|
|
||||||
onClick={() => handleSelectDate(item.id)}
|
|
||||||
className={`w-full flex items-center gap-4 px-4 py-3.5 transition-all ${
|
|
||||||
isSelected
|
|
||||||
? 'bg-primary/5'
|
|
||||||
: 'hover:bg-gray-50'
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
{/* 회차 번호 */}
|
|
||||||
<div className={`w-9 h-9 rounded-xl flex items-center justify-center text-sm font-bold transition-colors ${
|
|
||||||
isSelected
|
|
||||||
? 'bg-primary text-white'
|
|
||||||
: 'bg-gray-100 text-gray-500'
|
|
||||||
}`}>
|
|
||||||
{index + 1}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* 날짜 정보 */}
|
|
||||||
<div className="flex-1 text-left">
|
|
||||||
<div className={`font-medium ${
|
|
||||||
isSelected ? 'text-primary' : 'text-gray-800'
|
|
||||||
}`}>
|
|
||||||
{formatShortDate(item.date, item.time)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* 체크 표시 */}
|
|
||||||
{isSelected && (
|
|
||||||
<div className="w-6 h-6 bg-primary rounded-full flex items-center justify-center">
|
|
||||||
<Check size={14} className="text-white" strokeWidth={3} />
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</button>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
</motion.div>
|
|
||||||
)}
|
|
||||||
</AnimatePresence>
|
|
||||||
</motion.div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</motion.section>
|
|
||||||
|
|
||||||
{/* ========== 장소 정보 카드 ========== */}
|
|
||||||
{displayData.locationName && (
|
|
||||||
<motion.section
|
|
||||||
initial={{ opacity: 0, y: 20 }}
|
|
||||||
animate={{ opacity: 1, y: 0 }}
|
|
||||||
transition={{ delay: 0.3 }}
|
|
||||||
className="bg-white rounded-2xl shadow-sm ring-1 ring-gray-100 overflow-hidden"
|
|
||||||
>
|
|
||||||
{/* 헤더 */}
|
|
||||||
<div className="p-6 border-b border-gray-100">
|
|
||||||
<div className="flex items-center justify-between">
|
|
||||||
<div className="flex items-center gap-4">
|
|
||||||
{/* 장소 아이콘 */}
|
|
||||||
<div className="w-12 h-12 bg-gray-100 rounded-xl flex items-center justify-center">
|
|
||||||
<MapPin size={24} className="text-gray-600" />
|
|
||||||
</div>
|
|
||||||
{/* 텍스트 */}
|
|
||||||
<div>
|
|
||||||
<h2 className="text-lg font-bold text-gray-900">{displayData.locationName}</h2>
|
|
||||||
{displayData.locationAddress && (
|
|
||||||
<p className="text-sm text-gray-500 mt-0.5">{displayData.locationAddress}</p>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* 길찾기 버튼 - 카카오맵(국내) / 구글맵(해외) */}
|
|
||||||
<a
|
|
||||||
href={hasLocation
|
|
||||||
? `https://map.kakao.com/link/to/${encodeURIComponent(displayData.locationName)},${displayData.locationLat},${displayData.locationLng}`
|
|
||||||
: `https://www.google.com/maps/dir/?api=1&destination=${encodeURIComponent(displayData.locationAddress || displayData.locationName)}`
|
|
||||||
}
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
className="flex items-center gap-2 px-4 py-2.5 text-white text-sm font-semibold rounded-lg transition-colors"
|
|
||||||
style={{
|
|
||||||
backgroundColor: hasLocation ? '#0079f4' : '#4285F4'
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Navigation size={16} />
|
|
||||||
길찾기
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* 지도 - 높이 2배 */}
|
|
||||||
<div className="h-[32rem]">
|
|
||||||
{hasLocation ? (
|
|
||||||
<KakaoMap
|
|
||||||
lat={parseFloat(displayData.locationLat)}
|
|
||||||
lng={parseFloat(displayData.locationLng)}
|
|
||||||
name={displayData.locationName}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<iframe
|
|
||||||
src={`https://maps.google.com/maps?q=${encodeURIComponent(displayData.locationAddress || displayData.locationName)}&output=embed&hl=ko`}
|
|
||||||
className="h-full w-full border-0"
|
|
||||||
loading="lazy"
|
|
||||||
referrerPolicy="no-referrer-when-downgrade"
|
|
||||||
title="Google Maps"
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</motion.section>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* ========== 공연 정보 카드 ========== */}
|
|
||||||
{hasDescription && (
|
|
||||||
<motion.section
|
|
||||||
initial={{ opacity: 0, y: 20 }}
|
|
||||||
animate={{ opacity: 1, y: 0 }}
|
|
||||||
transition={{ delay: 0.4 }}
|
|
||||||
className="bg-white rounded-2xl shadow-sm ring-1 ring-gray-100 p-6"
|
|
||||||
>
|
|
||||||
<div className="flex items-center gap-3 mb-4">
|
|
||||||
<div className="w-10 h-10 rounded-xl bg-purple-50 flex items-center justify-center">
|
|
||||||
<svg className="w-5 h-5 text-purple-500" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
||||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
|
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
<h2 className="text-lg font-bold text-gray-900">공연 정보</h2>
|
|
||||||
</div>
|
|
||||||
<p className="text-gray-600 leading-relaxed whitespace-pre-wrap">
|
|
||||||
{decodeHtmlEntities(displayData.description)}
|
|
||||||
</p>
|
|
||||||
</motion.section>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* ========== 외부 링크 버튼 ========== */}
|
|
||||||
{displayData.sourceUrl && (
|
|
||||||
<motion.div
|
|
||||||
initial={{ opacity: 0, y: 20 }}
|
|
||||||
animate={{ opacity: 1, y: 0 }}
|
|
||||||
transition={{ delay: 0.5 }}
|
|
||||||
className="flex justify-center"
|
|
||||||
>
|
|
||||||
<a
|
|
||||||
href={displayData.sourceUrl}
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
className="inline-flex items-center gap-2 px-6 py-3 bg-gray-900 text-white rounded-xl font-semibold hover:bg-gray-800 transition-colors"
|
|
||||||
>
|
|
||||||
<ExternalLink size={18} />
|
|
||||||
티켓 예매 및 상세 정보
|
|
||||||
</a>
|
|
||||||
</motion.div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default ConcertSection;
|
|
||||||
|
|
@ -1,88 +0,0 @@
|
||||||
import { useEffect, useRef, useState } from 'react';
|
|
||||||
import { Navigation } from 'lucide-react';
|
|
||||||
|
|
||||||
// 카카오맵 SDK 키
|
|
||||||
const KAKAO_MAP_KEY = import.meta.env.VITE_KAKAO_JS_KEY;
|
|
||||||
|
|
||||||
// 카카오맵 컴포넌트
|
|
||||||
function KakaoMap({ lat, lng, name }) {
|
|
||||||
const mapRef = useRef(null);
|
|
||||||
const [mapLoaded, setMapLoaded] = useState(false);
|
|
||||||
const [mapError, setMapError] = useState(false);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
// API 키가 없으면 에러
|
|
||||||
if (!KAKAO_MAP_KEY) {
|
|
||||||
setMapError(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 카카오맵 SDK 동적 로드
|
|
||||||
if (!window.kakao?.maps) {
|
|
||||||
const script = document.createElement('script');
|
|
||||||
script.src = `//dapi.kakao.com/v2/maps/sdk.js?appkey=${KAKAO_MAP_KEY}&autoload=false`;
|
|
||||||
script.onload = () => {
|
|
||||||
window.kakao.maps.load(() => setMapLoaded(true));
|
|
||||||
};
|
|
||||||
script.onerror = () => setMapError(true);
|
|
||||||
document.head.appendChild(script);
|
|
||||||
} else {
|
|
||||||
setMapLoaded(true);
|
|
||||||
}
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!mapLoaded || !mapRef.current || mapError) return;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const position = new window.kakao.maps.LatLng(lat, lng);
|
|
||||||
const map = new window.kakao.maps.Map(mapRef.current, {
|
|
||||||
center: position,
|
|
||||||
level: 3,
|
|
||||||
});
|
|
||||||
|
|
||||||
// 마커 추가
|
|
||||||
const marker = new window.kakao.maps.Marker({
|
|
||||||
position,
|
|
||||||
map,
|
|
||||||
});
|
|
||||||
|
|
||||||
// 인포윈도우 추가
|
|
||||||
if (name) {
|
|
||||||
const infowindow = new window.kakao.maps.InfoWindow({
|
|
||||||
content: `<div style="padding:8px 12px;font-size:13px;font-weight:500;">${name}</div>`,
|
|
||||||
});
|
|
||||||
infowindow.open(map, marker);
|
|
||||||
}
|
|
||||||
} 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="group flex h-full w-full items-center justify-center bg-white/80 text-center backdrop-blur transition-all hover:bg-white"
|
|
||||||
>
|
|
||||||
<div>
|
|
||||||
<Navigation size={32} className="mx-auto text-gray-400 group-hover:text-primary transition-colors mb-3" />
|
|
||||||
<p className="text-gray-700 font-semibold">{name}</p>
|
|
||||||
<p className="text-sm text-gray-400 mt-1">길찾기 열기</p>
|
|
||||||
</div>
|
|
||||||
</a>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
ref={mapRef}
|
|
||||||
className="h-full w-full"
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default KakaoMap;
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
export { default as YoutubeSection } from "./YoutubeSection";
|
export { default as YoutubeSection } from "./YoutubeSection";
|
||||||
export { default as XSection } from "./XSection";
|
export { default as XSection } from "./XSection";
|
||||||
export { default as ConcertSection } from "./ConcertSection";
|
|
||||||
export { default as DefaultSection } from "./DefaultSection";
|
export { default as DefaultSection } from "./DefaultSection";
|
||||||
export { default as KakaoMap } from "./KakaoMap";
|
|
||||||
export * from "./utils";
|
export * from "./utils";
|
||||||
|
|
|
||||||
|
|
@ -49,8 +49,4 @@ export const formatXDateTime = (dateStr, timeStr) => {
|
||||||
export const CATEGORY_ID = {
|
export const CATEGORY_ID = {
|
||||||
YOUTUBE: 2,
|
YOUTUBE: 2,
|
||||||
X: 3,
|
X: 3,
|
||||||
ALBUM: 4,
|
|
||||||
FANSIGN: 5,
|
|
||||||
CONCERT: 6,
|
|
||||||
TICKET: 7,
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue