From 6435b40a51338217fed7270833004c9bdea26e3d Mon Sep 17 00:00:00 2001 From: Thomas Ricouard Date: Sat, 6 Jan 2024 12:32:23 +0100 Subject: [PATCH] Add followed tags to tag suggestion --- .../AutoComplete/ExpandedView.swift | 58 +++++++++++++++---- .../StatusEditorAutoCompleteView.swift | 4 +- 2 files changed, 50 insertions(+), 12 deletions(-) diff --git a/Packages/Status/Sources/Status/Editor/Components/AutoComplete/ExpandedView.swift b/Packages/Status/Sources/Status/Editor/Components/AutoComplete/ExpandedView.swift index 419d1cc0..951b6729 100644 --- a/Packages/Status/Sources/Status/Editor/Components/AutoComplete/ExpandedView.swift +++ b/Packages/Status/Sources/Status/Editor/Components/AutoComplete/ExpandedView.swift @@ -4,12 +4,15 @@ import Foundation import SwiftUI import Models import SwiftData - +import Env extension StatusEditorAutoCompleteView { + + @MainActor struct ExpandedView: View { @Environment(\.modelContext) private var context @Environment(Theme.self) private var theme + @Environment(CurrentAccount.self) private var currentAccount var viewModel: StatusEditorViewModel @Binding var isTagSuggestionExpanded: Bool @@ -17,6 +20,15 @@ extension StatusEditorAutoCompleteView { @Query(sort: \RecentTag.lastUse, order: .reverse) var recentTags: [RecentTag] var body: some View { + TabView { + recentTagsPage + followedTagsPage + } + .tabViewStyle(.page(indexDisplayMode: .always)) + .frame(height: 200) + } + + private var recentTagsPage: some View { ScrollView(.vertical) { LazyVStack(alignment: .leading, spacing: 12) { Text("status.editor.language-select.recently-used") @@ -48,15 +60,41 @@ extension StatusEditorAutoCompleteView { } .padding(.horizontal, .layoutPadding) } - .frame(height: 200) - .gesture(DragGesture(minimumDistance: 0, coordinateSpace: .local) - .onEnded({ value in - withAnimation { - if value.translation.height > 0 { - isTagSuggestionExpanded = false - } - } - })) + } + + private var followedTagsPage: some View { + ScrollView(.vertical) { + LazyVStack(alignment: .leading, spacing: 12) { + 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) + } } } } diff --git a/Packages/Status/Sources/Status/Editor/Components/AutoComplete/StatusEditorAutoCompleteView.swift b/Packages/Status/Sources/Status/Editor/Components/AutoComplete/StatusEditorAutoCompleteView.swift index 35614ae0..28a5c242 100644 --- a/Packages/Status/Sources/Status/Editor/Components/AutoComplete/StatusEditorAutoCompleteView.swift +++ b/Packages/Status/Sources/Status/Editor/Components/AutoComplete/StatusEditorAutoCompleteView.swift @@ -38,7 +38,7 @@ struct StatusEditorAutoCompleteView: View { .padding(.horizontal, .layoutPadding) } .scrollContentBackground(.hidden) - if !viewModel.tagsSuggestions.isEmpty { + if viewModel.mentionsSuggestions.isEmpty { Spacer() Button { withAnimation { @@ -46,8 +46,8 @@ struct StatusEditorAutoCompleteView: View { } } label: { Image(systemName: isTagSuggestionExpanded ? "chevron.down.circle" : "chevron.up.circle") + .padding(.trailing, 8) } - .padding(.trailing, 8) } } .frame(height: 40)