From b56da94a7c905d0853d973fbe9b9d54d7d480bc5 Mon Sep 17 00:00:00 2001 From: Thomas Ricouard Date: Wed, 21 Feb 2024 09:45:29 +0100 Subject: [PATCH] Add more sheets to shared + link to filters in timeline top filters --- IceCubesApp/App/AppRegistry.swift | 6 ++++++ .../Tabs/Settings/AccountSettingView.swift | 13 +++--------- .../Sources/Account/AccountDetailView.swift | 17 ++++------------ Packages/Env/Sources/Env/Router.swift | 16 ++++++++++++++- .../View/TimelineContentFilterView.swift | 20 +++++++++++++++++++ 5 files changed, 48 insertions(+), 24 deletions(-) diff --git a/IceCubesApp/App/AppRegistry.swift b/IceCubesApp/App/AppRegistry.swift index 081c1190..d69707ca 100644 --- a/IceCubesApp/App/AppRegistry.swift +++ b/IceCubesApp/App/AppRegistry.swift @@ -140,6 +140,12 @@ extension View { .presentationDetents([.medium]) .presentationBackground(.thinMaterial) .withEnvironments() + case .accountEditInfo: + EditAccountView() + .withEnvironments() + case .accountFiltersList: + FiltersListView() + .withEnvironments() } } } diff --git a/IceCubesApp/App/Tabs/Settings/AccountSettingView.swift b/IceCubesApp/App/Tabs/Settings/AccountSettingView.swift index 9a9c5afc..b1209004 100644 --- a/IceCubesApp/App/Tabs/Settings/AccountSettingView.swift +++ b/IceCubesApp/App/Tabs/Settings/AccountSettingView.swift @@ -17,9 +17,8 @@ struct AccountSettingsView: View { @Environment(Theme.self) private var theme @Environment(AppAccountsManager.self) private var appAccountsManager @Environment(Client.self) private var client + @Environment(RouterPath.self) private var routerPath - @State private var isEditingAccount: Bool = false - @State private var isEditingFilters: Bool = false @State private var cachedPostsCount: Int = 0 @State private var timelineCache = TimelineCache() @@ -30,7 +29,7 @@ struct AccountSettingsView: View { Form { Section { Button { - isEditingAccount = true + routerPath.presentedSheet = .accountFiltersList } label: { Label("account.action.edit-info", systemImage: "pencil") .frame(maxWidth: .infinity, alignment: .leading) @@ -40,7 +39,7 @@ struct AccountSettingsView: View { if currentInstance.isFiltersSupported { Button { - isEditingFilters = true + routerPath.presentedSheet = .accountFiltersList } label: { Label("account.action.edit-filters", systemImage: "line.3.horizontal.decrease.circle") .frame(maxWidth: .infinity, alignment: .leading) @@ -96,12 +95,6 @@ struct AccountSettingsView: View { } .listRowBackground(theme.primaryBackgroundColor) } - .sheet(isPresented: $isEditingAccount, content: { - EditAccountView() - }) - .sheet(isPresented: $isEditingFilters, content: { - FiltersListView() - }) .toolbar { ToolbarItem(placement: .principal) { HStack { diff --git a/Packages/Account/Sources/Account/AccountDetailView.swift b/Packages/Account/Sources/Account/AccountDetailView.swift index fc89cef4..83f3d8fc 100644 --- a/Packages/Account/Sources/Account/AccountDetailView.swift +++ b/Packages/Account/Sources/Account/AccountDetailView.swift @@ -23,9 +23,6 @@ public struct AccountDetailView: View { @State private var viewModel: AccountDetailViewModel @State private var isCurrentUser: Bool = false @State private var showBlockConfirmation: Bool = false - - @State private var isEditingAccount: Bool = false - @State private var isEditingFilters: Bool = false @State private var isEditingRelationshipNote: Bool = false @State private var displayTitle: Bool = false @@ -136,20 +133,14 @@ public struct AccountDetailView: View { viewModel.handleEvent(event: latestEvent, currentAccount: currentAccount) } } - .onChange(of: isEditingAccount) { _, newValue in - if !newValue { + .onChange(of: routerPath.presentedSheet) { oldValue, newValue in + if oldValue == .accountEditInfo || newValue == .accountEditInfo { Task { await viewModel.fetchAccount() await preferences.refreshServerPreferences() } } } - .sheet(isPresented: $isEditingAccount, content: { - EditAccountView() - }) - .sheet(isPresented: $isEditingFilters, content: { - FiltersListView() - }) .sheet(isPresented: $isEditingRelationshipNote, content: { EditRelationshipNoteView(accountDetailViewModel: viewModel) }) @@ -306,7 +297,7 @@ public struct AccountDetailView: View { if isCurrentUser { Button { - isEditingAccount = true + routerPath.presentedSheet = .accountEditInfo } label: { Label("account.action.edit-info", systemImage: "pencil") } @@ -321,7 +312,7 @@ public struct AccountDetailView: View { if currentInstance.isFiltersSupported { Button { - isEditingFilters = true + routerPath.presentedSheet = .accountFiltersList } label: { Label("account.action.edit-filters", systemImage: "line.3.horizontal.decrease.circle") } diff --git a/Packages/Env/Sources/Env/Router.swift b/Packages/Env/Sources/Env/Router.swift index 42b8c640..9ab5da63 100644 --- a/Packages/Env/Sources/Env/Router.swift +++ b/Packages/Env/Sources/Env/Router.swift @@ -38,7 +38,15 @@ public enum WindowDestinationMedia: Hashable, Codable { case mediaViewer(attachments: [MediaAttachment], selectedAttachment: MediaAttachment) } -public enum SheetDestination: Identifiable { +public enum SheetDestination: Identifiable, Hashable { + public static func == (lhs: SheetDestination, rhs: SheetDestination) -> Bool { + lhs.id == rhs.id + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(id) + } + case newStatusEditor(visibility: Models.Visibility) case editStatusEditor(status: Status) case replyToStatusEditor(status: Status) @@ -60,6 +68,8 @@ public enum SheetDestination: Identifiable { case shareImage(image: UIImage, status: Status) case editTagGroup(tagGroup: TagGroup, onSaved: ((TagGroup) -> Void)?) case timelineContentFilter + case accountEditInfo + case accountFiltersList public var id: String { switch self { @@ -90,6 +100,10 @@ public enum SheetDestination: Identifiable { "settings" case .timelineContentFilter: "timelineContentFilter" + case .accountEditInfo: + "accountEditInfo" + case .accountFiltersList: + "accountFiltersList" } } } diff --git a/Packages/Timeline/Sources/Timeline/View/TimelineContentFilterView.swift b/Packages/Timeline/Sources/Timeline/View/TimelineContentFilterView.swift index a73f2159..4f4e110a 100644 --- a/Packages/Timeline/Sources/Timeline/View/TimelineContentFilterView.swift +++ b/Packages/Timeline/Sources/Timeline/View/TimelineContentFilterView.swift @@ -1,10 +1,14 @@ import DesignSystem import SwiftUI +import Env public struct TimelineContentFilterView: View { @Environment(Theme.self) private var theme + @Environment(CurrentInstance.self) private var currentInstance + @Environment(RouterPath.self) private var routerPath @State private var contentFilter = TimelineContentFilter.shared + @State private var isEditingFilters = false public init() {} @@ -27,6 +31,22 @@ public struct TimelineContentFilterView: View { #if !os(visionOS) .listRowBackground(theme.primaryBackgroundColor) #endif + + Section { + if currentInstance.isFiltersSupported { + Button { + routerPath.presentedSheet = .accountFiltersList + } label: { + Label("account.action.edit-filters", systemImage: "line.3.horizontal.decrease.circle") + .frame(maxWidth: .infinity, alignment: .leading) + .contentShape(Rectangle()) + } + .buttonStyle(.plain) + } + } + #if !os(visionOS) + .listRowBackground(theme.primaryBackgroundColor) + #endif } .navigationTitle("timeline.content-filter.title") .navigationBarTitleDisplayMode(.inline)