Add more sheets to shared + link to filters in timeline top filters

This commit is contained in:
Thomas Ricouard 2024-02-21 09:45:29 +01:00
parent e612fbdf7c
commit b56da94a7c
5 changed files with 48 additions and 24 deletions

View file

@ -140,6 +140,12 @@ extension View {
.presentationDetents([.medium]) .presentationDetents([.medium])
.presentationBackground(.thinMaterial) .presentationBackground(.thinMaterial)
.withEnvironments() .withEnvironments()
case .accountEditInfo:
EditAccountView()
.withEnvironments()
case .accountFiltersList:
FiltersListView()
.withEnvironments()
} }
} }
} }

View file

@ -17,9 +17,8 @@ struct AccountSettingsView: View {
@Environment(Theme.self) private var theme @Environment(Theme.self) private var theme
@Environment(AppAccountsManager.self) private var appAccountsManager @Environment(AppAccountsManager.self) private var appAccountsManager
@Environment(Client.self) private var client @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 cachedPostsCount: Int = 0
@State private var timelineCache = TimelineCache() @State private var timelineCache = TimelineCache()
@ -30,7 +29,7 @@ struct AccountSettingsView: View {
Form { Form {
Section { Section {
Button { Button {
isEditingAccount = true routerPath.presentedSheet = .accountFiltersList
} label: { } label: {
Label("account.action.edit-info", systemImage: "pencil") Label("account.action.edit-info", systemImage: "pencil")
.frame(maxWidth: .infinity, alignment: .leading) .frame(maxWidth: .infinity, alignment: .leading)
@ -40,7 +39,7 @@ struct AccountSettingsView: View {
if currentInstance.isFiltersSupported { if currentInstance.isFiltersSupported {
Button { Button {
isEditingFilters = true routerPath.presentedSheet = .accountFiltersList
} label: { } label: {
Label("account.action.edit-filters", systemImage: "line.3.horizontal.decrease.circle") Label("account.action.edit-filters", systemImage: "line.3.horizontal.decrease.circle")
.frame(maxWidth: .infinity, alignment: .leading) .frame(maxWidth: .infinity, alignment: .leading)
@ -96,12 +95,6 @@ struct AccountSettingsView: View {
} }
.listRowBackground(theme.primaryBackgroundColor) .listRowBackground(theme.primaryBackgroundColor)
} }
.sheet(isPresented: $isEditingAccount, content: {
EditAccountView()
})
.sheet(isPresented: $isEditingFilters, content: {
FiltersListView()
})
.toolbar { .toolbar {
ToolbarItem(placement: .principal) { ToolbarItem(placement: .principal) {
HStack { HStack {

View file

@ -23,9 +23,6 @@ public struct AccountDetailView: View {
@State private var viewModel: AccountDetailViewModel @State private var viewModel: AccountDetailViewModel
@State private var isCurrentUser: Bool = false @State private var isCurrentUser: Bool = false
@State private var showBlockConfirmation: 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 isEditingRelationshipNote: Bool = false
@State private var displayTitle: Bool = false @State private var displayTitle: Bool = false
@ -136,20 +133,14 @@ public struct AccountDetailView: View {
viewModel.handleEvent(event: latestEvent, currentAccount: currentAccount) viewModel.handleEvent(event: latestEvent, currentAccount: currentAccount)
} }
} }
.onChange(of: isEditingAccount) { _, newValue in .onChange(of: routerPath.presentedSheet) { oldValue, newValue in
if !newValue { if oldValue == .accountEditInfo || newValue == .accountEditInfo {
Task { Task {
await viewModel.fetchAccount() await viewModel.fetchAccount()
await preferences.refreshServerPreferences() await preferences.refreshServerPreferences()
} }
} }
} }
.sheet(isPresented: $isEditingAccount, content: {
EditAccountView()
})
.sheet(isPresented: $isEditingFilters, content: {
FiltersListView()
})
.sheet(isPresented: $isEditingRelationshipNote, content: { .sheet(isPresented: $isEditingRelationshipNote, content: {
EditRelationshipNoteView(accountDetailViewModel: viewModel) EditRelationshipNoteView(accountDetailViewModel: viewModel)
}) })
@ -306,7 +297,7 @@ public struct AccountDetailView: View {
if isCurrentUser { if isCurrentUser {
Button { Button {
isEditingAccount = true routerPath.presentedSheet = .accountEditInfo
} label: { } label: {
Label("account.action.edit-info", systemImage: "pencil") Label("account.action.edit-info", systemImage: "pencil")
} }
@ -321,7 +312,7 @@ public struct AccountDetailView: View {
if currentInstance.isFiltersSupported { if currentInstance.isFiltersSupported {
Button { Button {
isEditingFilters = true routerPath.presentedSheet = .accountFiltersList
} label: { } label: {
Label("account.action.edit-filters", systemImage: "line.3.horizontal.decrease.circle") Label("account.action.edit-filters", systemImage: "line.3.horizontal.decrease.circle")
} }

View file

@ -38,7 +38,15 @@ public enum WindowDestinationMedia: Hashable, Codable {
case mediaViewer(attachments: [MediaAttachment], selectedAttachment: MediaAttachment) 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 newStatusEditor(visibility: Models.Visibility)
case editStatusEditor(status: Status) case editStatusEditor(status: Status)
case replyToStatusEditor(status: Status) case replyToStatusEditor(status: Status)
@ -60,6 +68,8 @@ public enum SheetDestination: Identifiable {
case shareImage(image: UIImage, status: Status) case shareImage(image: UIImage, status: Status)
case editTagGroup(tagGroup: TagGroup, onSaved: ((TagGroup) -> Void)?) case editTagGroup(tagGroup: TagGroup, onSaved: ((TagGroup) -> Void)?)
case timelineContentFilter case timelineContentFilter
case accountEditInfo
case accountFiltersList
public var id: String { public var id: String {
switch self { switch self {
@ -90,6 +100,10 @@ public enum SheetDestination: Identifiable {
"settings" "settings"
case .timelineContentFilter: case .timelineContentFilter:
"timelineContentFilter" "timelineContentFilter"
case .accountEditInfo:
"accountEditInfo"
case .accountFiltersList:
"accountFiltersList"
} }
} }
} }

View file

@ -1,10 +1,14 @@
import DesignSystem import DesignSystem
import SwiftUI import SwiftUI
import Env
public struct TimelineContentFilterView: View { public struct TimelineContentFilterView: View {
@Environment(Theme.self) private var theme @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 contentFilter = TimelineContentFilter.shared
@State private var isEditingFilters = false
public init() {} public init() {}
@ -27,6 +31,22 @@ public struct TimelineContentFilterView: View {
#if !os(visionOS) #if !os(visionOS)
.listRowBackground(theme.primaryBackgroundColor) .listRowBackground(theme.primaryBackgroundColor)
#endif #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") .navigationTitle("timeline.content-filter.title")
.navigationBarTitleDisplayMode(.inline) .navigationBarTitleDisplayMode(.inline)