Skip to content

Commit e34bc9d

Browse files
authored
[Refactor] 프로필, 내핏프티 개선 (#51)
2 parents b4d8228 + 292e273 commit e34bc9d

File tree

21 files changed

+165
-78
lines changed

21 files changed

+165
-78
lines changed

Fitfty/Projects/Coordinator/Sources/Profile/ProfileCoordinator.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private extension ProfileCoordinator {
100100
style: .small,
101101
contentViewController: coordinator.navigationController
102102
)
103-
bottomSheetDelegate = bottomSheetViewController
103+
coordinator.bottomSheetDelegate = bottomSheetViewController
104104
return bottomSheetViewController
105105
}
106106

@@ -122,7 +122,7 @@ extension ProfileCoordinator: ProfileCoordinatorInterface {
122122
func showMyFitfty(_ myFitftyType: MyFitftyType) {
123123
let coordinator = makeMyFitftyCoordinator(myFitftyType)
124124
coordinator.start()
125-
coordinator.navigationController.modalPresentationStyle = .overFullScreen
125+
coordinator.navigationController.modalPresentationStyle = .fullScreen
126126
navigationController.present(coordinator.navigationController, animated: true)
127127
}
128128

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
// MyFitftyError.swift
3+
// Core
4+
//
5+
// Created by 임영선 on 2023/02/23.
6+
// Copyright © 2023 Fitfty. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public enum MyFitftyError: Error {
12+
case noWeather
13+
case failUpload
14+
case failModify
15+
case failGetPost
16+
case others(String)
17+
}
18+
19+
extension MyFitftyError: LocalizedError {
20+
public var errorDescription: String? {
21+
switch self {
22+
case .noWeather:
23+
return NSLocalizedString("날씨를 불러오는데 실패했어요.\n해외 사진은 날씨 조회가 불가능해요.", comment: "noWeather")
24+
case .failUpload:
25+
return NSLocalizedString("핏프티 등록에 실패했어요. 잠시 후 다시 시도해 주세요.", comment: "failUpload")
26+
case .failModify:
27+
return NSLocalizedString("핏프티 수정에 실패했어요. 잠시 후 다시 시도해 주세요.", comment: "failModify")
28+
case .failGetPost:
29+
return NSLocalizedString("핏프티 정보를 가져오는데 실패했어요. 잠시 후 다시 시도해 주세요.", comment: "failGetPost")
30+
case .others(let message):
31+
return NSLocalizedString(message, comment: "Others Message")
32+
}
33+
}
34+
}

Fitfty/Projects/Core/Sources/LocalStorage.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public enum LocalKey: String {
1717
case userIdentifier
1818
case userAccount
1919
case hasCompletedWelcomePage
20+
case isGuest
2021
}
2122

