diff --git a/iOS/Features/Home/Sources/Home/Presentation/HomeViewController.swift b/iOS/Features/Home/Sources/Home/Presentation/HomeViewController.swift index bc65e6b..1bf3e11 100644 --- a/iOS/Features/Home/Sources/Home/Presentation/HomeViewController.swift +++ b/iOS/Features/Home/Sources/Home/Presentation/HomeViewController.swift @@ -144,10 +144,15 @@ public final class HomeViewController: HomeBottomSheetViewController { self.viewModel.state.journeyDidCancelled .receive(on: DispatchQueue.main) - .sink { [weak self] cancelledJourney in + .sink(receiveCompletion: { [weak self] completion in + if case .failure = completion { + self?.contentViewController.clearOverlays() + self?.contentViewController.recordingDidStop() + } + }, receiveValue: { [weak self] cancelledJourney in self?.contentViewController.clearOverlays() self?.contentViewController.recordingDidStop(cancelledJourney) - } + }) .store(in: &self.cancellables) self.viewModel.state.visibleJourneys @@ -196,7 +201,7 @@ public final class HomeViewController: HomeBottomSheetViewController { private func updateButtonMode(isRecording: Bool) { UIView.transition(with: self.view, - duration: 0.5, + duration: 0.34, options: .transitionCrossDissolve, animations: { [weak self] in self?.startButton.isHidden = isRecording diff --git a/iOS/Features/Home/Sources/Home/Presentation/HomeViewModel.swift b/iOS/Features/Home/Sources/Home/Presentation/HomeViewModel.swift index 86be724..052cf92 100644 --- a/iOS/Features/Home/Sources/Home/Presentation/HomeViewModel.swift +++ b/iOS/Features/Home/Sources/Home/Presentation/HomeViewModel.swift @@ -31,7 +31,7 @@ public final class HomeViewModel { // Passthrough public var journeyDidStarted = PassthroughSubject() public var journeyDidResumed = PassthroughSubject() - public var journeyDidCancelled = PassthroughSubject() + public var journeyDidCancelled = PassthroughSubject() public var visibleJourneys = PassthroughSubject<[Journey], Never>() // CurrentValue @@ -181,6 +181,7 @@ private extension HomeViewModel { self.state.journeyDidCancelled.send(deletedJourney) case .failure(let error): MSLogger.make(category: .home).error("\(error)") + self.state.journeyDidCancelled.send(completion: .failure(error)) } } } diff --git a/iOS/Features/Home/Sources/NavigateMap/Presentation/Common/MapViewController+EventListener.swift b/iOS/Features/Home/Sources/NavigateMap/Presentation/Common/MapViewController+EventListener.swift index 36644e4..c4fa331 100644 --- a/iOS/Features/Home/Sources/NavigateMap/Presentation/Common/MapViewController+EventListener.swift +++ b/iOS/Features/Home/Sources/NavigateMap/Presentation/Common/MapViewController+EventListener.swift @@ -71,7 +71,7 @@ extension MapViewController { #endif } - public func recordingDidStop(_ stoppedJourney: RecordingJourney) { + public func recordingDidStop(_ stoppedJourney: RecordingJourney? = nil) { guard self.viewModel is RecordJourneyViewModel else { MSLogger.make(category: .home).error("여정이 종료되어야 하지만 이미 Map에서 NavigateMapViewModel을 사용하고 있습니다.") return @@ -85,7 +85,9 @@ extension MapViewController { self.locationManager.allowsBackgroundLocationUpdates = false #if DEBUG - MSLogger.make(category: .home).debug("여정 기록이 종료되었습니다: \(stoppedJourney)") + if let stoppedJourney { + MSLogger.make(category: .home).debug("여정 기록이 종료되었습니다: \(stoppedJourney)") + } #endif } diff --git a/iOS/MSData/Sources/MSData/RepositoryImplementation/JourneyRepository.swift b/iOS/MSData/Sources/MSData/RepositoryImplementation/JourneyRepository.swift index ffe90ef..fdfa658 100644 --- a/iOS/MSData/Sources/MSData/RepositoryImplementation/JourneyRepository.swift +++ b/iOS/MSData/Sources/MSData/RepositoryImplementation/JourneyRepository.swift @@ -150,18 +150,16 @@ public struct JourneyRepositoryImplementation: JourneyRepository { public mutating func deleteJourney(_ recordingJourney: RecordingJourney, userID: UUID) async -> Result { + defer { try? self.recordingJourney.finish() } + let requestDTO = DeleteJourneyRequestDTO(userID: userID, journeyID: recordingJourney.id) let router = JourneyRouter.deleteJourney(dto: requestDTO) let result = await self.networking.request(DeleteJourneyResponseDTO.self, router: router) + switch result { case .success(let responseDTO): - do { - try self.recordingJourney.finish() - let deletedJourney = responseDTO.toDomain() - return .success(deletedJourney) - } catch { - return .failure(error) - } + let deletedJourney = responseDTO.toDomain() + return .success(deletedJourney) case .failure(let error): return .failure(error) }