Skip to content

Commit

Permalink
[FIX/#177] FeedView 좋아요 로직 업데이트
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkySide committed Nov 3, 2024
1 parent 87f2ad1 commit 61e0918
Showing 1 changed file with 16 additions and 28 deletions.
44 changes: 16 additions & 28 deletions PLAT/PLAT/Presentaion/TrackFeed/TrackFeedView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -204,16 +204,21 @@ private struct FeedRow: View {
.padding(.bottom, 8)

FeedActionView(
track: track,
isNonePlaylistToastPresented: $isNonePlaylistToastPresented,
currentTrack: $musicControlUseCase.state.currentTrack,
isLoading: $isLoading
isLoading: $isLoading,
track: track
)
.padding(.bottom, 18)
}
}
.padding(.top, 18)

Sepeartor()
}
}

private struct Sepeartor: View {
var body: some View {
Rectangle()
.foregroundColor(.gray9)
.frame(maxWidth: .infinity)
Expand Down Expand Up @@ -564,41 +569,21 @@ private struct FeedActionView: View {
@Environment(MusicControlUseCase.self) private var musicControlUseCase
@Environment(PlaylistUseCase.self) private var playlistUseCase

let track: Track
@State private var isLike = false

@Binding private(set) var isNonePlaylistToastPresented: Bool
@Binding private(set) var currentTrack: Track?
@Binding private(set) var isLoading: Bool

/// Feed를 업데이트합니다.
private func updateFeed() {
Task {
let trackList = await trackUseCase.fetchFeedTrackList()

let fetchMusicListResult = await musicControlUseCase.fetchMusicList(from: trackList)
switch fetchMusicListResult {
case .success(let musicList):
trackUseCase.updateFeedTrackListMusicInfo(from: musicList)

case .failure(let error):
// TODO: 에러 처리
print(error)
}
}
}
let track: Track

/// 트랙의 좋아요를 업데이트합니다.
private func likeTrack() {
Task {
isLoading = true
let result = await trackUseCase.likeTrack(trackId: Int(track.id), isLike: track.isLike)
switch result {

// TODO: track을 눈속임 하는 것처럼 State로 관리해서 계속 Fetch 안할 수 있게 만들기
case .success: updateFeed()
case .failure(let error): print(error)
case let .success(bool): isLike = bool
case let .failure(error): print(error)
}
isLoading = false
}
}

Expand All @@ -607,7 +592,7 @@ private struct FeedActionView: View {
Button {
likeTrack()
} label: {
Image(systemName: track.isLike ? SystemImage.like : SystemImage.unLike)
Image(systemName: isLike ? SystemImage.like : SystemImage.unLike)
.foregroundColor(.white)
.frame(width: 20, height: 20)
.padding(.trailing, 31)
Expand All @@ -629,6 +614,9 @@ private struct FeedActionView: View {
.padding(.trailing, 220)
}
}
.task {
isLike = track.isLike
}
}
}

Expand Down

0 comments on commit 61e0918

Please sign in to comment.