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
|
import SwiftUI
|
||||||
|
|
||||||
struct HomeState: Equatable {
|
struct HomeState: Equatable {
|
||||||
enum Route: Equatable {
|
enum Route: Equatable, CaseIterable {
|
||||||
case history
|
case history
|
||||||
case send
|
case send
|
||||||
case recoveryPhraseDisplay
|
case recoveryPhraseDisplay
|
||||||
|
@ -82,6 +82,15 @@ extension HomeViewStore {
|
||||||
.map(\.id)
|
.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> {
|
var showHistoryBinding: Binding<Bool> {
|
||||||
self.binding(
|
self.binding(
|
||||||
get: { $0.route == .history },
|
get: { $0.route == .history },
|
||||||
|
|
|
@ -4,79 +4,59 @@ import ComposableArchitecture
|
||||||
struct HomeView: View {
|
struct HomeView: View {
|
||||||
let store: Store<HomeState, HomeAction>
|
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 {
|
var body: some View {
|
||||||
WithViewStore(store) { viewStore in
|
WithViewStore(store) { viewStore in
|
||||||
VStack {
|
VStack {
|
||||||
Button(
|
List {
|
||||||
action: { viewStore.toggleShowingHistory() },
|
Section(header: Text("Navigation Stack Routes")) {
|
||||||
label: { Text(viewStore.historyToggleString()) }
|
ForEach(navigationRouteValues) { routeValue in
|
||||||
)
|
Text("\(String(describing: routeValue.route))")
|
||||||
.primaryButtonStyle
|
.navigationLink(
|
||||||
.frame(height: 50)
|
isActive: viewStore.bindingForRoute(routeValue.route),
|
||||||
|
destination: {
|
||||||
|
view(for: routeValue.route)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Button(
|
Section(header: Text("Other Actions")) {
|
||||||
action: { viewStore.toggleSelectedTransaction() },
|
Button(
|
||||||
label: { Text("Toggle Selected Transaction") }
|
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)))"
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
.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(
|
.fullScreenCover(
|
||||||
isPresented: viewStore.showHistoryBinding,
|
isPresented: viewStore.showHistoryBinding,
|
||||||
content: {
|
content: {
|
||||||
|
@ -90,10 +70,18 @@ struct HomeView: View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
.navigationBarTitle("Home")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct RouteValue: Identifiable {
|
||||||
|
let id: Int
|
||||||
|
let route: HomeState.Route
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Previews
|
||||||
|
|
||||||
extension HomeStore {
|
extension HomeStore {
|
||||||
static var placeholder: HomeStore {
|
static var placeholder: HomeStore {
|
||||||
HomeStore(
|
HomeStore(
|
||||||
|
|
Loading…
Reference in New Issue