Skip to content

Commit

Permalink
Fix editting profile
Browse files Browse the repository at this point in the history
  • Loading branch information
hhhello0507 committed Oct 7, 2024
1 parent 519091f commit 1c61167
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import jakarta.validation.constraints.Size
data class EditUserReq(
@Size(min = 1, max = 24)
val nickname: String?,
val graduatingYear: Int,
val graduatingYear: Int?,
val schoolId: Long?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ extension EditGraduatingYearView {
.padding(insets)
}
.onReceive(viewModel.$editGraduatingYearFlow) { flow in
print("WOWOWOWOW")
print(flow)
switch flow {
case .success:
router.toRoot()
appState.fetchCurrentUser()
router.toRoot()
case .failure:
dialog.present(
.init(title: "수정 실패")
Expand Down
28 changes: 17 additions & 11 deletions Graduating-iOS/Graduating/Feature/EditProfile/EditProfileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,25 @@ extension EditProfileView: View {
}
}

extension EditProfileView {
@ViewBuilder
func safeAreaContent() -> some View {
MyButton(
"수정 완료",
isEnabled: viewModel.isValidInput,
expanded: true
) {
viewModel.editProfile()
}
.padding(.horizontal, 20)
.padding(.bottom, 8)
}
}

extension EditProfileView {
func initNickname() {
guard let user = appState.currentUser.data else { return }
viewModel.nickname = user.nickname
viewModel.initNickname(user.nickname)
}

func receiveEditProfileFlow(flow: Flow) {
Expand All @@ -41,8 +56,8 @@ extension EditProfileView {
dialog.present(
.init(title: "프로필 수정 성공")
.primaryButton("닫기") {
appState.fetchCurrentUser()
router.pop()
// appState.fetchCurrentUser() // TODO: Handle
}
)
case .failure:
Expand All @@ -54,13 +69,4 @@ extension EditProfileView {
break
}
}

@ViewBuilder
func safeAreaContent() -> some View {
MyButton("수정 완료", expanded: true) {
viewModel.editProfile()
}
.padding(.horizontal, 20)
.padding(.bottom, 8)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,24 @@ import Shared

final class EditProfileViewModel: ObservableObject {
@Published var editProfileFlow = Flow.idle
var originNickname: String?
@Published var nickname = ""
var subscriptions = Set<AnyCancellable>()

var isValidInput: Bool {
!nickname.isEmpty && originNickname != nickname
}
}

extension EditProfileViewModel {
func initNickname(_ nickname: String) {
self.originNickname = nickname
self.nickname = nickname
}

func editProfile() {
UserService.shared.editUser(
.init(
nickname: nickname
)
.init(nickname: nickname)
)
.flow(\.editProfileFlow, on: self)
.silentSink()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ extension EditSchoolView {
.onReceive(viewModel.$editSchoolFlow) { flow in
switch flow {
case .success:
router.toRoot()
appState.fetchCurrentUser()
router.toRoot()
case .failure:
dialog.present(
.init(title: "수정 실패")
Expand Down
1 change: 0 additions & 1 deletion Graduating-iOS/Graduating/Feature/ViewModel/AppState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ extension AppState {
}

func fetchCurrentUser() {
guard currentUser.data == nil else { return }
UserService.shared.getMe()
.resource(\.currentUser, on: self)
.sink {
Expand Down
3 changes: 1 addition & 2 deletions Graduating-iOS/Shared/Combine/Flow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ public enum Flow {
case fetching
case success
case failure(Error)
case finished
}

public extension Publisher {
Expand All @@ -27,7 +26,7 @@ public extension Publisher {
receiveCompletion: { completion in
switch completion {
case .finished:
object[keyPath: keyPath] = .finished
break
case .failure(let error):
object[keyPath: keyPath] = .failure(error)
}
Expand Down

0 comments on commit 1c61167

Please sign in to comment.