-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Style/Feat] ProfileEditView를 구현했습니다.
- Loading branch information
Showing
7 changed files
with
588 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// User.swift | ||
// Score | ||
// | ||
// Created by sole on 4/12/24. | ||
// | ||
|
||
import Foundation | ||
|
||
//MARK: - User | ||
|
||
struct User: Equatable, | ||
Hashable { | ||
// identifier | ||
let nickName: String | ||
let profileImageName: String | ||
let sex: Sex | ||
let height: Int | ||
let weight: Int | ||
let schoolName: String | ||
let grade: Int | ||
// 운동 알림 시간? | ||
|
||
//MARK: - defaultModel | ||
|
||
static let defaultModel: User = .init(nickName: "왕감자", | ||
profileImageName: "", | ||
sex: .female, | ||
height: 160, | ||
weight: 50, | ||
schoolName: "감자대학교", | ||
grade: 1) | ||
} | ||
|
||
//MARK: - Sex | ||
|
||
enum Sex: String { | ||
case male = "남" | ||
case female = "여" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// PhotoPickerFeature.swift | ||
// Score | ||
// | ||
// Created by sole on 4/14/24. | ||
// | ||
|
||
import ComposableArchitecture | ||
import PhotosUI | ||
import SwiftUI | ||
|
||
@Reducer | ||
struct PhotoPickerFeature { | ||
struct State: Equatable { | ||
var selectedImage: Image? | ||
@BindingState var photoItem: PhotosPickerItem? | ||
} | ||
|
||
enum Action: BindableAction { | ||
case binding(BindingAction<State>) | ||
case photoSelectChanging(PhotosPickerItem?) | ||
case imageUpdating(Image?) | ||
} | ||
|
||
var body: some ReducerOf<Self> { | ||
BindingReducer() | ||
|
||
Reduce { state, action in | ||
switch action { | ||
case .binding(_): | ||
return .none | ||
case .photoSelectChanging(let photosPickerItem): | ||
guard let photosPickerItem | ||
else { | ||
return .send(.imageUpdating(nil)) | ||
} | ||
return .run { send in | ||
let image = try await photosPickerItem.loadTransferable(type: Image.self) | ||
await send(.imageUpdating(image)) | ||
} | ||
case .imageUpdating(let image): | ||
guard let image | ||
else { return .none } | ||
state.selectedImage = image | ||
return .none | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// | ||
// ProfileEditFeature.swift | ||
// Score | ||
// | ||
// Created by sole on 4/12/24. | ||
// | ||
|
||
import ComposableArchitecture | ||
import PhotosUI | ||
import SwiftUI | ||
|
||
@Reducer | ||
struct ProfileEditFeature { | ||
struct State: Equatable { | ||
var displayedUser: User? | ||
|
||
var displayedProfileImage: Image? | ||
|
||
@BindingState var displayedNickName: String | ||
@BindingState var displayedHeight: String | ||
@BindingState var displayedWeight: String | ||
@BindingState var displayedSex: Sex | ||
@BindingState var displayedSchool: String | ||
@BindingState var displayedGrade: Int | ||
|
||
@BindingState var isPresentingEditGradeSheet: Bool | ||
@BindingState var isPresentingEditSchoolSheet: Bool | ||
|
||
} | ||
|
||
enum Action: BindableAction { | ||
case binding(BindingAction<State>) | ||
|
||
case schoolEditButtonTapped | ||
case gradeEditButtonTapped | ||
case sexSelectButtonTapped(Sex) | ||
case editDoneButtonTapped | ||
|
||
case photoSelectChanging(PhotosPickerItem?) | ||
case imageUpdating(Image?) | ||
} | ||
|
||
var body: some ReducerOf<Self> { | ||
BindingReducer() | ||
|
||
Reduce { state, action in | ||
switch action { | ||
case .schoolEditButtonTapped: | ||
return .none | ||
|
||
case .gradeEditButtonTapped: | ||
// presenting sheet | ||
state.isPresentingEditGradeSheet = true | ||
return .none | ||
|
||
case .sexSelectButtonTapped(let sex): | ||
state.displayedSex = sex | ||
return .none | ||
|
||
case .editDoneButtonTapped: | ||
// to update the remote database | ||
return .none | ||
|
||
case .photoSelectChanging(let photosPickerItem): | ||
guard let photosPickerItem | ||
else { | ||
return .send(.imageUpdating(nil)) | ||
} | ||
|
||
return .run { send in | ||
let image = try await photosPickerItem.loadTransferable(type: Image.self) | ||
await send(.imageUpdating(image)) | ||
} catch: { error, send in | ||
await send(.imageUpdating(nil)) | ||
} | ||
|
||
case .imageUpdating(let image): | ||
guard let image | ||
else { return .none } | ||
state.displayedProfileImage = image | ||
return .none | ||
|
||
case .binding(_): | ||
return .none | ||
} | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.