2223
public protocol LocalStorageService: AnyObject {

Fitfty/Projects/Core/Sources/Utilities/UserManager.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public protocol UserManager {
2222
func updateUserState(_ state: Bool)
2323
func updateCurrentLocation(_ address: Address)
2424
func updateGender(_ gender: Gender)
25+
func getGender() -> Gender
2526
func updateGuestState(_ isGuest: Bool)
2627
func updateCompletedWelcomePage()
2728
func getCurrentGuestState() -> Bool
@@ -50,7 +51,7 @@ extension DefaultUserManager: UserManager {
5051
public var isNewUser: Bool {
5152
localStorage.read(key: .isNewUser) as? Bool ?? true
5253
}
53-
54+
5455
public var currentLocation: Address? {
5556
let address = localStorage.read(key: .currentLocation) as? [String: Any] ?? [:]
5657
return Address(address)
@@ -82,6 +83,10 @@ extension DefaultUserManager: UserManager {
8283
_gender = gender
8384
}
8485

86+
public func getGender() -> Gender {
87+
return _gender ?? .female
88+
}
89+
8590
public func updateGuestState(_ isGuest: Bool) {
8691
_guestState.send(isGuest)
8792
}

Fitfty/Projects/MainFeed/Sources/MyFitfty/ViewControllers/MyFitftyViewController.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ private extension MyFitftyViewController {
182182
button.tintColor = .black
183183
button.setPreferredSymbolConfiguration(.init(scale: .medium), forImageIn: .normal)
184184
button.addTarget(self, action: #selector(didTapCancelButton), for: .touchUpInside)
185+
button.contentEdgeInsets = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10)
186+
button.imageEdgeInsets = UIEdgeInsets(top: 0, left: -20, bottom: 0, right: 0)
185187
return button
186188
}()
187189
navigationItem.leftBarButtonItem = UIBarButtonItem(customView: leftButton)
@@ -419,7 +421,7 @@ extension MyFitftyViewController {
419421
private func contentSectionLayout() -> NSCollectionLayoutSection? {
420422
let layoutSize = NSCollectionLayoutSize(
421423
widthDimension: .fractionalWidth(1),
422-
heightDimension: .absolute(UIScreen.main.bounds.width*0.936+55+64)
424+
heightDimension: .absolute(UIScreen.main.bounds.width*0.936+13+40+64)
423425
)
424426
let group = NSCollectionLayoutGroup.horizontal(
425427
layoutSize: .init(

Fitfty/Projects/MainFeed/Sources/MyFitfty/ViewModel/MyFitfty/MyFitftyViewModel.swift

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public final class MyFitftyViewModel {
5353
]
5454

5555
private var genderTagItems: [(gender: String, isSelected: Bool)] = [
56-
("여성", true),
56+
("여성", false),
5757
("남성", false)
5858
]
5959

@@ -224,6 +224,7 @@ extension MyFitftyViewModel: MyFitftyViewModelInput {
224224
func viewDidLoad() {
225225
switch myFitftyType {
226226
case .uploadMyFitfty:
227+
changeTag(.genderTag, selectedIndex: userManager.gender == .female ? 0 : 1)
227228
currentState.send(.sections([
228229
MyFitftySection(sectionKind: .content, items: [MyFitftyCellModel.content(UUID())]),
229230
MyFitftySection(sectionKind: .weatherTag, items: getWeatherTagCellModels()),
@@ -293,12 +294,12 @@ extension MyFitftyViewModel: MyFitftyViewModelInput {
293294
currentState.send(.isLoading(false))
294295
} else {
295296
currentState.send(.isLoading(false))
296-
currentState.send(.errorMessage("프로필 조회에 알 수 없는 에러가 발생했습니다."))
297+
currentState.send(.errorMessage(MyFitftyError.failGetPost.localizedDescription))
297298
}
298299
} catch {
299-
Logger.debug(error: error, message: "작성했던 게시글 조회 실패")
300+
Logger.debug(error: error, message: MyFitftyError.failGetPost.localizedDescription)
300301
currentState.send(.isLoading(false))
301-
currentState.send(.errorMessage("작성했던 게시글 조회에 알 수 없는 에러가 발생했습니다."))
302+
currentState.send(.errorMessage(MyFitftyError.failGetPost.localizedDescription))
302303
}
303304
}
304305
}
@@ -430,7 +431,7 @@ private extension MyFitftyViewModel {
430431
], true))
431432
} catch {
432433
Logger.debug(error: error, message: "사진 날씨정보 가져오기 실패")
433-
self.currentState.send(.errorMessage("사진의 날씨 정보를 가져오는데 알 수 없는 에러가 발생했습니다."))
434+
self.currentState.send(.errorMessage(MyFitftyError.noWeather.localizedDescription))
434435
}
435436
}
436437
}
@@ -471,7 +472,7 @@ private extension MyFitftyViewModel {
471472
self.currentState.send(.completed(true))
472473
} else {
473474
self.currentState.send(.completed(false))
474-
self.currentState.send(.errorMessage("핏프티 등록에 알 수 없는 에러가 발생했습니다."))
475+
self.currentState.send(.errorMessage(MyFitftyError.failUpload.localizedDescription))
475476
}
476477

477478
case .modifyMyFitfty:
@@ -488,25 +489,23 @@ private extension MyFitftyViewModel {
488489
photoTakenTime: self.photoTakenTime,
489490
tagGroup: tagGroup
490491
)
491-
print(request)
492492
let response = try await putPost(request: request, boardToken: boardToken)
493493
if response.result == "SUCCESS" {
494494
self.currentState.send(.completed(true))
495495
} else {
496-
print(response)
497496
self.currentState.send(.completed(false))
498-
self.currentState.send(.errorMessage("핏프티 수정에 알 수 없는 에러가 발생했습니다."))
497+
self.currentState.send(.errorMessage(MyFitftyError.failModify.localizedDescription))
499498
}
500499
}
501500
} else {
502501
self.currentState.send(.completed(false))
503-
self.currentState.send(.errorMessage("핏프티 등록에 알 수 없는 에러가 발생했습니다."))
502+
self.currentState.send(.errorMessage(MyFitftyError.failModify.localizedDescription))
504503
}
505504
self.currentState.send(.isLoading(false))
506505
} catch {
507-
Logger.debug(error: error, message: "핏프티 등록 실패")
506+
Logger.debug(error: error, message: MyFitftyError.failUpload.localizedDescription)
508507
self.currentState.send(.isLoading(false))
509-
self.currentState.send(.errorMessage("핏프티 등록에 알 수 없는 에러가 발생했습니다."))
508+
self.currentState.send(.errorMessage(MyFitftyError.failUpload.localizedDescription))
510509
}
511510
}
512511
}

Fitfty/Projects/MainFeed/Sources/MyFitfty/Views/UploadCody/ContentCell.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ final class ContentCell: UICollectionViewCell {
115115
contentView.addSubviews(codyImageView, backgroundButton, uploadPhotoButton,
116116
contentTextView, guidanceLabel, tapView)
117117
NSLayoutConstraint.activate([
118-
backgroundButton.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 15),
118+
backgroundButton.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 13),
119119
backgroundButton.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
120120
backgroundButton.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),
121121
backgroundButton.heightAnchor.constraint(equalToConstant: UIScreen.main.bounds.width*0.936),
@@ -125,7 +125,7 @@ final class ContentCell: UICollectionViewCell {
125125
tapView.trailingAnchor.constraint(equalTo: backgroundButton.trailingAnchor),
126126
tapView.heightAnchor.constraint(equalTo: backgroundButton.heightAnchor),
127127

128-
codyImageView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 15),
128+
codyImageView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 13),
129129
codyImageView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
130130
codyImageView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),
131131
codyImageView.heightAnchor.constraint(equalTo: backgroundButton.heightAnchor),

