Fix list not updating in the quick access pills

This commit is contained in:
Thomas Ricouard 2024-01-02 11:54:17 +01:00
parent c4b85679a2
commit 13e87b41e9
3 changed files with 50 additions and 4 deletions

View File

@ -72,8 +72,17 @@ public struct ListEditView: View {
.background(theme.secondaryBackgroundColor)
.toolbar {
ToolbarItem {
Button("action.done") {
dismiss()
Button {
Task {
await viewModel.update()
dismiss()
}
} label: {
if viewModel.isUpdating {
ProgressView()
} else {
Text("action.done")
}
}
}
}

View File

@ -2,9 +2,11 @@ import SwiftUI
import Env
import Models
import DesignSystem
import Network
@MainActor
struct TimelineQuickAccessPills: View {
@Environment(Client.self) private var client
@Environment(Theme.self) private var theme
@Environment(CurrentAccount.self) private var currentAccount
@ -23,11 +25,28 @@ struct TimelineQuickAccessPills: View {
}
.scrollClipDisabled()
.scrollIndicators(.never)
.onChange(of: currentAccount.lists, { _, lists in
guard client.isAuth else { return }
var filters = pinnedFilters
for (index, filter) in filters.enumerated() {
switch filter {
case .list(let list):
if let accountList = lists.first(where: { $0.id == list.id }),
accountList.title != list.title {
filters[index] = .list(list: accountList)
}
default:
break
}
}
pinnedFilters = filters
})
}
@ViewBuilder
private func makePill(_ filter: TimelineFilter) -> some View {
if !isFilterSupport(filter) {
if !isFilterSupported(filter) {
EmptyView()
} else if filter == timeline {
makeButton(filter)
@ -47,6 +66,11 @@ struct TimelineQuickAccessPills: View {
Label(filter.title.replacingOccurrences(of: "#", with: ""),
systemImage: filter.iconName())
.font(.callout)
case let .list(list):
if let list = currentAccount.lists.first(where: { $0.id == list.id }) {
Label(list.title, systemImage: filter.iconName())
.font(.callout)
}
default:
Label(filter.localizedTitle(), systemImage: filter.iconName())
.font(.callout)
@ -62,7 +86,7 @@ struct TimelineQuickAccessPills: View {
draggedItem: $draggedFilter))
}
private func isFilterSupport(_ filter: TimelineFilter) -> Bool {
private func isFilterSupported(_ filter: TimelineFilter) -> Bool {
switch filter {
case .list(let list):
return currentAccount.lists.contains(where: { $0.id == list.id })

View File

@ -140,6 +140,19 @@ public struct TimelineView: View {
}
}
}
.onChange(of: account.lists, { _, lists in
guard client.isAuth else { return }
switch timeline {
case let .list(list):
if let accountList = lists.first(where: { $0.id == list.id }),
list.id == accountList.id,
accountList.title != list.title {
timeline = .list(list: accountList)
}
default:
break
}
})
.onChange(of: timeline) { _, newValue in
switch newValue {
case let .remoteLocal(server, _):