Skip to content

Commit

Permalink
merge #397: 타임라인 수정 / 삭제 간 문제 해결
Browse files Browse the repository at this point in the history
[fix] 타임라인 수정 / 삭제 간 문제 해결
  • Loading branch information
kth1210 authored Jan 16, 2024
2 parents 5a8bff8 + d82b7fd commit 94b9b7a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ private extension TimelineDetailVC {
viewModel.state
.map(\.isEdit)
.filter { $0 }
.removeDuplicates()
.withUnretained(self)
.sink { owner, _ in
let timelineDetailInfo = owner.viewModel.currentState.timelineDetailInfo
Expand All @@ -246,6 +245,7 @@ private extension TimelineDetailVC {
timelineDetailInfo: timelineDetailInfo
)
owner.navigationController?.pushViewController(timelineEditVC, animated: true)
owner.viewModel.sendAction(.movedToEdit)
}
.store(in: &cancellables)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ enum TimelineDetailAction: BaseAction {
case editTimeline
case deleteTimeline
case translateTimeline
case movedToEdit
}

enum TimelineDetailSideEffect: BaseSideEffect {
Expand All @@ -34,6 +35,7 @@ enum TimelineDetailSideEffect: BaseSideEffect {
case popToTimeline(Bool)
case showTimelineDetailEditing
case loadTimelineTranslatedInfo(TimelineTranslatedInfo)
case resetIsEditStatus
}

struct TimelineDetailState: BaseState {
Expand Down Expand Up @@ -68,6 +70,9 @@ final class TimelineDetailViewModel: BaseViewModel<TimelineDetailAction, Timelin

case .translateTimeline:
return translateTimeline()

case .movedToEdit:
return .just(.resetIsEditStatus)
}
}

Expand All @@ -91,6 +96,9 @@ final class TimelineDetailViewModel: BaseViewModel<TimelineDetailAction, Timelin

case let .timelineDetailError(error):
print(error)

case .resetIsEditStatus:
newState.isEdit = false
}

return newState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,19 @@ final class TimelineWritingVC: UIViewController {
}

@objc private func imageButtonCancelTapped() {
selectImageButton.setImage(nil)
viewModel.sendAction(.imageDidChange(nil))
selectImageButton.updateView()
changeImage(to: nil)
}

@objc private func locationButtonCancelTapped() {
selectLocation.setText(to: Constants.selectLocation)
viewModel.sendAction(.placeDidChange(.emtpy))
}

private func changeImage(to image: UIImage?) {
selectImageButton.setImage(image)
viewModel.sendAction(.imageDidChange)
}