Fitfty/Projects/Profile/Sources/Post/ViewControllers/PostViewController.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ final public class PostViewController: UIViewController {
114114
self?.showAlert(message: message)
115115
case .isLoading(let isLoading):
116116
isLoading ? self?.loadingIndicatorView.startAnimating() : self?.loadingIndicatorView.stopAnimating()
117+
case .bookmark(let currentIsSelected, let isSelected, let bookmarkCount):
118+
guard let isSelected = isSelected,
119+
let bookmarkCount = bookmarkCount,
120+
let currentIsSelected = currentIsSelected else {
121+
return
122+
}
123+
self?.postView.setBookmarkCount(count: bookmarkCount, currentIsSelected: currentIsSelected, isSelected: isSelected)
117124
}
118125
}).store(in: &cancellables)
119126
}

Fitfty/Projects/Profile/Sources/Post/ViewModel/PostViewModel.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public final class PostViewModel {
2323
private var currentState: CurrentValueSubject<ViewModelState?, Never> = .init(nil)
2424
private var cancellables: Set<AnyCancellable> = .init()
2525
private var isBookmarked: Bool?
26+
private var isCurrentBookmarked: Bool?
27+
private var bookmarkCount: Int?
2628

2729
public init() { }
2830

@@ -53,6 +55,7 @@ extension PostViewModel: ViewModelType {
5355
case isLoading(Bool)
5456
case errorMessage(String)
5557
case update(PostResponse)
58+
case bookmark(Bool?, Bool?, Int?)
5659
}
5760

5861
public var state: AnyPublisher<ViewModelState, Never> { currentState.compactMap { $0 }.eraseToAnyPublisher() }
@@ -73,6 +76,8 @@ private extension PostViewModel {
7376
return
7477
}
7578
self.isBookmarked = response.data?.bookmarked
79+
self.isCurrentBookmarked = response.data?.bookmarked
80+
self.bookmarkCount = response.data?.bookmarkCnt
7681
self.currentState.send(.update(response))
7782
currentState.sink(receiveValue: { [weak self] state in
7883
switch state {
@@ -104,7 +109,8 @@ private extension PostViewModel {
104109
if response.result == .fail {
105110
self.currentState.send(.errorMessage("북마크 업데이트 실패"))
106111
}
107-
update(boardToken: boardToken)
112+
self.isBookmarked = !isBookmarked
113+
self.currentState.send(.bookmark(self.isCurrentBookmarked, self.isBookmarked, self.bookmarkCount))
108114
} catch {
109115
self.currentState.send(.errorMessage("북마크 업데이트 실패"))
110116
Logger.debug(error: error, message: "북마크 업데이트 실패")

Fitfty/Projects/Profile/Sources/Post/Views/MyPostBottomSheetView.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,3 @@ extension MyPostBottomSheetView {
7575
}
7676

7777
}
78-

0 commit comments

Comments
 (0)