@@ -6,38 +6,18 @@ import { useSheetStore } from '@/store/sheetStore';
66import { useYouTubeStore } from '@/store/youtubeStore' ;
77import defaultImage from '@assets/images/default.png' ;
88import { useQuery } from '@tanstack/react-query' ;
9- import { getEmotionRecordById } from '@/apis/emotionRecord' ;
9+ import { getEmotionRecordById , getSpotifyVideoId } from '@/apis/emotionRecord' ;
1010import { formatDate } from '@/utils/formatDate' ;
11- import { useEffect } from 'react' ;
12- import { searchYoutubeVideo } from '@/apis/youtube' ;
11+ import { useEffect , useState } from 'react' ;
1312
1413interface CardDetailModalProps {
15- // emotion: string; // 감정
16- // albumImage: string; // 앨범이미지
17- // songTitle: string; // 노래 제목
18- // artistName: string; // 가수
19- // date: string; // 날짜
20- // authorName: string; // 글작성자
2114 isChatting : boolean ; // 현재 채팅중인지 (임시)
22- // isOwnPost: boolean; // 본인 글 여부(임시)
2315 recordId : number ; // 감정기록 id
2416 handleDelete ?: ( ) => void ; // 삭제 함수
2517 handleEdit ?: ( ) => void ; // 수정 함수
2618}
2719
28- function CardDetailModal ( {
29- // emotion,
30- // albumImage,
31- // songTitle,
32- // artistName,
33- // date,
34- // authorName,
35- isChatting,
36- // isOwnPost,
37- recordId,
38- handleDelete,
39- handleEdit,
40- } : CardDetailModalProps ) {
20+ function CardDetailModal ( { isChatting, recordId, handleDelete, handleEdit } : CardDetailModalProps ) {
4121 const { isCardSheetOpen, setCurrentRecord } = useSheetStore ( ) ;
4222 const { setVideoId, players, setIsPlaying } = useYouTubeStore ( ) ;
4323 const isPlaying = players [ '3' ] ?. isPlaying || false ;
@@ -47,38 +27,54 @@ function CardDetailModal({
4727 queryFn : ( ) => getEmotionRecordById ( recordId ) ,
4828 } ) ;
4929
30+ const [ currentVideoId , setCurrentVideoId ] = useState < string | null > ( null ) ;
31+
32+ useEffect ( ( ) => {
33+ const getVideoId = async ( ) => {
34+ if ( ! data ?. data ?. spotifyMusic ) return ; // 데이터가 없으면 실행하지 않음
35+
36+ try {
37+ const currentMusicId = data . data . spotifyMusic . spotifyId ;
38+ const res = await getSpotifyVideoId ( currentMusicId ) ;
39+ const savedVideoId = res . data . videoId ;
40+ setCurrentVideoId ( savedVideoId ) ;
41+ } catch ( error ) {
42+ console . log ( error ) ;
43+ }
44+ } ;
45+ getVideoId ( ) ;
46+ } , [ ] ) ;
47+
48+ // videoId가 변경될 때마다 zustand store의 videoId를 업데이트
49+ useEffect ( ( ) => {
50+ if ( currentVideoId ) {
51+ setVideoId ( '2' , currentVideoId ) ; // YouTube store의 videoId를 업데이트
52+ }
53+ } , [ currentVideoId ] ) ;
54+
5055 useEffect ( ( ) => {
5156 if ( ! data ?. data ?. spotifyMusic ) return ; // 데이터가 없으면 실행하지 않음
5257 console . log ( data ?. data ) ;
5358
5459 setCurrentRecord ( data . data ) ;
5560
56- const artistName = data . data . spotifyMusic . artist ;
57- const songTitle = data . data . spotifyMusic . title ;
58-
59- const getVideoId = async ( ) => {
60- const id = await searchYoutubeVideo ( `${ artistName } - ${ songTitle } lyrics` ) ;
61- setVideoId ( '3' , id ) ;
62- } ;
63- getVideoId ( ) ;
64-
6561 return ( ) => {
6662 setCurrentRecord ( null ) ;
6763 } ;
6864 } , [ data ] ) ;
6965
70- //sheet open 시 스크롤 제거
71- useEffect ( ( ) => {
72- if ( isCardSheetOpen ) {
73- document . body . style . overflow = 'hidden' ; // 스크롤 막기
74- } else {
75- document . body . style . overflow = 'auto' ; // 스크롤 복원
76- }
77-
78- return ( ) => {
79- document . body . style . overflow = 'auto' ;
80- } ;
81- } , [ isCardSheetOpen ] ) ;
66+ // // sheet open 시 스크롤 제거
67+ // useEffect(() => {
68+ // if (isCardSheetOpen) {
69+ // document.body.style.overflow = 'hidden'; // 스크롤 막기
70+ // } else {
71+ // document.body.style.overflow = 'auto'; // 스크롤 복원
72+ // }
73+
74+ // return () => {
75+ // document.body.style.overflow = 'auto';
76+ // };
77+ // }, [isCardSheetOpen]);
8278
8379 if ( ! isCardSheetOpen ) {
8480 return null ;
0 commit comments