Skip to content

Commit

Permalink
Merge pull request #29 from score-dev/#26/style-profile-edit
Browse files Browse the repository at this point in the history
[Style/Feat] ProfileEditView를 구현했습니다.
  • Loading branch information
soletree authored Apr 13, 2024
2 parents 28532aa + 0ee0cdc commit e84349e
Show file tree
Hide file tree
Showing 7 changed files with 588 additions and 0 deletions.
36 changes: 36 additions & 0 deletions Score/Score.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
FD8FC3B92BC8465D00B80B3D /* DayOfWeek.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD8FC3B82BC8465D00B80B3D /* DayOfWeek.swift */; };
FD8FC3BB2BC8470700B80B3D /* Month.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD8FC3BA2BC8470700B80B3D /* Month.swift */; };
FD8FC3BE2BC86EB100B80B3D /* DateComponentsWithID.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD8FC3BD2BC86EB100B80B3D /* DateComponentsWithID.swift */; };
FD9E06FC2BC97D29000109FD /* User.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD9E06FB2BC97D29000109FD /* User.swift */; };
FD9E06FF2BC97DF6000109FD /* ProfileEditView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD9E06FE2BC97DF6000109FD /* ProfileEditView.swift */; };
FD9E07012BC97F20000109FD /* ProfileEditFeature.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD9E07002BC97F20000109FD /* ProfileEditFeature.swift */; };
FD9E07082BCB0913000109FD /* PhotoPickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD9E07072BCB0913000109FD /* PhotoPickerView.swift */; };
FD9E070A2BCB0A1C000109FD /* PhotoPickerFeature.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD9E07092BCB0A1C000109FD /* PhotoPickerFeature.swift */; };
FDC18D392BC6D92A00A86D41 /* Secrets.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = FDC18D382BC6D86500A86D41 /* Secrets.xcconfig */; };
FDE62A102BAD959A00DFDA5C /* SCLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDE62A0F2BAD959A00DFDA5C /* SCLabel.swift */; };
FDE9EA222BBDCA10007AA4D7 /* SCPopUp.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDE9EA212BBDCA10007AA4D7 /* SCPopUp.swift */; };
Expand Down Expand Up @@ -82,6 +87,11 @@
FD8FC3B82BC8465D00B80B3D /* DayOfWeek.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DayOfWeek.swift; sourceTree = "<group>"; };
FD8FC3BA2BC8470700B80B3D /* Month.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Month.swift; sourceTree = "<group>"; };
FD8FC3BD2BC86EB100B80B3D /* DateComponentsWithID.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateComponentsWithID.swift; sourceTree = "<group>"; };
FD9E06FB2BC97D29000109FD /* User.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = User.swift; sourceTree = "<group>"; };
FD9E06FE2BC97DF6000109FD /* ProfileEditView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileEditView.swift; sourceTree = "<group>"; };
FD9E07002BC97F20000109FD /* ProfileEditFeature.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileEditFeature.swift; sourceTree = "<group>"; };
FD9E07072BCB0913000109FD /* PhotoPickerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoPickerView.swift; sourceTree = "<group>"; };
FD9E07092BCB0A1C000109FD /* PhotoPickerFeature.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoPickerFeature.swift; sourceTree = "<group>"; };
FDC18D382BC6D86500A86D41 /* Secrets.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Secrets.xcconfig; sourceTree = "<group>"; };
FDE62A0F2BAD959A00DFDA5C /* SCLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SCLabel.swift; sourceTree = "<group>"; };
FDE9EA212BBDCA10007AA4D7 /* SCPopUp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SCPopUp.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -180,6 +190,7 @@
FD13D4962BAB56A00016F0A0 /* UIComponent */ = {
isa = PBXGroup;
children = (
FD9E07022BCAD9BB000109FD /* Picker */,
FDE9EA202BBDCA01007AA4D7 /* PopUp */,
FD3C6EB92BBC79ED00B14FF9 /* Chip */,
FD3C6EB52BBC418C00B14FF9 /* TabBar */,
Expand Down Expand Up @@ -292,10 +303,27 @@
isa = PBXGroup;
children = (
FD8FC3BD2BC86EB100B80B3D /* DateComponentsWithID.swift */,
FD9E06FB2BC97D29000109FD /* User.swift */,
);
path = Model;
sourceTree = "<group>";
};
FD9E06FD2BC97DE1000109FD /* MyPage */ = {
isa = PBXGroup;
children = (
FD9E06FE2BC97DF6000109FD /* ProfileEditView.swift */,
FD9E07072BCB0913000109FD /* PhotoPickerView.swift */,
);
path = MyPage;
sourceTree = "<group>";
};
FD9E07022BCAD9BB000109FD /* Picker */ = {
isa = PBXGroup;
children = (
);
path = Picker;
sourceTree = "<group>";
};
FDE9EA202BBDCA01007AA4D7 /* PopUp */ = {
isa = PBXGroup;
children = (
Expand All @@ -308,6 +336,8 @@
isa = PBXGroup;
children = (
FD8FC3AF2BC8251700B80B3D /* CalendarFeature.swift */,
FD9E07002BC97F20000109FD /* ProfileEditFeature.swift */,
FD9E07092BCB0A1C000109FD /* PhotoPickerFeature.swift */,
);
path = Reducer;
sourceTree = "<group>";
Expand All @@ -323,6 +353,7 @@
isa = PBXGroup;
children = (
FD0C39692BA9914B00CC05AA /* ContentView.swift */,
FD9E06FD2BC97DE1000109FD /* MyPage */,
FD8FC3B32BC834E400B80B3D /* Calendar */,
FD13D4962BAB56A00016F0A0 /* UIComponent */,
);
Expand Down Expand Up @@ -451,10 +482,13 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
FD9E070A2BCB0A1C000109FD /* PhotoPickerFeature.swift in Sources */,
FD8FC3BE2BC86EB100B80B3D /* DateComponentsWithID.swift in Sources */,
FD8FC3B72BC8426800B80B3D /* CalendarGridItem.swift in Sources */,
FD9E06FF2BC97DF6000109FD /* ProfileEditView.swift in Sources */,
FD2A260A2BAC837000F7B317 /* SCRadioButton.swift in Sources */,
FD13D49A2BAB62370016F0A0 /* SCCheckBox.swift in Sources */,
FD9E06FC2BC97D29000109FD /* User.swift in Sources */,
FD208FC02BB9AF3500DD4D3B /* SCIcon.swift in Sources */,
FD0C397A2BA9DA4A00CC05AA /* Font+.swift in Sources */,
FD208FC92BB9EAEF00DD4D3B /* SCProgressCard.swift in Sources */,
Expand All @@ -464,6 +498,7 @@
FD8FC3B02BC8251700B80B3D /* CalendarFeature.swift in Sources */,
FD8FC3B22BC826F600B80B3D /* Date+.swift in Sources */,
FDE9EA222BBDCA10007AA4D7 /* SCPopUp.swift in Sources */,
FD9E07082BCB0913000109FD /* PhotoPickerView.swift in Sources */,
FD3C6EBB2BBC79FE00B14FF9 /* SCSearchChip.swift in Sources */,
FD4A3B432BBADCD400D2DFFA /* SCRecordButton.swift in Sources */,
FD208FC72BB9E13A00DD4D3B /* SCProgressBar.swift in Sources */,
Expand All @@ -473,6 +508,7 @@
FD8FC3B92BC8465D00B80B3D /* DayOfWeek.swift in Sources */,
FD0C396A2BA9914B00CC05AA /* ContentView.swift in Sources */,
FD13D4982BAB56AA0016F0A0 /* SCButton.swift in Sources */,
FD9E07012BC97F20000109FD /* ProfileEditFeature.swift in Sources */,
FD208FC32BB9B2FC00DD4D3B /* Constants.swift in Sources */,
FDE62A102BAD959A00DFDA5C /* SCLabel.swift in Sources */,
FD3C6EBD2BBC7DE700B14FF9 /* SCTagChip.swift in Sources */,
Expand Down
12 changes: 12 additions & 0 deletions Score/Score/Constant/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ enum Constants {
enum Layout: CGFloat {
case horizontal = 24
}

//MARK: - View

enum View {
//MARK: - MyPage

enum MyPage: String {
case nickNamePlaceHolder = "현재 닉네임"
case heightPlaceHolder = "000cm"
case weightPlaceHolder = "00kg"
}
}
}

//MARK: - Preview
Expand Down
40 changes: 40 additions & 0 deletions Score/Score/Model/User.swift
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 = ""
}
49 changes: 49 additions & 0 deletions Score/Score/Reducer/PhotoPickerFeature.swift
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
}
}
}
}
89 changes: 89 additions & 0 deletions Score/Score/Reducer/ProfileEditFeature.swift
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
}
}
}
}

Loading

0 comments on commit e84349e

Please sign in to comment.