IceCubesApp/Packages/StatusKit/Sources/StatusKit/Editor/Components/AutoComplete/RemoteTagsView.swift

45 lines
1.3 KiB
Swift
Raw Normal View History

2024-01-06 09:52:04 +00:00
import DesignSystem
import EmojiText
import Foundation
import Models
import SwiftData
2024-02-14 11:48:14 +00:00
import SwiftUI
2024-01-06 09:52:04 +00:00
2024-01-06 17:43:26 +00:00
extension StatusEditor.AutoCompleteView {
2024-01-06 09:52:04 +00:00
struct RemoteTagsView: View {
@Environment(\.modelContext) private var context
@Environment(Theme.self) private var theme
2024-02-14 11:48:14 +00:00
2024-01-06 17:43:26 +00:00
var viewModel: StatusEditor.ViewModel
2024-01-06 09:52:04 +00:00
@Binding var isTagSuggestionExpanded: Bool
2024-02-14 11:48:14 +00:00
2024-01-06 09:52:04 +00:00
@Query(sort: \RecentTag.lastUse, order: .reverse) var recentTags: [RecentTag]
2024-02-14 11:48:14 +00:00
2024-01-06 09:52:04 +00:00
var body: some View {
ForEach(viewModel.tagsSuggestions) { tag in
Button {
withAnimation {
isTagSuggestionExpanded = false
viewModel.selectHashtagSuggestion(tag: tag.name)
}
if let index = recentTags.firstIndex(where: { $0.title.lowercased() == tag.name.lowercased() }) {
recentTags[index].lastUse = Date()
} else {
context.insert(RecentTag(title: tag.name))
}
} label: {
VStack(alignment: .leading) {
Text("#\(tag.name)")
.font(.scaledFootnote)
.fontWeight(.bold)
.foregroundColor(theme.labelColor)
Text("tag.suggested.mentions-\(tag.totalUses)")
.font(.scaledFootnote)
.foregroundStyle(theme.tintColor)
}
}
}
}
}
}