|
1 | | -import commentIcon from '@assets/icons/comment-icon.svg'; |
2 | 1 | import homeIcon from '@assets/icons/home-icon.svg'; |
3 | 2 | import CardDetailButtons from '@/components/modalSheet/CardDetailButtons'; |
4 | | -import headsetIcon from '@assets/icons/headset-icon-gray.svg'; |
5 | | -import playIcon from '@assets/icons/play/play-icon-gray.svg'; |
6 | | -import pauseIcon from '@assets/icons/pause-icon-gray.svg'; |
7 | 3 | import { useNavigate } from 'react-router'; |
8 | | -import { useSheetStore } from '@/store/sheetStore'; |
9 | | -// import { cancelChatRequest, requestChat } from '@/apis/chat'; |
10 | | -import { requestChat } from '@/apis/chat'; |
11 | | -import { useModalStore } from '@/store/modalStore'; |
12 | | -// import { useChatStore } from '@/store/chatStore'; |
| 4 | +import PlayToggleButton from '@/components/modalSheet/PlayToggleButton'; |
| 5 | +import ChatRequestButton from '@/components/modalSheet/ChatRequestButton'; |
13 | 6 |
|
14 | 7 | interface ChatActionButtonsProps { |
15 | 8 | recordId: number; |
16 | | - isChatting: boolean; |
17 | | - isPlaying: boolean; |
| 9 | + videoId: string; |
18 | 10 | isOwnPost: boolean; // 본인 글 여부 |
19 | 11 | authorId: string; // 작성자 id |
20 | | - onPlayPauseToggle: () => void; |
21 | 12 | } |
22 | 13 |
|
23 | 14 | // 카드상세 모달에서 채팅중인지에 따라서 버튼 속성 결정 |
24 | | -function ChatActionButtons({ |
25 | | - recordId, |
26 | | - isChatting, |
27 | | - isPlaying, |
28 | | - isOwnPost, |
29 | | - onPlayPauseToggle, |
30 | | - authorId, |
31 | | -}: ChatActionButtonsProps) { |
| 15 | +function ChatActionButtons({ recordId, videoId, isOwnPost, authorId }: ChatActionButtonsProps) { |
32 | 16 | const navigate = useNavigate(); |
33 | 17 |
|
34 | | - // const { openSheet, closeSheet, currentRecord } = useSheetStore(); // 모달 시트 |
35 | | - const { openSheet } = useSheetStore(); // 모달 시트 |
36 | | - // const { pastRecord } = useChatStore(); |
37 | | - const { openModal, closeModal } = useModalStore(); |
38 | | - |
39 | 18 | const handleGoToUserPage = () => { |
40 | | - // closeAllSheets(); // 모든 시트를 닫아야할지 카드모달시트만 닫으면 될지 고민중 |
41 | 19 | navigate(`/user/${authorId}`); // 유저 페이지로 이동 |
42 | 20 | }; |
43 | 21 |
|
44 | | - //채팅 요청 취소(요청 보낸 사람) |
45 | | - // const cancel = async () => { |
46 | | - // if (!currentRecord?.recordId && !pastRecord?.recordId) { |
47 | | - // // console.log('record가 존재하지 않습니다'); |
48 | | - // return; |
49 | | - // } |
50 | | - // try { |
51 | | - // // console.log(currentRecord); |
52 | | - // const { code } = await cancelChatRequest( |
53 | | - // currentRecord?.recordId || Number(pastRecord?.recordId), |
54 | | - // ); |
55 | | - // if (code === 200) { |
56 | | - // // console.log('취소 요청 성공'); |
57 | | - // closeSheet('isRequestSendingSheetOpen'); |
58 | | - // } else { |
59 | | - // throw new Error('취소 요청 실패'); |
60 | | - // } |
61 | | - // } catch (error) { |
62 | | - // console.error(error); |
63 | | - // closeSheet('isRequestSendingSheetOpen'); // 취소 요청 실패시 창 닫기 |
64 | | - // } |
65 | | - // }; |
66 | | - |
67 | | - //채팅 요청 |
68 | | - //요청 보내면 sse로 recordId, 보낸 사람 정보 보내줘야 함 |
69 | | - const request = async () => { |
70 | | - // if (!recordId) { |
71 | | - // // console.log('recordId가 존재하지 않습니다.'); |
72 | | - // return; |
73 | | - // } |
74 | | - try { |
75 | | - const { code } = await requestChat(recordId); |
76 | | - if (code === 200) { |
77 | | - openSheet('isRequestSendingSheetOpen'); |
78 | | - } else if (code === 202) { |
79 | | - openModal({ |
80 | | - title: '현재 로그아웃 중입니다.', |
81 | | - onConfirm: () => { |
82 | | - closeModal(); |
83 | | - // cancel(); |
84 | | - }, |
85 | | - }); |
86 | | - } else { |
87 | | - throw new Error('잠시 후 다시 시도해 주세요'); |
88 | | - } |
89 | | - } catch (error) { |
90 | | - // console.log(error); |
91 | | - openModal({ |
92 | | - title: '잠시 후 다시 시도해 주세요', |
93 | | - onConfirm: () => { |
94 | | - closeModal(); |
95 | | - }, |
96 | | - }); |
97 | | - } |
98 | | - }; |
99 | | - |
100 | | - // 채팅 유무에 따라서 props다르게 |
101 | | - const chatButtonProps = isChatting |
102 | | - ? { icon: headsetIcon, label: '대화 중...' } |
103 | | - : { icon: commentIcon, label: '대화하기', onClick: request }; |
104 | | - |
105 | | - // 노래 재생 유무에 따라서 다르게 |
106 | | - const playButtonProps = isPlaying |
107 | | - ? { icon: pauseIcon, label: '재생 중...', onClick: onPlayPauseToggle } |
108 | | - : { icon: playIcon, label: '재생하기', onClick: onPlayPauseToggle }; |
109 | | - |
110 | 22 | return ( |
111 | | - <> |
112 | | - {!isOwnPost && <CardDetailButtons {...chatButtonProps} />} |
113 | | - {<CardDetailButtons {...playButtonProps} />} |
| 23 | + <div className="flex gap-10"> |
| 24 | + {!isOwnPost && <ChatRequestButton recordId={recordId} />} |
| 25 | + <PlayToggleButton videoId={videoId} /> |
114 | 26 | {!isOwnPost && ( |
115 | 27 | <CardDetailButtons icon={homeIcon} label="구경가기" onClick={handleGoToUserPage} /> |
116 | 28 | )} |
117 | | - </> |
| 29 | + </div> |
118 | 30 | ); |
119 | 31 | } |
120 | 32 |
|
|
0 commit comments