mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-11-22 16:31:00 +00:00
Fix list not updating in the quick access pills
This commit is contained in:
parent
c4b85679a2
commit
13e87b41e9
3 changed files with 50 additions and 4 deletions
|
@ -72,8 +72,17 @@ public struct ListEditView: View {
|
||||||
.background(theme.secondaryBackgroundColor)
|
.background(theme.secondaryBackgroundColor)
|
||||||
.toolbar {
|
.toolbar {
|
||||||
ToolbarItem {
|
ToolbarItem {
|
||||||
Button("action.done") {
|
Button {
|
||||||
dismiss()
|
Task {
|
||||||
|
await viewModel.update()
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
|
} label: {
|
||||||
|
if viewModel.isUpdating {
|
||||||
|
ProgressView()
|
||||||
|
} else {
|
||||||
|
Text("action.done")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,11 @@ import SwiftUI
|
||||||
import Env
|
import Env
|
||||||
import Models
|
import Models
|
||||||
import DesignSystem
|
import DesignSystem
|
||||||
|
import Network
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
struct TimelineQuickAccessPills: View {
|
struct TimelineQuickAccessPills: View {
|
||||||
|
@Environment(Client.self) private var client
|
||||||
@Environment(Theme.self) private var theme
|
@Environment(Theme.self) private var theme
|
||||||
@Environment(CurrentAccount.self) private var currentAccount
|
@Environment(CurrentAccount.self) private var currentAccount
|
||||||
|
|
||||||
|
@ -23,11 +25,28 @@ struct TimelineQuickAccessPills: View {
|
||||||
}
|
}
|
||||||
.scrollClipDisabled()
|
.scrollClipDisabled()
|
||||||
.scrollIndicators(.never)
|
.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
|
@ViewBuilder
|
||||||
private func makePill(_ filter: TimelineFilter) -> some View {
|
private func makePill(_ filter: TimelineFilter) -> some View {
|
||||||
if !isFilterSupport(filter) {
|
if !isFilterSupported(filter) {
|
||||||
EmptyView()
|
EmptyView()
|
||||||
} else if filter == timeline {
|
} else if filter == timeline {
|
||||||
makeButton(filter)
|
makeButton(filter)
|
||||||
|
@ -47,6 +66,11 @@ struct TimelineQuickAccessPills: View {
|
||||||
Label(filter.title.replacingOccurrences(of: "#", with: ""),
|
Label(filter.title.replacingOccurrences(of: "#", with: ""),
|
||||||
systemImage: filter.iconName())
|
systemImage: filter.iconName())
|
||||||
.font(.callout)
|
.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:
|
default:
|
||||||
Label(filter.localizedTitle(), systemImage: filter.iconName())
|
Label(filter.localizedTitle(), systemImage: filter.iconName())
|
||||||
.font(.callout)
|
.font(.callout)
|
||||||
|
@ -62,7 +86,7 @@ struct TimelineQuickAccessPills: View {
|
||||||
draggedItem: $draggedFilter))
|
draggedItem: $draggedFilter))
|
||||||
}
|
}
|
||||||
|
|
||||||
private func isFilterSupport(_ filter: TimelineFilter) -> Bool {
|
private func isFilterSupported(_ filter: TimelineFilter) -> Bool {
|
||||||
switch filter {
|
switch filter {
|
||||||
case .list(let list):
|
case .list(let list):
|
||||||
return currentAccount.lists.contains(where: { $0.id == list.id })
|
return currentAccount.lists.contains(where: { $0.id == list.id })
|
||||||
|
|
|
@ -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
|
.onChange(of: timeline) { _, newValue in
|
||||||
switch newValue {
|
switch newValue {
|
||||||
case let .remoteLocal(server, _):
|
case let .remoteLocal(server, _):
|
||||||
|
|
Loading…
Reference in a new issue