Refactor home view to show different routes better
This makes navigation while we are dealing with placeholders much easier, though this will likely _all_ be deleted as we start to implement proper UIs
This commit is contained in:
parent
0481038986
commit
82e8f5cc78
|
@ -2,7 +2,7 @@ import ComposableArchitecture
|
|||
import SwiftUI
|
||||
|
||||
struct HomeState: Equatable {
|
||||
enum Route: Equatable {
|
||||
enum Route: Equatable, CaseIterable {
|
||||
case history
|
||||
case send
|
||||
case recoveryPhraseDisplay
|
||||
|
@ -82,6 +82,15 @@ extension HomeViewStore {
|
|||
.map(\.id)
|
||||
}
|
||||
|
||||
func bindingForRoute(_ route: HomeState.Route) -> Binding<Bool> {
|
||||
self.binding(
|
||||
get: { $0.route == route },
|
||||
send: { isActive in
|
||||
return .updateRoute(isActive ? route : nil)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
var showHistoryBinding: Binding<Bool> {
|
||||
self.binding(
|
||||
get: { $0.route == .history },
|
||||
|
|
|
@ -4,79 +4,59 @@ import ComposableArchitecture
|
|||
struct HomeView: View {
|
||||
let store: Store<HomeState, HomeAction>
|
||||
|
||||
var navigationRouteValues: [RouteValue] = HomeState.Route.allCases
|
||||
.enumerated()
|
||||
.filter { $0.1 != .history }
|
||||
.map { RouteValue(id: $0.0, route: $0.1) }
|
||||
|
||||
var modalRoutes: [RouteValue] = HomeState.Route.allCases
|
||||
.enumerated()
|
||||
.filter { $0.1 == .history }
|
||||
.map { RouteValue(id: $0.0, route: $0.1) }
|
||||
|
||||
@ViewBuilder func view(for route: HomeState.Route) -> some View {
|
||||
switch route {
|
||||
case .history:
|
||||
TransactionHistoryView(store: store.historyStore())
|
||||
case .send:
|
||||
SendView(
|
||||
store: .init(
|
||||
initialState: .placeholder,
|
||||
reducer: SendReducer.default(
|
||||
whenDone: { HomeViewStore(store).send(.updateRoute(nil)) }
|
||||
).debug(),
|
||||
environment: ()
|
||||
)
|
||||
)
|
||||
case .recoveryPhraseDisplay:
|
||||
RecoveryPhraseDisplayView(store: .demo)
|
||||
}
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
WithViewStore(store) { viewStore in
|
||||
VStack {
|
||||
Button(
|
||||
action: { viewStore.toggleShowingHistory() },
|
||||
label: { Text(viewStore.historyToggleString()) }
|
||||
)
|
||||
.primaryButtonStyle
|
||||
.frame(height: 50)
|
||||
List {
|
||||
Section(header: Text("Navigation Stack Routes")) {
|
||||
ForEach(navigationRouteValues) { routeValue in
|
||||
Text("\(String(describing: routeValue.route))")
|
||||
.navigationLink(
|
||||
isActive: viewStore.bindingForRoute(routeValue.route),
|
||||
destination: {
|
||||
view(for: routeValue.route)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Button(
|
||||
action: { viewStore.toggleSelectedTransaction() },
|
||||
label: { Text("Toggle Selected Transaction") }
|
||||
)
|
||||
.primaryButtonStyle
|
||||
.frame(height: 50)
|
||||
|
||||
Button(
|
||||
action: { viewStore.send(.updateRoute(.recoveryPhraseDisplay)) },
|
||||
label: { Text("Show Recovery Phrase Demo") }
|
||||
)
|
||||
.primaryButtonStyle
|
||||
.frame(height: 50)
|
||||
|
||||
Button(
|
||||
action: { viewStore.send(.updateRoute(.send)) },
|
||||
label: { Text("Go to Send") }
|
||||
)
|
||||
.primaryButtonStyle
|
||||
.frame(height: 50)
|
||||
|
||||
Spacer()
|
||||
|
||||
HStack {
|
||||
VStack(alignment: .leading) {
|
||||
Text("Route: \(String(dumping: viewStore.route))")
|
||||
Text(
|
||||
// swiftlint:disable:next line_length
|
||||
"SelectedTransaction: \(String(dumping: viewStore.transactionHistoryState.route.map(/TransactionHistoryState.Route.showTransaction)))"
|
||||
Section(header: Text("Other Actions")) {
|
||||
Button(
|
||||
action: { viewStore.toggleSelectedTransaction() },
|
||||
label: { Text("Toggle Selected Transaction") }
|
||||
)
|
||||
}
|
||||
.multilineTextAlignment(.leading)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
}
|
||||
.padding(.horizontal, 30)
|
||||
.navigationBarTitle("Home", displayMode: .inline)
|
||||
.navigationLinkEmpty(
|
||||
isActive: viewStore.showPhraseDisplayBinding,
|
||||
destination: {
|
||||
RecoveryPhraseDisplayView(store: .demo)
|
||||
}
|
||||
)
|
||||
.navigationLinkEmpty(
|
||||
isActive: viewStore.showSendBinding,
|
||||
destination: {
|
||||
SendView(
|
||||
store: .init(
|
||||
initialState: .init(
|
||||
transaction: .placeholder,
|
||||
route: nil
|
||||
),
|
||||
reducer: SendReducer.default(
|
||||
whenDone: { viewStore.send(.updateRoute(nil)) }
|
||||
)
|
||||
.debug(),
|
||||
environment: ()
|
||||
)
|
||||
)
|
||||
}
|
||||
)
|
||||
.fullScreenCover(
|
||||
isPresented: viewStore.showHistoryBinding,
|
||||
content: {
|
||||
|
@ -90,10 +70,18 @@ struct HomeView: View {
|
|||
}
|
||||
}
|
||||
)
|
||||
.navigationBarTitle("Home")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct RouteValue: Identifiable {
|
||||
let id: Int
|
||||
let route: HomeState.Route
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
extension HomeStore {
|
||||
static var placeholder: HomeStore {
|
||||
HomeStore(
|
||||
|
|
Loading…
Reference in New Issue