Skip to content

Commit

Permalink
🐛 Spot 완료 Navigation 버그 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
SwiftyJunnos committed Jan 10, 2024
1 parent 9d52ea1 commit 3409893
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,9 @@ public final class SaveSpotViewController: UIViewController {
// MARK: - Combine Binding

private func bind() {
self.viewModel.state.spot
self.viewModel.state.uploadedSpot
.receive(on: DispatchQueue.main)
.sink { [weak self] spot in
guard let spot = spot else { return }
self?.navigationDelegate?.popToHome(spot: spot)
}
.store(in: &self.cancellables)
Expand Down Expand Up @@ -262,12 +261,11 @@ public final class SaveSpotViewController: UIViewController {

private func completeButtonDidTap() {
guard let jpegData = self.image.jpegData(compressionQuality: 0.1) else {
MSLogger.make(category: .spot).debug("현재 이미지를 Data로 변환할 수 없습니다.")
MSLogger.make(category: .spot).warning("현재 이미지를 Data로 변환할 수 없습니다.")
return
}

self.viewModel.trigger(.startUploadSpot(jpegData))
self.navigationDelegate?.popToHome()
self.viewModel.trigger(.uploadSpot(jpegData))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ import MSLogger
public final class SaveSpotViewModel {

public enum Action {
case startUploadSpot(Data)
case uploadSpot(Data)
}

public struct State {
public var spot = PassthroughSubject<Spot?, Never>()
// Passthrough
public var uploadedSpot = PassthroughSubject<Spot, Never>()
}

// MARK: - Properties
Expand Down Expand Up @@ -51,21 +52,21 @@ internal extension SaveSpotViewModel {

func trigger(_ action: Action) {
switch action {
case .startUploadSpot(let data):
case .uploadSpot(let data):
Task {
guard let recordingJourneyID = self.journeyRepository.recordingJourneyID else {
MSLogger.make(category: .spot).error("recoding 중인 journeyID를 찾지 못하였습니다.")
return
}
let spot = RequestableSpot(journeyID: recordingJourneyID,
coordinate: self.coordinate,
timestamp: .now,
photoData: data)
coordinate: self.coordinate,
timestamp: .now,
photoData: data)

let result = await self.spotRepository.upload(spot: spot)
switch result {
case .success(let spot):
self.state.spot.send(spot)
self.state.uploadedSpot.send(spot)
MSLogger.make(category: .network).debug("성공적으로 업로드되었습니다: \(spot)")
case .failure(let error):
MSLogger.make(category: .network).error("\(error): 업로드에 실패하였습니다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,13 +351,7 @@ extension SpotViewController: UIImagePickerControllerDelegate {
self.presentSpotSaveViewController(with: image, coordinate: self.viewModel.coordinate)
}

}

// MARK: - Functions

private extension SpotViewController {

func presentSpotSaveViewController(with image: UIImage, coordinate: Coordinate) {
private func presentSpotSaveViewController(with image: UIImage, coordinate: Coordinate) {
self.viewModel.stopCamera()
self.navigationDelegate?.presentSaveSpot(using: image, coordinate: coordinate)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ public final class SpotViewModel: NSObject {

weak var delegate: ShotDelegate?
var swapMode: SwapMode = .back {
didSet {
self.configureSwapMode()
}
didSet { self.configureSwapMode() }
}

private let session = AVCaptureSession()
Expand Down
16 changes: 10 additions & 6 deletions iOS/MusicSpot/MusicSpot/Coordinator/SpotCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ extension SpotCoordinator: SpotNavigationDelegate {
picker.sourceType = .photoLibrary
picker.allowsEditing = true
picker.delegate = spotViewController
spotViewController.present(picker, animated: true)
self.navigationController.present(picker, animated: true)
}

func presentSaveSpot(using image: UIImage, coordinate: Coordinate) {
Expand All @@ -61,10 +61,12 @@ extension SpotCoordinator: SpotNavigationDelegate {
spotRepository: spotRepository,
coordinate: coordinate)
let spotSaveViewController = SaveSpotViewController(image: image, viewModel: viewModel)
spotSaveViewController.modalPresentationStyle = .fullScreen
spotSaveViewController.modalPresentationStyle = .overFullScreen
spotSaveViewController.navigationDelegate = self
self.navigationController.presentedViewController?.dismiss(animated: true)
self.navigationController.present(spotSaveViewController, animated: true)

self.navigationController.presentedViewController?.dismiss(animated: true) { [weak self] in
self?.navigationController.present(spotSaveViewController, animated: true)
}
}

func dismissToSpot() {
Expand All @@ -76,8 +78,10 @@ extension SpotCoordinator: SpotNavigationDelegate {
spotSaveViewController.dismiss(animated: true)
}

func popToHome(spot: Spot? = nil) {
self.finish()
func popToHome(spot: Spot?) {
self.navigationController.presentedViewController?.dismiss(animated: true) { [weak self] in
self?.finish()
}
}

}

0 comments on commit 3409893

Please sign in to comment.