Skip to content
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

Add a profile page #50

Merged
merged 1 commit into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/BadaApp/Equipment/EquipmentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct EquipmentView: View {
NavigationStack(
path: navigationStore.binding(
\.equipmentPaths,
send: { .setEquipmentPaths($0) })
send: { .setEquipmentPaths($0) })
) {
ScrollView(.vertical) {

Expand Down
4 changes: 2 additions & 2 deletions Sources/BadaApp/Home/HomeReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import BadaDomain

struct HomeReducer: Reducer {
enum Action: Sendable {
case initialize
case load
case getDiveLogs
case setLogCount(Int?)
}
Expand All @@ -23,7 +23,7 @@ struct HomeReducer: Reducer {

func reduce(state: inout State, action: Action) -> AnyEffect<Action> {
switch action {
case .initialize:
case .load:
return .merge {
.just(.getDiveLogs)
}
Expand Down
12 changes: 8 additions & 4 deletions Sources/BadaApp/Home/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
}
}

Expand Down
27 changes: 27 additions & 0 deletions Sources/BadaApp/Home/ProfileReducer.swift
Original file line number Diff line number Diff line change
@@ -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<Action> {
switch action {
case .load:
return .none
case .save:
return .none
}
}
}
53 changes: 53 additions & 0 deletions Sources/BadaApp/Home/ProfileView.swift
Original file line number Diff line number Diff line change
@@ -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()
}
5 changes: 5 additions & 0 deletions Sources/BadaApp/Navigation/NavigationStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -83,6 +86,7 @@ struct NavigationReducer: Reducer {
extension NavigationReducer.Action {
enum Home {
case root
case profile
}

enum Equipment {
Expand All @@ -103,6 +107,7 @@ extension NavigationReducer.State {
}

enum HomePath: Hashable {
case profile
}

enum EquipmentPath: Hashable {
Expand Down
4 changes: 2 additions & 2 deletions Tests/BadaAppTests/HomeReducerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import BadaTesting
@Suite
struct HomeReducerTests {
@Test
func initialize() async {
func load() async {
let container = UseCaseContainer()
container.register {
GetDiveLogsUseCase { .success([]) }
Expand All @@ -26,7 +26,7 @@ struct HomeReducerTests {
)
await sut.expect(\.logCount, nil)

await sut.send(.initialize)
await sut.send(.load)
await sut.expect(\.logCount, 0)
}
}
Expand Down