From 499f56b47141affca8860e0485d62ac6077a8404 Mon Sep 17 00:00:00 2001 From: Seungyeop Yeom Date: Sat, 18 Jan 2025 15:42:00 +0900 Subject: [PATCH] Add a profile page --- Sources/BadaApp/Equipment/EquipmentView.swift | 2 +- Sources/BadaApp/Home/HomeReducer.swift | 4 +- Sources/BadaApp/Home/HomeView.swift | 12 +++-- Sources/BadaApp/Home/ProfileReducer.swift | 27 ++++++++++ Sources/BadaApp/Home/ProfileView.swift | 53 +++++++++++++++++++ .../BadaApp/Navigation/NavigationStore.swift | 5 ++ Tests/BadaAppTests/HomeReducerTests.swift | 4 +- 7 files changed, 98 insertions(+), 9 deletions(-) create mode 100644 Sources/BadaApp/Home/ProfileReducer.swift create mode 100644 Sources/BadaApp/Home/ProfileView.swift diff --git a/Sources/BadaApp/Equipment/EquipmentView.swift b/Sources/BadaApp/Equipment/EquipmentView.swift index 2da71e0..b4adc7c 100644 --- a/Sources/BadaApp/Equipment/EquipmentView.swift +++ b/Sources/BadaApp/Equipment/EquipmentView.swift @@ -19,7 +19,7 @@ struct EquipmentView: View { NavigationStack( path: navigationStore.binding( \.equipmentPaths, - send: { .setEquipmentPaths($0) }) + send: { .setEquipmentPaths($0) }) ) { ScrollView(.vertical) { diff --git a/Sources/BadaApp/Home/HomeReducer.swift b/Sources/BadaApp/Home/HomeReducer.swift index 4e370ad..4e34ba5 100644 --- a/Sources/BadaApp/Home/HomeReducer.swift +++ b/Sources/BadaApp/Home/HomeReducer.swift @@ -10,7 +10,7 @@ import BadaDomain struct HomeReducer: Reducer { enum Action: Sendable { - case initialize + case load case getDiveLogs case setLogCount(Int?) } @@ -23,7 +23,7 @@ struct HomeReducer: Reducer { func reduce(state: inout State, action: Action) -> AnyEffect { switch action { - case .initialize: + case .load: return .merge { .just(.getDiveLogs) } diff --git a/Sources/BadaApp/Home/HomeView.swift b/Sources/BadaApp/Home/HomeView.swift index 24cd5b6..13a507f 100644 --- a/Sources/BadaApp/Home/HomeView.swift +++ b/Sources/BadaApp/Home/HomeView.swift @@ -19,12 +19,12 @@ struct HomeView: View { NavigationStack( path: navigationStore.binding( \.homePaths, - send: { .setHomePaths($0) }) + send: { .setHomePaths($0) }) ) { ScrollView(.vertical) { VStack(spacing: 16) { - SectionHeader(title: "Bio") { - // TODO: Move to the bio edit page + SectionHeader(title: "Profile") { + navigationStore.send(.home(.profile)) } VStack(spacing: 16) { InfoRow( @@ -73,13 +73,17 @@ struct HomeView: View { .background(.background.secondary) .navigationTitle(L10n.Home.title) .navigationDestination(for: NavigationState.HomePath.self) { path in + switch path { + case .profile: + ProfileView() + } } .onAppear(perform: onAppear) } } private func onAppear() { - store.send(.initialize) + store.send(.load) } } diff --git a/Sources/BadaApp/Home/ProfileReducer.swift b/Sources/BadaApp/Home/ProfileReducer.swift new file mode 100644 index 0000000..f658c86 --- /dev/null +++ b/Sources/BadaApp/Home/ProfileReducer.swift @@ -0,0 +1,27 @@ +// +// BadaBook +// Apache License, Version 2.0 +// +// Copyright (c) 2024 Seungyeop Yeom ( https://github.com/OceanPositive ). +// + +import BadaCore + +struct ProfileReducer: Reducer { + enum Action: Sendable { + case load + case save + } + + struct State: Sendable, Equatable { + } + + func reduce(state: inout State, action: Action) -> AnyEffect { + switch action { + case .load: + return .none + case .save: + return .none + } + } +} diff --git a/Sources/BadaApp/Home/ProfileView.swift b/Sources/BadaApp/Home/ProfileView.swift new file mode 100644 index 0000000..1e3af41 --- /dev/null +++ b/Sources/BadaApp/Home/ProfileView.swift @@ -0,0 +1,53 @@ +// +// BadaBook +// Apache License, Version 2.0 +// +// Copyright (c) 2024 Seungyeop Yeom ( https://github.com/OceanPositive ). +// + +import BadaCore +import BadaUI + +struct ProfileView: View { + @StateObject private var store = ViewStore( + reducer: ProfileReducer(), + state: ProfileReducer.State() + ) + + var body: some View { + Form { + + } + #if os(macOS) + .padding() + #endif + .navigationTitle("Profile") + #if os(iOS) + .navigationBarTitleDisplayMode(.inline) + #endif + .toolbar { + ToolbarItem(placement: .confirmationAction) { + saveButton + } + } + .onAppear(perform: onAppear) + } + + private var saveButton: some View { + Button(action: tapSaveButton) { + Text("Save") + } + } + + private func onAppear() { + store.send(.load) + } + + private func tapSaveButton() { + store.send(.save) + } +} + +#Preview { + ProfileView() +} diff --git a/Sources/BadaApp/Navigation/NavigationStore.swift b/Sources/BadaApp/Navigation/NavigationStore.swift index 5637b2c..e7a9780 100644 --- a/Sources/BadaApp/Navigation/NavigationStore.swift +++ b/Sources/BadaApp/Navigation/NavigationStore.swift @@ -58,6 +58,9 @@ struct NavigationReducer: Reducer { case .root: state.homePaths = [] return .none + case .profile: + state.homePaths = [.profile] + return .none } case let .equipment(equipment): state.mainTab = .equipment @@ -83,6 +86,7 @@ struct NavigationReducer: Reducer { extension NavigationReducer.Action { enum Home { case root + case profile } enum Equipment { @@ -103,6 +107,7 @@ extension NavigationReducer.State { } enum HomePath: Hashable { + case profile } enum EquipmentPath: Hashable { diff --git a/Tests/BadaAppTests/HomeReducerTests.swift b/Tests/BadaAppTests/HomeReducerTests.swift index f9c72e7..8089fcb 100644 --- a/Tests/BadaAppTests/HomeReducerTests.swift +++ b/Tests/BadaAppTests/HomeReducerTests.swift @@ -14,7 +14,7 @@ import BadaTesting @Suite struct HomeReducerTests { @Test - func initialize() async { + func load() async { let container = UseCaseContainer() container.register { GetDiveLogsUseCase { .success([]) } @@ -26,7 +26,7 @@ struct HomeReducerTests { ) await sut.expect(\.logCount, nil) - await sut.send(.initialize) + await sut.send(.load) await sut.expect(\.logCount, 0) } }