mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2025-02-11 23:35:15 +00:00
Add basic search on timeline
This commit is contained in:
parent
5f05248523
commit
e3180a37e8
2 changed files with 26 additions and 0 deletions
|
@ -64,6 +64,10 @@ public struct TimelineView: View {
|
|||
.scrollContentBackground(.hidden)
|
||||
.background(theme.primaryBackgroundColor)
|
||||
#endif
|
||||
.searchable(text: $viewModel.searchQuery,
|
||||
isPresented: $viewModel.isSearchPresented,
|
||||
placement: .navigationBarDrawer(displayMode: .automatic),
|
||||
prompt: Text("Search"))
|
||||
.introspect(.list, on: .iOS(.v17)) { (collectionView: UICollectionView) in
|
||||
DispatchQueue.main.async {
|
||||
self.collectionView = collectionView
|
||||
|
|
|
@ -77,6 +77,28 @@ import SwiftUI
|
|||
var isTimelineVisible: Bool = false
|
||||
let pendingStatusesObserver: PendingStatusesObserver = .init()
|
||||
var scrollToIndexAnimated: Bool = false
|
||||
|
||||
var searchQuery: String = "" {
|
||||
didSet {
|
||||
Task {
|
||||
let statuses = await datasource.get().filter { status in
|
||||
status.content.asRawText.contains(searchQuery)
|
||||
}
|
||||
statusesState = .display(statuses: statuses, nextPageState: .none)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var isSearchPresented: Bool = false {
|
||||
didSet {
|
||||
if !isSearchPresented {
|
||||
Task {
|
||||
let statuses = await datasource.get()
|
||||
statusesState = .display(statuses: statuses, nextPageState: .hasNextPage)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init() {
|
||||
pendingStatusesObserver.scrollToIndex = { [weak self] index in
|
||||
|
|
Loading…
Reference in a new issue