mirror of
https://github.com/yattee/yattee.git
synced 2025-08-05 02:04:07 +00:00
Replace environment objects with observed objects
This commit is contained in:
@@ -4,9 +4,8 @@ import SwiftUI
|
||||
struct SearchTextField: View {
|
||||
@Environment(\.navigationStyle) private var navigationStyle
|
||||
|
||||
@EnvironmentObject<NavigationModel> private var navigation
|
||||
@EnvironmentObject<RecentsModel> private var recents
|
||||
@EnvironmentObject<SearchModel> private var state
|
||||
private var navigation = NavigationModel.shared
|
||||
@ObservedObject private var state = SearchModel.shared
|
||||
|
||||
@Binding var favoriteItem: FavoriteItem?
|
||||
|
||||
@@ -34,7 +33,7 @@ struct SearchTextField: View {
|
||||
query.query = state.queryText
|
||||
navigation.hideKeyboard()
|
||||
}
|
||||
recents.addQuery(state.queryText, navigation: navigation)
|
||||
RecentsModel.shared.addQuery(state.queryText)
|
||||
}
|
||||
.disableAutocorrection(true)
|
||||
#if os(macOS)
|
||||
|
@@ -1,9 +1,7 @@
|
||||
import SwiftUI
|
||||
|
||||
struct SearchSuggestions: View {
|
||||
@EnvironmentObject<NavigationModel> private var navigation
|
||||
@EnvironmentObject<RecentsModel> private var recents
|
||||
@EnvironmentObject<SearchModel> private var state
|
||||
@ObservedObject private var state = SearchModel.shared
|
||||
|
||||
var body: some View {
|
||||
List {
|
||||
@@ -80,10 +78,10 @@ struct SearchSuggestions: View {
|
||||
|
||||
state.changeQuery { query in
|
||||
query.query = queryText
|
||||
navigation.hideKeyboard()
|
||||
NavigationModel.shared.hideKeyboard()
|
||||
}
|
||||
|
||||
recents.addQuery(queryText, navigation: navigation)
|
||||
RecentsModel.shared.addQuery(queryText)
|
||||
}
|
||||
|
||||
private var visibleSuggestions: [String] {
|
||||
|
@@ -14,17 +14,15 @@ struct SearchView: View {
|
||||
#if os(tvOS)
|
||||
@State private var searchDebounce = Debounce()
|
||||
@State private var recentsDebounce = Debounce()
|
||||
private var recents = RecentsModel.shared
|
||||
#endif
|
||||
|
||||
@State private var favoriteItem: FavoriteItem?
|
||||
|
||||
@Environment(\.navigationStyle) private var navigationStyle
|
||||
|
||||
@EnvironmentObject<AccountsModel> private var accounts
|
||||
@EnvironmentObject<NavigationModel> private var navigation
|
||||
@EnvironmentObject<PlayerModel> private var player
|
||||
@EnvironmentObject<RecentsModel> private var recents
|
||||
@EnvironmentObject<SearchModel> private var state
|
||||
@ObservedObject private var accounts = AccountsModel.shared
|
||||
@ObservedObject private var state = SearchModel.shared
|
||||
private var favorites = FavoritesModel.shared
|
||||
|
||||
@Default(.recentlyOpened) private var recentlyOpened
|
||||
@@ -313,20 +311,17 @@ struct SearchView: View {
|
||||
case .query:
|
||||
state.queryText = item.title
|
||||
state.changeQuery { query in query.query = item.title }
|
||||
navigation.hideKeyboard()
|
||||
NavigationModel.shared.hideKeyboard()
|
||||
|
||||
updateFavoriteItem()
|
||||
recents.add(item)
|
||||
RecentsModel.shared.add(item)
|
||||
case .channel:
|
||||
guard let channel = item.channel else {
|
||||
return
|
||||
}
|
||||
|
||||
NavigationModel.openChannel(
|
||||
NavigationModel.shared.openChannel(
|
||||
channel,
|
||||
player: player,
|
||||
recents: recents,
|
||||
navigation: navigation,
|
||||
navigationStyle: navigationStyle
|
||||
)
|
||||
case .playlist:
|
||||
@@ -334,11 +329,8 @@ struct SearchView: View {
|
||||
return
|
||||
}
|
||||
|
||||
NavigationModel.openChannelPlaylist(
|
||||
NavigationModel.shared.openChannelPlaylist(
|
||||
playlist,
|
||||
player: player,
|
||||
recents: recents,
|
||||
navigation: navigation,
|
||||
navigationStyle: navigationStyle
|
||||
)
|
||||
}
|
||||
@@ -359,7 +351,7 @@ struct SearchView: View {
|
||||
|
||||
private func removeButton(_ item: RecentItem) -> some View {
|
||||
Button {
|
||||
recents.close(item)
|
||||
RecentsModel.shared.close(item)
|
||||
recentsChanged.toggle()
|
||||
} label: {
|
||||
Label("Remove", systemImage: "trash")
|
||||
@@ -368,12 +360,12 @@ struct SearchView: View {
|
||||
|
||||
private var clearHistoryButton: some View {
|
||||
Button {
|
||||
navigation.presentAlert(
|
||||
NavigationModel.shared.presentAlert(
|
||||
Alert(
|
||||
title: Text("Are you sure you want to clear search history?"),
|
||||
message: Text("This cannot be reverted"),
|
||||
primaryButton: .destructive(Text("Clear")) {
|
||||
recents.clear()
|
||||
RecentsModel.shared.clear()
|
||||
recentsChanged.toggle()
|
||||
},
|
||||
secondaryButton: .cancel()
|
||||
|
Reference in New Issue
Block a user