From ba2021759a875422cd8da935f6e700a781441172 Mon Sep 17 00:00:00 2001 From: Ben Follington <5009316+bfollington@users.noreply.github.com> Date: Mon, 15 Jan 2024 16:05:26 +1100 Subject: [PATCH] Show settings when tapping sync indicator (#1068) Fixes https://github.com/subconsciousnetwork/subconscious/issues/1031 - tap sync indicator to show settings - surface sync failure in root settings view --- .../Shared/Components/MainToolbar.swift | 45 ++++++++++++------- .../Components/Settings/SettingsView.swift | 29 +++++++++--- 2 files changed, 51 insertions(+), 23 deletions(-) diff --git a/xcode/Subconscious/Shared/Components/MainToolbar.swift b/xcode/Subconscious/Shared/Components/MainToolbar.swift index 31fefe6b..1ffb7a6d 100644 --- a/xcode/Subconscious/Shared/Components/MainToolbar.swift +++ b/xcode/Subconscious/Shared/Components/MainToolbar.swift @@ -11,6 +11,7 @@ import ObservableStore struct SyncStatusView: View { var status: ResourceStatus + var action: () -> Void var color: Color { switch status { @@ -41,23 +42,28 @@ struct SyncStatusView: View { @State var showLabel = true var body: some View { - HStack(spacing: AppTheme.unit2) { - ZStack { - Circle() - .foregroundStyle(color) - Circle() - .stroke(Color.separator.opacity(0.75), lineWidth: 0.5) + Button( + action: action, + label: { + HStack(spacing: AppTheme.unit2) { + ZStack { + Circle() + .foregroundStyle(color) + Circle() + .stroke(Color.separator.opacity(0.75), lineWidth: 0.5) + } + .frame(width: 8, height: 8) + + Text(showLabel ? label : "") + .font(.caption2) + .foregroundStyle(.secondary) + .transition(.opacity) + .id("sync-status-label") + .frame(width: 128, height: 16, alignment: .leading) + .fixedSize(horizontal: true, vertical: true) + } } - .frame(width: 8, height: 8) - - Text(showLabel ? label : "") - .font(.caption2) - .foregroundStyle(.secondary) - .transition(.opacity) - .id("sync-status-label") - .frame(width: 128, height: 16, alignment: .leading) - .fixedSize(horizontal: true, vertical: true) - } + ) .onAppear { switch status { case .succeeded: @@ -90,7 +96,12 @@ struct MainToolbar: ToolbarContent { var body: some ToolbarContent { ToolbarItem(placement: .navigationBarLeading) { - SyncStatusView(status: app.state.lastGatewaySyncStatus) + SyncStatusView( + status: app.state.lastGatewaySyncStatus, + action: { + app.send(.presentSettingsSheet(true)) + } + ) } ToolbarItem(placement: .primaryAction) { diff --git a/xcode/Subconscious/Shared/Components/Settings/SettingsView.swift b/xcode/Subconscious/Shared/Components/Settings/SettingsView.swift index d4e52bb7..d408b1e1 100644 --- a/xcode/Subconscious/Shared/Components/Settings/SettingsView.swift +++ b/xcode/Subconscious/Shared/Components/Settings/SettingsView.swift @@ -80,7 +80,7 @@ struct SettingsView: View { .lineLimit(1) } ) - + LabeledContent( "Version", value: app.state.sphereVersion ?? unknown @@ -88,18 +88,35 @@ struct SettingsView: View { .lineLimit(1) .textSelection(.enabled) + let syncFailed: Bool = Func.run { + switch app.state.lastGatewaySyncStatus { + case .failed: + return true + default: + return false + } + } + NavigationLink( destination: { GatewayURLSettingsView(app: app) }, label: { - LabeledContent( - "Gateway", - value: app.state.gatewayURL - ) - .lineLimit(1) + HStack { + if (syncFailed) { + Image( + systemName: "exclamationmark.arrow.triangle.2.circlepath" + ) + } + LabeledContent( + "Gateway", + value: app.state.gatewayURL + ) + .lineLimit(1) + } } ) + .foregroundColor(syncFailed ? .red : nil) }, header: { Text("Noosphere")