private func actionKeyboardWillShow(_ keyboardFrame: CGRect) {
self.scrollView.contentInset.bottom = keyboardFrame.size.height
scrollView.scrollRectToVisible(textView.frame, animated: true)
Expand Down Expand Up @@ -336,6 +339,7 @@ private extension TimelineWritingVC {

viewModel.state
.map(\.imageURLString)
.removeDuplicates()
.withUnretained(self)
.sink { owner, imageURLString in
owner.selectImageButton.setImage(urlString: imageURLString)
Expand Down Expand Up @@ -439,7 +443,7 @@ extension TimelineWritingVC: PHPickerViewControllerDelegate {
guard let self = self else { return }
DispatchQueue.main.async {
guard let selectedImage = image as? UIImage else { return }
self.selectImageButton.setImage(selectedImage)
self.changeImage(to: selectedImage)
}
}

Expand All @@ -465,7 +469,7 @@ extension TimelineWritingVC: LocationSearchDelegate {
extension TimelineWritingVC: TLNavigationBarDelegate {
func rightButtonDidTapped() {
if let selectedImage = selectImageButton.imageView.image {
let image = selectedImage.downSampling()
let image = viewModel.currentState.isOriginImage ? selectedImage : selectedImage.downSampling()
let imageData = image?.jpegData(compressionQuality: 1)
viewModel.sendAction(.tapCompleteButton(imageData))
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class SelectImageButton: UIView {

// MARK: - UI Components

let view: UIView = {
private let view: UIView = {
let view = UIView()
view.layer.cornerRadius = Metric.cornerRadius
view.clipsToBounds = true
Expand All @@ -41,7 +41,7 @@ final class SelectImageButton: UIView {

let imageView: UIImageView = .init()

let selectView: UIStackView = {
private let selectView: UIStackView = {
let view = UIStackView()
view.axis = .vertical
view.alignment = .center
Expand All @@ -51,26 +51,19 @@ final class SelectImageButton: UIView {
return view
}()

let selectViewIcon: UIImageView = {
private let selectViewIcon: UIImageView = {
let view = UIImageView(image: TLImage.Common.album)
view.contentMode = .scaleAspectFit

return view
}()

let selectViewLabel: TLLabel = {
private let selectViewLabel: TLLabel = {
let label = TLLabel(font: TLFont.body2, color: TLColor.white)
label.textAlignment = .center
return label
}()

// MARK: - Properties

private var hasImage: Bool {
imageView.image != nil
}
let width = Metric.viewWidth + Metric.buttonOffset

// MARK: - initialize

init() {
Expand All @@ -86,20 +79,20 @@ final class SelectImageButton: UIView {

// MARK: - Functions

func updateView() {
private func updateView(hasImage: Bool) {
selectView.isHidden = hasImage
imageView.isHidden = !hasImage
cancelButton.isHidden = !hasImage
}

func setImage(_ image: UIImage?) {
imageView.image = image
updateView()
updateView(hasImage: image != nil)
}

func setImage(urlString: String?, imagePath: String? = nil) {
imageView.setImage(from: urlString, imagePath: imagePath)
updateView()
updateView(hasImage: urlString != nil)
}

}
Expand All @@ -111,7 +104,7 @@ private extension SelectImageButton {
func setupAttributes() {
selectViewLabel.setText(to: "선택")
view.backgroundColor = TLColor.backgroundGray
updateView()
updateView(hasImage: false)
}

func setupLayout() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ enum TimelineWritingAction: BaseAction {
case metaDataTime(String)
case searchPlace(String)
case placeDidChange(TimelinePlace)
case imageDidChange(Data?)
case imageDidChange
case placeDidScrollToBottom
case tapCompleteButton(Data?)
case configTimelineDetailInfo(TimelineDetailInfo)
Expand All @@ -43,7 +43,7 @@ enum TimelineWritingSideEffect: BaseSideEffect {
case updateTitleState(String)
case updateContentState(String)
case updateTimeState(String)
case updateImageState(Data?)
case updateImageState
case updatePlaceState(TimelinePlace)
case updatePlaceKeyword(String)
case fetchPlaceList(TimelinePlaceList)
Expand All @@ -55,6 +55,7 @@ enum TimelineWritingSideEffect: BaseSideEffect {
}

struct TimelineWritingState: BaseState {
var isOriginImage: Bool = false
var isCompletable: Bool = false
var timelineDetailRequest: TimelineDetailRequest = .empty
var popToTimeline: Bool = false
Expand Down Expand Up @@ -113,8 +114,8 @@ final class TimelineWritingViewModel: BaseViewModel<TimelineWritingAction, Timel
case .placeDidChange(let place):
return .just(.updatePlaceState(place))

case .imageDidChange(let imageData):
return .just(.updateImageState(imageData))
case .imageDidChange:
return .just(.updateImageState)

case let .searchPlace(keyword):
return Publishers.Merge(
Expand Down Expand Up @@ -157,8 +158,8 @@ final class TimelineWritingViewModel: BaseViewModel<TimelineWritingAction, Timel
case .updateTimeState(let time):
newState.timelineDetailRequest.time = time

case .updateImageState(let imageData):
newState.timelineDetailRequest.image = imageData
case .updateImageState:
newState.isOriginImage = false

case .createTimeline:
newState.popToTimeline = true
Expand Down Expand Up @@ -187,9 +188,11 @@ final class TimelineWritingViewModel: BaseViewModel<TimelineWritingAction, Timel
case let .showTimelineInfo(detailRequest):
newState.timelineDetailRequest = detailRequest
newState.isEdit = true
newState.isCompletable = completeButtonState(newState)

case let .setOriginImage(imageURL):
newState.imageURLString = imageURL
newState.isOriginImage = true

case let .popToTimelineDetail(isSuccess):
newState.isEditCompleted = isSuccess
Expand Down

0 comments on commit 94b9b7a

Please sign in to comment.