The overall UI of Ferrite has been changed to make animations smoother and streamline the experiences. A new search filter interface has been added for all iOS versions, but iOS 15 and up have smooth UI applied due to bugs with searchbars in iOS 14 (which shouldn't even have a searchbar in the first place). Also fix the plugin fetching logic to not listen to a combine publisher and instead use a notification that is easier to control. Signed-off-by: kingbri <bdashore3@proton.me>
75 lines
3.2 KiB
Swift
75 lines
3.2 KiB
Swift
//
|
|
// ContentView.swift
|
|
// Ferrite
|
|
//
|
|
// Created by Brian Dashore on 7/1/22.
|
|
//
|
|
|
|
import SwiftUI
|
|
import SwiftUIX
|
|
|
|
struct ContentView: View {
|
|
@EnvironmentObject var scrapingModel: ScrapingViewModel
|
|
@EnvironmentObject var debridManager: DebridManager
|
|
@EnvironmentObject var navModel: NavigationViewModel
|
|
@EnvironmentObject var pluginManager: PluginManager
|
|
|
|
var body: some View {
|
|
NavView {
|
|
SearchResultsView()
|
|
.listStyle(.insetGrouped)
|
|
.navigationTitle("Search")
|
|
.navigationSearchBar {
|
|
SearchBar("Search",
|
|
text: $scrapingModel.searchText,
|
|
isEditing: $navModel.isEditingSearch,
|
|
onCommit: {
|
|
scrapingModel.searchResults = []
|
|
scrapingModel.runningSearchTask = Task {
|
|
navModel.isSearching = true
|
|
navModel.showSearchProgress = true
|
|
|
|
let sources = pluginManager.fetchInstalledSources()
|
|
await scrapingModel.scanSources(sources: sources)
|
|
|
|
if debridManager.enabledDebrids.count > 0, !scrapingModel.searchResults.isEmpty {
|
|
debridManager.clearIAValues()
|
|
|
|
// Remove magnets that don't have a hash
|
|
let magnets = scrapingModel.searchResults.compactMap {
|
|
if let magnetHash = $0.magnet.hash {
|
|
return Magnet(hash: magnetHash, link: $0.magnet.link)
|
|
} else {
|
|
return nil
|
|
}
|
|
}
|
|
await debridManager.populateDebridIA(magnets)
|
|
}
|
|
|
|
navModel.showSearchProgress = false
|
|
}
|
|
})
|
|
.showsCancelButton(navModel.isEditingSearch || navModel.isSearching)
|
|
.onCancel {
|
|
scrapingModel.searchResults = []
|
|
scrapingModel.runningSearchTask?.cancel()
|
|
scrapingModel.runningSearchTask = nil
|
|
navModel.isSearching = false
|
|
scrapingModel.searchText = ""
|
|
}
|
|
}
|
|
.navigationSearchBarHiddenWhenScrolling(false)
|
|
.searchAppearance {
|
|
SearchFilterHeaderView()
|
|
.environmentObject(scrapingModel)
|
|
.environmentObject(debridManager)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct ContentView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
ContentView()
|
|
}
|
|
}
|