Skip to content

Commit

Permalink
[FIX/#177] FeedView 삭제 후 Alert 출력
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkySide committed Nov 3, 2024
1 parent 23010fe commit d44a33a
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 32 deletions.
23 changes: 13 additions & 10 deletions PLAT/PLAT/Domain/UseCase/TrackUseCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,19 @@ extension TrackUseCase {
case .failure(let error): return .failure(error)
}
}

/// 선택한 트랙을 삭제합니다.
func deleteTrack(trackId: Int) async -> Result<Void, Error> {
let result = await trackService.delete(trackId: trackId)
switch result {
case .success:
feedTrackList.removeAll { $0.id == trackId }
return .success(())

case .failure(let error):
return .failure(error)
}
}
}

// MARK: - Effect
Expand All @@ -144,7 +157,6 @@ extension TrackUseCase {
case fetchCurrentTrack(id: Int)
case uploadTrack(isrc: String, image: UIImage?, content: String?, location: Location)
case reportTrack(trackId: Int)
case deleteTrack(trackId: Int)
}

func effect(_ effect: Effect) {
Expand Down Expand Up @@ -180,15 +192,6 @@ extension TrackUseCase {
case .failure(let error): print(error) // TODO: 에러 처리
}
}

case .deleteTrack(trackId: let trackId):
Task {
let result = await trackService.delete(trackId: trackId)
switch result {
case .success: feedTrackList.removeAll { $0.id == trackId }
case .failure(let error): print(error) // TODO: 에러 처리
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ private struct MusicControllerView: View {
Menu {
if authUseCase.checkMyTrack(currentTrack: trackUseCase.currentTrack) {
Button(role: .destructive) {
trackUseCase.effect(.deleteTrack(trackId: Int(trackUseCase.currentTrack.id)))
#warning("삭제하기 로직 수정")
// trackUseCase.effect(.deleteTrack(trackId: Int(trackUseCase.currentTrack.id)))
} label: {
Text("삭제하기")
}
Expand Down
81 changes: 60 additions & 21 deletions PLAT/PLAT/Presentaion/TrackFeed/TrackFeedView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -192,27 +192,8 @@ private struct FeedRowView: View {

Spacer()

Menu {
if authUseCase.checkMyTrack(currentTrack: track) {
Button(role: .destructive) {
trackUseCase.effect(.deleteTrack(trackId: Int(track.id)))
} label: {
Text("삭제하기")
}
} else {
Button(role: .destructive) {
pathModel.push(.report(trackId: track.id))
} label: {
Text("신고하기")
}
}
} label: {
Image(systemName: "ellipsis")
.foregroundColor(.white)
.frame(width: 20, height: 20)
.padding(.bottom, 8)
}
.padding(.trailing, 18)
MenuButton(isLoading: $isLoading, track: track)
.padding(.trailing, 18)
}
.padding(.bottom, 8)

Expand Down Expand Up @@ -252,6 +233,64 @@ private struct FeedRowView: View {
}
}

// MARK: - MenuButton

private struct MenuButton: View {

@Environment(PathModel.self) private var pathModel
@Environment(AuthUseCase.self) private var authUseCase
@Environment(TrackUseCase.self) private var trackUseCase

@State private var isDeleteAlertPresented = false
@State private var isDeleteCompletionAlertPresented = false
@State private var deleteCompletionALertMessage = ""

@Binding private(set) var isLoading: Bool

let track: Track

var body: some View {
Menu {
if authUseCase.checkMyTrack(currentTrack: track) {
Button(role: .destructive) {
isDeleteAlertPresented.toggle()
} label: {
Text("삭제하기")
}
} else {
Button(role: .destructive) {
pathModel.push(.report(trackId: track.id))
} label: {
Text("신고하기")
}
}
} label: {
Image(systemName: "ellipsis")
.foregroundColor(.white)
.frame(width: 20, height: 20)
.padding(.bottom, 8)
}
.alert("트랙을 삭제하시겠어요?", isPresented: $isDeleteAlertPresented) {
AlertActionButton(variant: .cancel)
AlertActionButton(variant: .confim) {
Task {
isLoading = true
let result = await trackUseCase.deleteTrack(trackId: Int(track.id))
switch result {
case .success: deleteCompletionALertMessage = "트랙이 삭제되었습니다"
case .failure: deleteCompletionALertMessage = "일시적인 오류로 트랙 삭제에 실패했습니다"
}
isDeleteCompletionAlertPresented.toggle()
isLoading = false
}
}
}
.alert(deleteCompletionALertMessage, isPresented: $isDeleteCompletionAlertPresented) {
AlertActionButton(variant: .confim)
}
}
}

// MARK: - FeedProfileImage

private struct FeedProfileImage: View {
Expand Down

0 comments on commit d44a33a

Please sign in to comment.