IceCubesApp/Packages/Status/Sources/Status/Editor/Components/AutoComplete/StatusEditorAutoCompleteView.swift
2024-01-06 12:32:23 +01:00

62 lines
1.9 KiB
Swift

import DesignSystem
import EmojiText
import Foundation
import SwiftUI
import Models
import SwiftData
@MainActor
struct StatusEditorAutoCompleteView: View {
@Environment(\.modelContext) var context
@Environment(Theme.self) var theme
var viewModel: StatusEditorViewModel
@State private var isTagSuggestionExpanded: Bool = false
@Query(sort: \RecentTag.lastUse, order: .reverse) var recentTags: [RecentTag]
var body: some View {
if !viewModel.mentionsSuggestions.isEmpty ||
!viewModel.tagsSuggestions.isEmpty ||
(viewModel.showRecentsTagsInline && !recentTags.isEmpty) {
VStack {
HStack {
ScrollView(.horizontal, showsIndicators: false) {
LazyHStack {
if !viewModel.mentionsSuggestions.isEmpty {
Self.MentionsView(viewModel: viewModel)
} else {
if viewModel.showRecentsTagsInline {
Self.RecentTagsView(viewModel: viewModel, isTagSuggestionExpanded: $isTagSuggestionExpanded)
} else {
Self.RemoteTagsView(viewModel: viewModel, isTagSuggestionExpanded: $isTagSuggestionExpanded)
}
}
}
.padding(.horizontal, .layoutPadding)
}
.scrollContentBackground(.hidden)
if viewModel.mentionsSuggestions.isEmpty {
Spacer()
Button {
withAnimation {
isTagSuggestionExpanded.toggle()
}
} label: {
Image(systemName: isTagSuggestionExpanded ? "chevron.down.circle" : "chevron.up.circle")
.padding(.trailing, 8)
}
}
}
.frame(height: 40)
if isTagSuggestionExpanded {
Self.ExpandedView(viewModel: viewModel, isTagSuggestionExpanded: $isTagSuggestionExpanded)
}
}
.background(.thinMaterial)
}
}
}