Skip to content

Commit c818c16

Browse files
authored
Merge pull request #203 from prgrms-web-devcourse-final-project/fix/199-profileMusic
[fix] 프로필 뮤직 삭제 로직 수정
2 parents fcdc6e5 + 9da70b0 commit c818c16

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

src/apis/user.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ interface UserProfileEdit {
55
loginId: string;
66
password: string;
77
nickName: string;
8-
spotifyId: string;
8+
spotifyId: string | -1;
99
title: string;
1010
artist: string;
1111
albumImage: string;

src/components/MusicCard.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ export default function MusicCard({
120120
</div>
121121
{rightElement === 'button' && (
122122
<Button
123+
type="button"
123124
onClick={() => openSheet('isMusicSheetOpen')}
124125
variant={buttonType}
125126
className="w-[51px] h-[32px] flex-shrink-0"

src/pages/editprofile/components/ProfileEditForm.tsx

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { twMerge } from 'tailwind-merge';
1616
type ProfileFormType = {
1717
password: string;
1818
nickName: string;
19-
spotifyId: string;
19+
spotifyId: string | -1;
2020
title: string;
2121
artist: string;
2222
albumImage: string;
@@ -52,11 +52,19 @@ function ProfileEditForm() {
5252
if (nickname !== prevNickname.current) {
5353
updatedData.nickName = nickname;
5454
}
55+
// 현재 프로필 뮤직이랑 이전 프로필 뮤직이 다를때만 업데이트
5556
if (selectedProfileMusic !== prevProfileMusic.current) {
56-
updatedData.spotifyId = selectedProfileMusic?.spotifyId;
57-
updatedData.title = selectedProfileMusic?.title;
58-
updatedData.artist = selectedProfileMusic?.artist;
59-
updatedData.albumImage = selectedProfileMusic?.album;
57+
// 프로필 뮤직이 선택되어있을 경우
58+
if (selectedProfileMusic) {
59+
updatedData.spotifyId = selectedProfileMusic.spotifyId;
60+
updatedData.title = selectedProfileMusic.title;
61+
updatedData.artist = selectedProfileMusic.artist;
62+
updatedData.albumImage = selectedProfileMusic.album;
63+
}
64+
// 프로필 뮤직이 선택되지않아서 삭제하는 로직
65+
else {
66+
updatedData.spotifyId = -1;
67+
}
6068
}
6169

6270
console.log('전송 데이터:', updatedData);
@@ -121,12 +129,14 @@ function ProfileEditForm() {
121129

122130
useEffect(() => {
123131
const loadMyProfile = async () => {
124-
const data = await getMyProfile();
125-
prevNickname.current = data.data.nickname; // 이전 닉네임 저장하기
126-
prevProfileMusic.current = data.data.profileMusic; // 이전 음악 저장하기
132+
const { data } = await getMyProfile();
133+
const { nickname, profileMusic } = data;
127134

128-
setNickname(data.data.nickname);
129-
selectProfileMusic(data.data.profileMusic);
135+
prevNickname.current = nickname; // 이전 닉네임 저장
136+
prevProfileMusic.current = profileMusic?.spotifyId ? profileMusic : null; // 이전 음악저장
137+
138+
setNickname(nickname);
139+
selectProfileMusic(prevProfileMusic.current);
130140
};
131141
loadMyProfile();
132142

0 commit comments

Comments
 (0)