mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-05-17 03:52:42 +00:00
45 lines
1.3 KiB
Swift
45 lines
1.3 KiB
Swift
import DesignSystem
|
|
import EmojiText
|
|
import Foundation
|
|
import Models
|
|
import SwiftData
|
|
import SwiftUI
|
|
|
|
extension StatusEditor.AutoCompleteView {
|
|
struct RemoteTagsView: View {
|
|
@Environment(\.modelContext) private var context
|
|
@Environment(Theme.self) private var theme
|
|
|
|
var viewModel: StatusEditor.ViewModel
|
|
@Binding var isTagSuggestionExpanded: Bool
|
|
|
|
@Query(sort: \RecentTag.lastUse, order: .reverse) var recentTags: [RecentTag]
|
|
|
|
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)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|