Add followed tags to tag suggestion

This commit is contained in:
Thomas Ricouard 2024-01-06 12:32:23 +01:00
parent 1297331407
commit 6435b40a51
2 changed files with 50 additions and 12 deletions

View file

@ -4,12 +4,15 @@ import Foundation
import SwiftUI import SwiftUI
import Models import Models
import SwiftData import SwiftData
import Env
extension StatusEditorAutoCompleteView { extension StatusEditorAutoCompleteView {
@MainActor
struct ExpandedView: View { struct ExpandedView: View {
@Environment(\.modelContext) private var context @Environment(\.modelContext) private var context
@Environment(Theme.self) private var theme @Environment(Theme.self) private var theme
@Environment(CurrentAccount.self) private var currentAccount
var viewModel: StatusEditorViewModel var viewModel: StatusEditorViewModel
@Binding var isTagSuggestionExpanded: Bool @Binding var isTagSuggestionExpanded: Bool
@ -17,6 +20,15 @@ extension StatusEditorAutoCompleteView {
@Query(sort: \RecentTag.lastUse, order: .reverse) var recentTags: [RecentTag] @Query(sort: \RecentTag.lastUse, order: .reverse) var recentTags: [RecentTag]
var body: some View { var body: some View {
TabView {
recentTagsPage
followedTagsPage
}
.tabViewStyle(.page(indexDisplayMode: .always))
.frame(height: 200)
}
private var recentTagsPage: some View {
ScrollView(.vertical) { ScrollView(.vertical) {
LazyVStack(alignment: .leading, spacing: 12) { LazyVStack(alignment: .leading, spacing: 12) {
Text("status.editor.language-select.recently-used") Text("status.editor.language-select.recently-used")
@ -48,15 +60,41 @@ extension StatusEditorAutoCompleteView {
} }
.padding(.horizontal, .layoutPadding) .padding(.horizontal, .layoutPadding)
} }
.frame(height: 200) }
.gesture(DragGesture(minimumDistance: 0, coordinateSpace: .local)
.onEnded({ value in private var followedTagsPage: some View {
withAnimation { ScrollView(.vertical) {
if value.translation.height > 0 { LazyVStack(alignment: .leading, spacing: 12) {
isTagSuggestionExpanded = false Text("timeline.filter.tags")
} .font(.scaledSubheadline)
} .foregroundStyle(theme.labelColor)
})) .fontWeight(.bold)
ForEach(currentAccount.tags) { tag in
HStack {
Button {
if let index = recentTags.firstIndex(where: { $0.title.lowercased() == tag.name.lowercased() }) {
recentTags[index].lastUse = Date()
} else {
context.insert(RecentTag(title: tag.name))
}
withAnimation {
isTagSuggestionExpanded = false
viewModel.selectHashtagSuggestion(tag: tag.name)
}
} label: {
VStack(alignment: .leading) {
Text("#\(tag.name)")
.font(.scaledFootnote)
.fontWeight(.bold)
.foregroundColor(theme.labelColor)
}
}
Spacer()
}
}
}
.padding(.horizontal, .layoutPadding)
}
} }
} }
} }

View file

@ -38,7 +38,7 @@ struct StatusEditorAutoCompleteView: View {
.padding(.horizontal, .layoutPadding) .padding(.horizontal, .layoutPadding)
} }
.scrollContentBackground(.hidden) .scrollContentBackground(.hidden)
if !viewModel.tagsSuggestions.isEmpty { if viewModel.mentionsSuggestions.isEmpty {
Spacer() Spacer()
Button { Button {
withAnimation { withAnimation {
@ -46,8 +46,8 @@ struct StatusEditorAutoCompleteView: View {
} }
} label: { } label: {
Image(systemName: isTagSuggestionExpanded ? "chevron.down.circle" : "chevron.up.circle") Image(systemName: isTagSuggestionExpanded ? "chevron.down.circle" : "chevron.up.circle")
.padding(.trailing, 8)
} }
.padding(.trailing, 8)
} }
} }
.frame(height: 40) .frame(height: 40)