Also sort tags and lists in profile view (#764)

* Add CurrentAccount.sortedLists and .sortedTags

Sorts alphabetically, ascending, lowercased on title and name respectively.

* TimelineTab uses CurrentAccount.sortedLists and .sortedTags

* Account detail sorts tags and lists

Alphabetically, ascending, lowercased via CurrentAccount.sortedTags, .sortedLists
This commit is contained in:
David Davies-Payne 2023-02-10 18:38:18 +13:00 committed by GitHub
parent 22b4044dfd
commit 11167c35c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 6 deletions

View file

@ -112,9 +112,8 @@ struct TimelineTab: View {
} }
} }
if !currentAccount.lists.isEmpty { if !currentAccount.lists.isEmpty {
let sortedLists = currentAccount.lists.sorted { $0.title.lowercased() < $1.title.lowercased() }
Menu("timeline.filter.lists") { Menu("timeline.filter.lists") {
ForEach(sortedLists) { list in ForEach(currentAccount.sortedLists) { list in
Button { Button {
timeline = .list(list: list) timeline = .list(list: list)
} label: { } label: {
@ -125,9 +124,8 @@ struct TimelineTab: View {
} }
if !currentAccount.tags.isEmpty { if !currentAccount.tags.isEmpty {
let sortedTags = currentAccount.tags.sorted { $0.name.lowercased() < $1.name.lowercased() }
Menu("timeline.filter.tags") { Menu("timeline.filter.tags") {
ForEach(sortedTags) { tag in ForEach(currentAccount.sortedTags) { tag in
Button { Button {
timeline = .hashtag(tag: tag.name, accountId: nil) timeline = .hashtag(tag: tag.name, accountId: nil)
} label: { } label: {

View file

@ -264,7 +264,7 @@ public struct AccountDetailView: View {
private var tagsListView: some View { private var tagsListView: some View {
Group { Group {
ForEach(currentAccount.tags) { tag in ForEach(currentAccount.sortedTags) { tag in
HStack { HStack {
TagRowView(tag: tag) TagRowView(tag: tag)
Spacer() Spacer()
@ -280,7 +280,7 @@ public struct AccountDetailView: View {
private var listsListView: some View { private var listsListView: some View {
Group { Group {
ForEach(currentAccount.lists) { list in ForEach(currentAccount.sortedLists) { list in
NavigationLink(value: RouterDestinations.list(list: list)) { NavigationLink(value: RouterDestinations.list(list: list)) {
HStack { HStack {
Text(list.title) Text(list.title)

View file

@ -16,6 +16,14 @@ public class CurrentAccount: ObservableObject {
public static let shared = CurrentAccount() public static let shared = CurrentAccount()
public var sortedLists: [List] {
lists.sorted { $0.title.lowercased() < $1.title.lowercased() }
}
public var sortedTags: [Tag] {
tags.sorted { $0.name.lowercased() < $1.name.lowercased() }
}
private init() {} private init() {}
public func setClient(client: Client) { public func setClient(client: Client) {