mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2024-12-17 17:20:21 +01:00
only show preset when it has matches
This commit is contained in:
@@ -667,9 +667,34 @@ enum ChatTagFilter: Identifiable, Equatable {
|
||||
|
||||
struct ChatTagsView: View {
|
||||
@EnvironmentObject var chatTagsModel: ChatTagsModel
|
||||
|
||||
@EnvironmentObject var chatModel: ChatModel
|
||||
|
||||
var presetTagFilters: [ChatTagFilter] {
|
||||
get {
|
||||
var tags: [ChatTagFilter] = []
|
||||
var filtersLeft = chatTagsModel.presetTags
|
||||
for chat in chatModel.chats {
|
||||
for filter in filtersLeft {
|
||||
if case let .presetTag(_, _, filterFunction) = filter {
|
||||
if filterFunction(chat.chatInfo) {
|
||||
tags.append(filter)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
filtersLeft.removeAll { tags.contains($0) }
|
||||
if filtersLeft.isEmpty {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return tags
|
||||
}
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
let tags = chatTagsModel.presetTags + chatTagsModel.tags
|
||||
let tags = presetTagFilters + chatTagsModel.tags
|
||||
HStack {
|
||||
ForEach(tags, id: \.id) { tag in
|
||||
let current = chatTagsModel.selectedTag == tag
|
||||
@@ -700,6 +725,9 @@ struct ChatTagsView: View {
|
||||
}.task {
|
||||
getChatTags()
|
||||
}
|
||||
.onChange(of: chatModel.currentUser?.userId) { _ in
|
||||
getChatTags()
|
||||
}
|
||||
}
|
||||
|
||||
private func getChatTags() {
|
||||
|
||||
Reference in New Issue
Block a user