-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
포킷 추가 및 수정 UI 구성 #54
포킷 추가 및 수정 UI 구성 #54
Changes from all commits
5f802fa
a39a004
8520441
96dcdc9
db2f6fe
2089c7f
e1ca6e8
10367da
e6925ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
// | ||
// CategorySettingMock.swift | ||
// FeatureCategorySetting | ||
// | ||
// Created by 김민호 on 7/25/24. | ||
// | ||
|
||
import Foundation | ||
import Util | ||
|
||
public struct CategorySettingMock: Equatable { | ||
let categoryId: Int | ||
let categoryName: String | ||
/// var: 포킷 수정 / 추가에서 이미지를 할당할 수 있음 | ||
var categoryImage: CategorySettingImageMock | ||
} | ||
|
||
public struct CategorySettingImageMock: Equatable { | ||
let imageId: Int | ||
let imageUrl: String | ||
|
||
public init(imageId: Int, imageUrl: String) { | ||
self.imageId = imageId | ||
self.imageUrl = imageUrl | ||
} | ||
} | ||
|
||
extension CategorySettingMock { | ||
static var mock: Self = Self( | ||
categoryId: 0, | ||
categoryName: "대충 포킷명", | ||
categoryImage: CategorySettingImageMock( | ||
imageId: 1, | ||
imageUrl: Constants.mockImageUrl | ||
) | ||
) | ||
} | ||
|
||
extension CategorySettingImageMock { | ||
static var mock: [Self] = [ | ||
Self( | ||
imageId: 0, | ||
imageUrl: Constants.mockImageUrl | ||
), | ||
Self( | ||
imageId: 1, | ||
imageUrl: Constants.mockImageUrl | ||
), | ||
Self( | ||
imageId: 2, | ||
imageUrl: Constants.mockImageUrl | ||
), | ||
Self( | ||
imageId: 3, | ||
imageUrl: Constants.mockImageUrl | ||
), | ||
Self( | ||
imageId: 4, | ||
imageUrl: Constants.mockImageUrl | ||
), | ||
Self( | ||
imageId: 5, | ||
imageUrl: Constants.mockImageUrl | ||
), | ||
Self( | ||
imageId: 6, | ||
imageUrl: Constants.mockImageUrl | ||
), | ||
Self( | ||
imageId: 7, | ||
imageUrl: Constants.mockImageUrl | ||
), | ||
Self( | ||
imageId: 8, | ||
imageUrl: Constants.mockImageUrl | ||
), | ||
Self( | ||
imageId: 9, | ||
imageUrl: Constants.mockImageUrl | ||
), | ||
Self( | ||
imageId: 10, | ||
imageUrl: Constants.mockImageUrl | ||
), | ||
] | ||
} | ||
|
||
|
||
public struct CategoryItemMock: Identifiable, Equatable { | ||
public let id: Int | ||
let userId: Int | ||
let categoryName: String | ||
let categoryImage: CategorySettingImageMock | ||
let linkCount: Int | ||
} | ||
|
||
extension CategoryItemMock { | ||
public static var mock: [Self] = | ||
[ | ||
Self( | ||
id: 0, | ||
userId: 1, | ||
categoryName: "카테고리명", | ||
categoryImage: CategorySettingImageMock( | ||
imageId: 0, | ||
imageUrl: "hi" | ||
), | ||
linkCount: 14 | ||
), | ||
Self( | ||
id: 1, | ||
userId: 1, | ||
categoryName: "여행", | ||
categoryImage: CategorySettingImageMock( | ||
imageId: 0, | ||
imageUrl: "hi" | ||
), | ||
linkCount: 0 | ||
), | ||
Self( | ||
id: 2, | ||
userId: 1, | ||
categoryName: "맛집리스트", | ||
categoryImage: CategorySettingImageMock( | ||
imageId: 0, | ||
imageUrl: "hi" | ||
), | ||
linkCount: 2 | ||
), | ||
Self( | ||
id: 3, | ||
userId: 1, | ||
categoryName: "디자인 레퍼런스", | ||
categoryImage: CategorySettingImageMock( | ||
imageId: 0, | ||
imageUrl: "hi" | ||
), | ||
linkCount: 7 | ||
), | ||
Self( | ||
id: 4, | ||
userId: 1, | ||
categoryName: "프로그래밍", | ||
categoryImage: CategorySettingImageMock( | ||
imageId: 0, | ||
imageUrl: "hi" | ||
), | ||
linkCount: 3 | ||
), | ||
Self( | ||
id: 5, | ||
userId: 1, | ||
categoryName: "백종원의 달콤살벌 홍콩반점", | ||
categoryImage: CategorySettingImageMock( | ||
imageId: 0, | ||
imageUrl: "hi" | ||
), | ||
linkCount: 182 | ||
), | ||
] | ||
} | ||
|
||
/* | ||
{ | ||
"categoryId": 0, | ||
"categoryName": "string", | ||
"categoryImage": { | ||
"imageId": 0, | ||
"imageUrl": "string" | ||
} | ||
} | ||
*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
// | ||
// PokitCategorySettingFeature.swift | ||
// Feature | ||
// | ||
// Created by 김민호 on 7/25/24. | ||
|
||
import ComposableArchitecture | ||
import Util | ||
|
||
@Reducer | ||
public struct PokitCategorySettingFeature { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (이건 순수한 궁금입니다) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
외부 모듈에서 쓰이기 때문입니다..!! |
||
/// - Dependency | ||
@Dependency(\.dismiss) var dismiss | ||
/// - State | ||
@ObservableState | ||
public struct State: Equatable { | ||
let type: SettingType | ||
var categoryId: Int? | ||
var selectedProfile: CategorySettingImageMock? | ||
var text: String | ||
var itemList: IdentifiedArrayOf<CategoryItemMock> = [] | ||
var isProfileSheetPresented: Bool = false | ||
var profileImages: [CategorySettingImageMock] = [] | ||
|
||
/// - 포킷 수정 API / 추가 API | ||
/// categoryName | ||
/// categoryImageId | ||
/// categoryId (포킷 수정용) | ||
|
||
public init( | ||
type: SettingType, | ||
categoryId: Int? = nil, | ||
selectedProfile: CategorySettingImageMock? = nil, | ||
text: String? = "", | ||
itemList: [CategoryItemMock] | ||
) { | ||
self.type = type | ||
self.categoryId = categoryId | ||
self.selectedProfile = selectedProfile | ||
self.text = text ?? "" | ||
itemList.forEach { self.itemList.append($0) } | ||
} | ||
} | ||
|
||
/// - Action | ||
public enum Action: FeatureAction, ViewAction { | ||
case view(View) | ||
case inner(InnerAction) | ||
case async(AsyncAction) | ||
case scope(ScopeAction) | ||
case delegate(DelegateAction) | ||
|
||
@CasePathable | ||
public enum View: BindableAction, Equatable { | ||
case binding(BindingAction<State>) | ||
case dismiss | ||
case profileSettingButtonTapped | ||
case saveButtonTapped | ||
} | ||
|
||
public enum InnerAction: Equatable { case doNothing } | ||
|
||
public enum AsyncAction: Equatable { case doNothing } | ||
|
||
public enum ScopeAction: Equatable { | ||
case profile(ProfileBottomSheet.Delegate) | ||
} | ||
|
||
public enum DelegateAction: Equatable { | ||
/// 이전화면으로 돌아가 카테고리 항목을 추가하면됨 | ||
case settingSuccess(CategorySettingMock) | ||
} | ||
} | ||
|
||
/// - Initiallizer | ||
public init() {} | ||
|
||
/// - Reducer Core | ||
private func core(into state: inout State, action: Action) -> Effect<Action> { | ||
switch action { | ||
/// - View | ||
case .view(let viewAction): | ||
return handleViewAction(viewAction, state: &state) | ||
|
||
/// - Inner | ||
case .inner(let innerAction): | ||
return handleInnerAction(innerAction, state: &state) | ||
|
||
/// - Async | ||
case .async(let asyncAction): | ||
return handleAsyncAction(asyncAction, state: &state) | ||
|
||
/// - Scope | ||
case .scope(let scopeAction): | ||
return handleScopeAction(scopeAction, state: &state) | ||
|
||
/// - Delegate | ||
case .delegate(let delegateAction): | ||
return handleDelegateAction(delegateAction, state: &state) | ||
} | ||
} | ||
|
||
/// - Reducer body | ||
public var body: some ReducerOf<Self> { | ||
BindingReducer(action: \.view) | ||
Reduce(self.core) | ||
._printChanges() | ||
} | ||
} | ||
//MARK: - FeatureAction Effect | ||
private extension PokitCategorySettingFeature { | ||
/// - View Effect | ||
func handleViewAction(_ action: Action.View, state: inout State) -> Effect<Action> { | ||
switch action { | ||
case .binding: | ||
return .none | ||
|
||
case .dismiss: | ||
return .run { _ in await dismiss() } | ||
|
||
case .profileSettingButtonTapped: | ||
/// 1. 프로필 목록 조회 API 호출 | ||
/// 2. 프로필 목록들을 profileImages에 할당 | ||
state.profileImages = CategorySettingImageMock.mock | ||
/// 3. 토글 on | ||
state.isProfileSheetPresented.toggle() | ||
return .none | ||
|
||
case .saveButtonTapped: | ||
return .run { send in | ||
///Todo: 네트워크 코드 추가 | ||
// let result = try await network | ||
|
||
/// - mock | ||
let result = CategorySettingMock(categoryId: 0, categoryName: "", categoryImage: CategorySettingImageMock(imageId: 0, imageUrl: "")) | ||
await send(.delegate(.settingSuccess(result))) | ||
} | ||
} | ||
} | ||
|
||
/// - Inner Effect | ||
func handleInnerAction(_ action: Action.InnerAction, state: inout State) -> Effect<Action> { | ||
return .none | ||
} | ||
|
||
/// - Async Effect | ||
func handleAsyncAction(_ action: Action.AsyncAction, state: inout State) -> Effect<Action> { | ||
return .none | ||
} | ||
|
||
/// - Scope Effect | ||
func handleScopeAction(_ action: Action.ScopeAction, state: inout State) -> Effect<Action> { | ||
switch action { | ||
case .profile(.imageSelected(let imageInfo)): | ||
state.isProfileSheetPresented = false | ||
state.selectedProfile = imageInfo | ||
return .none | ||
} | ||
} | ||
|
||
/// - Delegate Effect | ||
func handleDelegateAction(_ action: Action.DelegateAction, state: inout State) -> Effect<Action> { | ||
return .none | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// PokitCategorySettingType.swift | ||
// FeatureCategorySetting | ||
// | ||
// Created by 김민호 on 7/25/24. | ||
// | ||
|
||
import Foundation | ||
|
||
public enum SettingType { | ||
case 추가 | ||
case 수정 | ||
|
||
var title: String { | ||
switch self { | ||
case .추가: return "포킷 추가" | ||
case .수정: return "포킷 수정" | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(제가 코드를 다 보지 않아서 이해를 잘 못한걸수도 있읍니다.)
이 데이터는 직접 접근해서 변경하는걸까요?
아니면 변경하는 곳이 따로 있는걸까요?