diff --git a/IceCubesApp/App/AppRouter.swift b/IceCubesApp/App/AppRouter.swift index b77655e6..bd8c1c0e 100644 --- a/IceCubesApp/App/AppRouter.swift +++ b/IceCubesApp/App/AppRouter.swift @@ -112,12 +112,12 @@ extension View { } func withEnvironments() -> some View { - environmentObject(CurrentAccount.shared) + environment(CurrentAccount.shared) .environmentObject(UserPreferences.shared) - .environmentObject(CurrentInstance.shared) + .environment(CurrentInstance.shared) .environmentObject(Theme.shared) .environment(AppAccountsManager.shared) - .environmentObject(PushNotificationsService.shared) + .environment(PushNotificationsService.shared) .environment(AppAccountsManager.shared.currentClient) } } diff --git a/IceCubesApp/App/IceCubesApp.swift b/IceCubesApp/App/IceCubesApp.swift index 643eb6b0..482edde8 100644 --- a/IceCubesApp/App/IceCubesApp.swift +++ b/IceCubesApp/App/IceCubesApp.swift @@ -16,10 +16,10 @@ struct IceCubesApp: App { @Environment(\.scenePhase) private var scenePhase @State private var appAccountsManager = AppAccountsManager.shared - @StateObject private var currentInstance = CurrentInstance.shared - @StateObject private var currentAccount = CurrentAccount.shared + @State private var currentInstance = CurrentInstance.shared + @State private var currentAccount = CurrentAccount.shared @StateObject private var userPreferences = UserPreferences.shared - @StateObject private var pushNotificationsService = PushNotificationsService.shared + @State private var pushNotificationsService = PushNotificationsService.shared @State private var watcher = StreamWatcher() @StateObject private var quickLook = QuickLook() @StateObject private var theme = Theme.shared @@ -46,12 +46,12 @@ struct IceCubesApp: App { .environment(appAccountsManager) .environment(appAccountsManager.currentClient) .environmentObject(quickLook) - .environmentObject(currentAccount) - .environmentObject(currentInstance) + .environment(currentAccount) + .environment(currentInstance) .environmentObject(userPreferences) .environmentObject(theme) .environment(watcher) - .environmentObject(pushNotificationsService) + .environment(pushNotificationsService) .environment(\.isSupporter, isSupporter) .fullScreenCover(item: $quickLook.url, content: { url in QuickLookPreview(selectedURL: url, urls: quickLook.urls) diff --git a/IceCubesApp/App/SideBarView.swift b/IceCubesApp/App/SideBarView.swift index dc7d68d3..9f2202f7 100644 --- a/IceCubesApp/App/SideBarView.swift +++ b/IceCubesApp/App/SideBarView.swift @@ -7,7 +7,7 @@ import SwiftUI struct SideBarView: View { @Environment(AppAccountsManager.self) private var appAccounts - @EnvironmentObject private var currentAccount: CurrentAccount + @Environment(CurrentAccount.self) private var currentAccount @EnvironmentObject private var theme: Theme @Environment(StreamWatcher.self) private var watcher @EnvironmentObject private var userPreferences: UserPreferences diff --git a/IceCubesApp/App/Tabs/ExploreTab.swift b/IceCubesApp/App/Tabs/ExploreTab.swift index f98902bb..76481699 100644 --- a/IceCubesApp/App/Tabs/ExploreTab.swift +++ b/IceCubesApp/App/Tabs/ExploreTab.swift @@ -10,7 +10,7 @@ import SwiftUI struct ExploreTab: View { @EnvironmentObject private var theme: Theme @EnvironmentObject private var preferences: UserPreferences - @EnvironmentObject private var currentAccount: CurrentAccount + @Environment(CurrentAccount.self) private var currentAccount @Environment(Client.self) private var client @State private var routerPath = RouterPath() @Binding var popToRootTab: Tab diff --git a/IceCubesApp/App/Tabs/MessagesTab.swift b/IceCubesApp/App/Tabs/MessagesTab.swift index 25a59e02..767e7b1f 100644 --- a/IceCubesApp/App/Tabs/MessagesTab.swift +++ b/IceCubesApp/App/Tabs/MessagesTab.swift @@ -12,7 +12,7 @@ struct MessagesTab: View { @EnvironmentObject private var theme: Theme @Environment(StreamWatcher.self) private var watcher @Environment(Client.self) private var client - @EnvironmentObject private var currentAccount: CurrentAccount + @Environment(CurrentAccount.self) private var currentAccount @Environment(AppAccountsManager.self) private var appAccount @State private var routerPath = RouterPath() @Binding var popToRootTab: Tab diff --git a/IceCubesApp/App/Tabs/NotificationTab.swift b/IceCubesApp/App/Tabs/NotificationTab.swift index bd066097..53d04458 100644 --- a/IceCubesApp/App/Tabs/NotificationTab.swift +++ b/IceCubesApp/App/Tabs/NotificationTab.swift @@ -15,9 +15,9 @@ struct NotificationsTab: View { @Environment(Client.self) private var client @Environment(StreamWatcher.self) private var watcher @Environment(AppAccountsManager.self) private var appAccount - @EnvironmentObject private var currentAccount: CurrentAccount + @Environment(CurrentAccount.self) private var currentAccount @EnvironmentObject private var userPreferences: UserPreferences - @EnvironmentObject private var pushNotificationsService: PushNotificationsService + @Environment(PushNotificationsService.self) private var pushNotificationsService @State private var routerPath = RouterPath() @Binding var popToRootTab: Tab diff --git a/IceCubesApp/App/Tabs/ProfileTab.swift b/IceCubesApp/App/Tabs/ProfileTab.swift index 82ded4a1..1448d183 100644 --- a/IceCubesApp/App/Tabs/ProfileTab.swift +++ b/IceCubesApp/App/Tabs/ProfileTab.swift @@ -12,7 +12,7 @@ struct ProfileTab: View { @Environment(AppAccountsManager.self) private var appAccount @EnvironmentObject private var theme: Theme @Environment(Client.self) private var client - @EnvironmentObject private var currentAccount: CurrentAccount + @Environment(CurrentAccount.self) private var currentAccount @State private var routerPath = RouterPath() @Binding var popToRootTab: Tab diff --git a/IceCubesApp/App/Tabs/Settings/AccountSettingView.swift b/IceCubesApp/App/Tabs/Settings/AccountSettingView.swift index 730dd859..a1610a88 100644 --- a/IceCubesApp/App/Tabs/Settings/AccountSettingView.swift +++ b/IceCubesApp/App/Tabs/Settings/AccountSettingView.swift @@ -11,9 +11,9 @@ struct AccountSettingsView: View { @Environment(\.dismiss) private var dismiss @Environment(\.openURL) private var openURL - @EnvironmentObject private var pushNotifications: PushNotificationsService - @EnvironmentObject private var currentAccount: CurrentAccount - @EnvironmentObject private var currentInstance: CurrentInstance + @Environment(PushNotificationsService.self) private var pushNotifications + @Environment(CurrentAccount.self) private var currentAccount + @Environment(CurrentInstance.self) private var currentInstance @EnvironmentObject private var theme: Theme @Environment(AppAccountsManager.self) private var appAccountsManager @Environment(Client.self) private var client diff --git a/IceCubesApp/App/Tabs/Settings/AddAccountsView.swift b/IceCubesApp/App/Tabs/Settings/AddAccountsView.swift index 18d972be..fc8ccca1 100644 --- a/IceCubesApp/App/Tabs/Settings/AddAccountsView.swift +++ b/IceCubesApp/App/Tabs/Settings/AddAccountsView.swift @@ -14,9 +14,9 @@ struct AddAccountView: View { @Environment(\.scenePhase) private var scenePhase @Environment(AppAccountsManager.self) private var appAccountsManager - @EnvironmentObject private var currentAccount: CurrentAccount - @EnvironmentObject private var currentInstance: CurrentInstance - @EnvironmentObject private var pushNotifications: PushNotificationsService + @Environment(CurrentAccount.self) private var currentAccount + @Environment(CurrentInstance.self) private var currentInstance + @Environment(PushNotificationsService.self) private var pushNotifications @EnvironmentObject private var theme: Theme @State private var instanceName: String = "" diff --git a/IceCubesApp/App/Tabs/Settings/PushNotificationsView.swift b/IceCubesApp/App/Tabs/Settings/PushNotificationsView.swift index 272b06a8..f5f219bc 100644 --- a/IceCubesApp/App/Tabs/Settings/PushNotificationsView.swift +++ b/IceCubesApp/App/Tabs/Settings/PushNotificationsView.swift @@ -10,7 +10,7 @@ import UserNotifications struct PushNotificationsView: View { @EnvironmentObject private var theme: Theme @Environment(AppAccountsManager.self) private var appAccountsManager - @EnvironmentObject private var pushNotifications: PushNotificationsService + @Environment(PushNotificationsService.self) private var pushNotifications @StateObject public var subscription: PushNotificationSubscriptionSettings diff --git a/IceCubesApp/App/Tabs/Settings/SettingsTab.swift b/IceCubesApp/App/Tabs/Settings/SettingsTab.swift index 1fd0c825..aa919a81 100644 --- a/IceCubesApp/App/Tabs/Settings/SettingsTab.swift +++ b/IceCubesApp/App/Tabs/Settings/SettingsTab.swift @@ -12,10 +12,10 @@ import Timeline struct SettingsTabs: View { @Environment(\.dismiss) private var dismiss - @EnvironmentObject private var pushNotifications: PushNotificationsService + @Environment(PushNotificationsService.self) private var pushNotifications @EnvironmentObject private var preferences: UserPreferences @Environment(Client.self) private var client - @EnvironmentObject private var currentInstance: CurrentInstance + @Environment(CurrentInstance.self) private var currentInstance @Environment(AppAccountsManager.self) private var appAccountsManager @EnvironmentObject private var theme: Theme diff --git a/IceCubesApp/App/Tabs/Timeline/TimelineTab.swift b/IceCubesApp/App/Tabs/Timeline/TimelineTab.swift index f695c9ec..7a3a5e3c 100644 --- a/IceCubesApp/App/Tabs/Timeline/TimelineTab.swift +++ b/IceCubesApp/App/Tabs/Timeline/TimelineTab.swift @@ -10,7 +10,7 @@ import Timeline struct TimelineTab: View { @Environment(AppAccountsManager.self) private var appAccount @EnvironmentObject private var theme: Theme - @EnvironmentObject private var currentAccount: CurrentAccount + @Environment(CurrentAccount.self) private var currentAccount @EnvironmentObject private var preferences: UserPreferences @Environment(Client.self) private var client @State private var routerPath = RouterPath() diff --git a/IceCubesShareExtension/ShareViewController.swift b/IceCubesShareExtension/ShareViewController.swift index 060059e7..b9a8ed8c 100644 --- a/IceCubesShareExtension/ShareViewController.swift +++ b/IceCubesShareExtension/ShareViewController.swift @@ -30,9 +30,9 @@ class ShareViewController: UIViewController { .environmentObject(UserPreferences.shared) .environment(appAccountsManager) .environment(client) - .environmentObject(account) + .environment(account) .environmentObject(theme) - .environmentObject(instance) + .environment(instance) .tint(theme.tintColor) .preferredColorScheme(colorScheme == .light ? .light : .dark) let childView = UIHostingController(rootView: view) diff --git a/Packages/Account/Sources/Account/AccountDetailContextMenu.swift b/Packages/Account/Sources/Account/AccountDetailContextMenu.swift index cfae8a51..ce11c899 100644 --- a/Packages/Account/Sources/Account/AccountDetailContextMenu.swift +++ b/Packages/Account/Sources/Account/AccountDetailContextMenu.swift @@ -5,7 +5,7 @@ import SwiftUI public struct AccountDetailContextMenu: View { @Environment(Client.self) private var client @Environment(RouterPath.self) private var routerPath - @EnvironmentObject private var currentInstance: CurrentInstance + @Environment(CurrentInstance.self) private var currentInstance @EnvironmentObject private var preferences: UserPreferences var viewModel: AccountDetailViewModel diff --git a/Packages/Account/Sources/Account/AccountDetailHeaderView.swift b/Packages/Account/Sources/Account/AccountDetailHeaderView.swift index ecbf6db8..2795b004 100644 --- a/Packages/Account/Sources/Account/AccountDetailHeaderView.swift +++ b/Packages/Account/Sources/Account/AccountDetailHeaderView.swift @@ -14,7 +14,7 @@ struct AccountDetailHeaderView: View { @EnvironmentObject private var theme: Theme @EnvironmentObject private var quickLook: QuickLook @Environment(RouterPath.self) private var routerPath - @EnvironmentObject private var currentAccount: CurrentAccount + @Environment(CurrentAccount.self) private var currentAccount @Environment(\.redactionReasons) private var reasons @Environment(\.isSupporter) private var isSupporter: Bool diff --git a/Packages/Account/Sources/Account/AccountDetailView.swift b/Packages/Account/Sources/Account/AccountDetailView.swift index 975d7d7b..daf594eb 100644 --- a/Packages/Account/Sources/Account/AccountDetailView.swift +++ b/Packages/Account/Sources/Account/AccountDetailView.swift @@ -12,8 +12,8 @@ public struct AccountDetailView: View { @Environment(\.redactionReasons) private var reasons @Environment(StreamWatcher.self) private var watcher - @EnvironmentObject private var currentAccount: CurrentAccount - @EnvironmentObject private var currentInstance: CurrentInstance + @Environment(CurrentAccount.self) private var currentAccount + @Environment(CurrentInstance.self) private var currentInstance @EnvironmentObject private var preferences: UserPreferences @EnvironmentObject private var theme: Theme @Environment(Client.self) private var client diff --git a/Packages/Account/Sources/Account/AccountsList/AccountsListRow.swift b/Packages/Account/Sources/Account/AccountsList/AccountsListRow.swift index c80ebb1c..25ed8a03 100644 --- a/Packages/Account/Sources/Account/AccountsList/AccountsListRow.swift +++ b/Packages/Account/Sources/Account/AccountsList/AccountsListRow.swift @@ -22,7 +22,7 @@ import Observation public struct AccountsListRow: View { @EnvironmentObject private var theme: Theme - @EnvironmentObject private var currentAccount: CurrentAccount + @Environment(CurrentAccount.self) private var currentAccount @Environment(RouterPath.self) private var routerPath @Environment(Client.self) private var client @@ -118,7 +118,7 @@ public struct AccountsListRow: View { .scrollContentBackground(.hidden) .background(theme.primaryBackgroundColor) .environmentObject(theme) - .environmentObject(currentAccount) + .environment(currentAccount) .environment(client) } } diff --git a/Packages/Account/Sources/Account/AccountsList/AccountsListView.swift b/Packages/Account/Sources/Account/AccountsList/AccountsListView.swift index 45a8f415..dd1df8df 100644 --- a/Packages/Account/Sources/Account/AccountsList/AccountsListView.swift +++ b/Packages/Account/Sources/Account/AccountsList/AccountsListView.swift @@ -8,7 +8,7 @@ import SwiftUI public struct AccountsListView: View { @EnvironmentObject private var theme: Theme @Environment(Client.self) private var client - @EnvironmentObject private var currentAccount: CurrentAccount + @Environment(CurrentAccount.self) private var currentAccount @State private var viewModel: AccountsListViewModel @State private var didAppear: Bool = false diff --git a/Packages/Account/Sources/Account/Filters/EditFilterView.swift b/Packages/Account/Sources/Account/Filters/EditFilterView.swift index 57ed44b4..0acfdbc1 100644 --- a/Packages/Account/Sources/Account/Filters/EditFilterView.swift +++ b/Packages/Account/Sources/Account/Filters/EditFilterView.swift @@ -8,7 +8,7 @@ struct EditFilterView: View { @Environment(\.dismiss) private var dismiss @EnvironmentObject private var theme: Theme - @EnvironmentObject private var account: CurrentAccount + @Environment(CurrentAccount.self) private var account @Environment(Client.self) private var client @State private var isSavingFilter: Bool = false diff --git a/Packages/Account/Sources/Account/Filters/FiltersListView.swift b/Packages/Account/Sources/Account/Filters/FiltersListView.swift index f78d1afe..6a418921 100644 --- a/Packages/Account/Sources/Account/Filters/FiltersListView.swift +++ b/Packages/Account/Sources/Account/Filters/FiltersListView.swift @@ -8,7 +8,7 @@ public struct FiltersListView: View { @Environment(\.dismiss) private var dismiss @EnvironmentObject private var theme: Theme - @EnvironmentObject private var account: CurrentAccount + @Environment(CurrentAccount.self) private var account @Environment(Client.self) private var client @State private var isLoading: Bool = true diff --git a/Packages/AppAccount/Sources/AppAccount/AppAccountsSelectorView.swift b/Packages/AppAccount/Sources/AppAccount/AppAccountsSelectorView.swift index d4a94867..b26abe11 100644 --- a/Packages/AppAccount/Sources/AppAccount/AppAccountsSelectorView.swift +++ b/Packages/AppAccount/Sources/AppAccount/AppAccountsSelectorView.swift @@ -4,7 +4,7 @@ import SwiftUI public struct AppAccountsSelectorView: View { @EnvironmentObject private var preferences: UserPreferences - @EnvironmentObject private var currentAccount: CurrentAccount + @Environment(CurrentAccount.self) private var currentAccount @Environment(AppAccountsManager.self) private var appAccounts @EnvironmentObject private var theme: Theme diff --git a/Packages/Conversations/Sources/Conversations/Detail/ConversationDetailView.swift b/Packages/Conversations/Sources/Conversations/Detail/ConversationDetailView.swift index a174bb11..6cd9c793 100644 --- a/Packages/Conversations/Sources/Conversations/Detail/ConversationDetailView.swift +++ b/Packages/Conversations/Sources/Conversations/Detail/ConversationDetailView.swift @@ -12,7 +12,7 @@ public struct ConversationDetailView: View { @EnvironmentObject private var quickLook: QuickLook @Environment(RouterPath.self) private var routerPath - @EnvironmentObject private var currentAccount: CurrentAccount + @Environment(CurrentAccount.self) private var currentAccount @Environment(Client.self) private var client @EnvironmentObject private var theme: Theme @Environment(StreamWatcher.self) private var watcher diff --git a/Packages/Conversations/Sources/Conversations/Detail/ConversationMessageView.swift b/Packages/Conversations/Sources/Conversations/Detail/ConversationMessageView.swift index c3a4ef08..971a560f 100644 --- a/Packages/Conversations/Sources/Conversations/Detail/ConversationMessageView.swift +++ b/Packages/Conversations/Sources/Conversations/Detail/ConversationMessageView.swift @@ -8,7 +8,7 @@ import SwiftUI struct ConversationMessageView: View { @EnvironmentObject private var quickLook: QuickLook @Environment(RouterPath.self) private var routerPath - @EnvironmentObject private var currentAccount: CurrentAccount + @Environment(CurrentAccount.self) private var currentAccount @Environment(Client.self) private var client @EnvironmentObject private var theme: Theme diff --git a/Packages/Conversations/Sources/Conversations/List/ConversationsListRow.swift b/Packages/Conversations/Sources/Conversations/List/ConversationsListRow.swift index cb626738..15c58f2d 100644 --- a/Packages/Conversations/Sources/Conversations/List/ConversationsListRow.swift +++ b/Packages/Conversations/Sources/Conversations/List/ConversationsListRow.swift @@ -9,7 +9,7 @@ struct ConversationsListRow: View { @Environment(Client.self) private var client @Environment(RouterPath.self) private var routerPath @EnvironmentObject private var theme: Theme - @EnvironmentObject private var currentAccount: CurrentAccount + @Environment(CurrentAccount.self) private var currentAccount @Binding var conversation: Conversation @ObservedObject var viewModel: ConversationsListViewModel diff --git a/Packages/DesignSystem/Sources/DesignSystem/Views/FollowRequestButtons.swift b/Packages/DesignSystem/Sources/DesignSystem/Views/FollowRequestButtons.swift index 6de2e53c..043cb5b0 100644 --- a/Packages/DesignSystem/Sources/DesignSystem/Views/FollowRequestButtons.swift +++ b/Packages/DesignSystem/Sources/DesignSystem/Views/FollowRequestButtons.swift @@ -3,7 +3,7 @@ import Models import SwiftUI public struct FollowRequestButtons: View { - @EnvironmentObject private var currentAccount: CurrentAccount + @Environment(CurrentAccount.self) private var currentAccount let account: Account let requestUpdated: (() -> Void)? diff --git a/Packages/Env/Sources/Env/CurrentAccount.swift b/Packages/Env/Sources/Env/CurrentAccount.swift index b3db9321..15ea373b 100644 --- a/Packages/Env/Sources/Env/CurrentAccount.swift +++ b/Packages/Env/Sources/Env/CurrentAccount.swift @@ -2,18 +2,19 @@ import Combine import Foundation import Models import Network +import Observation @MainActor -public class CurrentAccount: ObservableObject { +@Observable public class CurrentAccount { private static var accountsCache: [String: Account] = [:] - @Published public private(set) var account: Account? - @Published public private(set) var lists: [List] = [] - @Published public private(set) var tags: [Tag] = [] - @Published public private(set) var followRequests: [Account] = [] - @Published public private(set) var isUpdating: Bool = false - @Published public private(set) var updatingFollowRequestAccountIds = Set() - @Published public private(set) var isLoadingAccount: Bool = false + public private(set) var account: Account? + public private(set) var lists: [List] = [] + public private(set) var tags: [Tag] = [] + public private(set) var followRequests: [Account] = [] + public private(set) var isUpdating: Bool = false + public private(set) var updatingFollowRequestAccountIds = Set() + public private(set) var isLoadingAccount: Bool = false private var client: Client? diff --git a/Packages/Env/Sources/Env/CurrentInstance.swift b/Packages/Env/Sources/Env/CurrentInstance.swift index 8535eb7e..41766cbe 100644 --- a/Packages/Env/Sources/Env/CurrentInstance.swift +++ b/Packages/Env/Sources/Env/CurrentInstance.swift @@ -2,10 +2,11 @@ import Combine import Foundation import Models import Network +import Observation @MainActor -public class CurrentInstance: ObservableObject { - @Published public private(set) var instance: Instance? +@Observable public class CurrentInstance { + public private(set) var instance: Instance? private var client: Client? diff --git a/Packages/Env/Sources/Env/PushNotificationsService.swift b/Packages/Env/Sources/Env/PushNotificationsService.swift index 636d01ca..3d398528 100644 --- a/Packages/Env/Sources/Env/PushNotificationsService.swift +++ b/Packages/Env/Sources/Env/PushNotificationsService.swift @@ -6,6 +6,7 @@ import Models import Network import SwiftUI import UserNotifications +import Observation extension UNNotificationResponse: @unchecked Sendable {} extension UNUserNotificationCenter: @unchecked Sendable {} @@ -28,7 +29,7 @@ public struct HandledNotification: Equatable { } @MainActor -public class PushNotificationsService: NSObject, ObservableObject { +@Observable public class PushNotificationsService: NSObject { enum Constants { static let endpoint = "https://icecubesrelay.fly.dev" static let keychainAuthKey = "notifications_auth_key" @@ -39,9 +40,9 @@ public class PushNotificationsService: NSObject, ObservableObject { public private(set) var subscriptions: [PushNotificationSubscriptionSettings] = [] - @Published public var pushToken: Data? + public var pushToken: Data? - @Published public var handledNotification: HandledNotification? + public var handledNotification: HandledNotification? override init() { super.init() diff --git a/Packages/Explore/Sources/Explore/ExploreView.swift b/Packages/Explore/Sources/Explore/ExploreView.swift index a6f3ec90..59885e1e 100644 --- a/Packages/Explore/Sources/Explore/ExploreView.swift +++ b/Packages/Explore/Sources/Explore/ExploreView.swift @@ -12,7 +12,7 @@ public struct ExploreView: View { @Environment(Client.self) private var client @Environment(RouterPath.self) private var routerPath - @StateObject private var viewModel = ExploreViewModel() + @State private var viewModel = ExploreViewModel() public init() {} @@ -89,6 +89,11 @@ public struct ExploreView: View { Text(scope.localizedString) } } + .onChange(of: viewModel.searchQuery) { oldValue, newValue in + if oldValue != newValue { + viewModel.search() + } + } } private var quickAccessView: some View { diff --git a/Packages/Explore/Sources/Explore/ExploreViewModel.swift b/Packages/Explore/Sources/Explore/ExploreViewModel.swift index af19b021..1dc96b41 100644 --- a/Packages/Explore/Sources/Explore/ExploreViewModel.swift +++ b/Packages/Explore/Sources/Explore/ExploreViewModel.swift @@ -1,10 +1,10 @@ -import Combine import Models import Network import SwiftUI +import Observation @MainActor -class ExploreViewModel: ObservableObject { +@Observable class ExploreViewModel { enum SearchScope: String, CaseIterable { case all, people, hashtags, posts @@ -39,34 +39,25 @@ class ExploreViewModel: ObservableObject { trendingLinks.isEmpty && trendingTags.isEmpty && trendingStatuses.isEmpty && suggestedAccounts.isEmpty } - @Published var searchQuery = "" { + var searchQuery = "" { didSet { isSearching = true } } - @Published var results: [String: SearchResults] = [:] - @Published var isLoaded = false - @Published var isSearching = false - @Published var suggestedAccounts: [Account] = [] - @Published var suggestedAccountsRelationShips: [Relationship] = [] - @Published var trendingTags: [Tag] = [] - @Published var trendingStatuses: [Status] = [] - @Published var trendingLinks: [Card] = [] - @Published var searchScope: SearchScope = .all + var results: [String: SearchResults] = [:] + var isLoaded = false + var isSearching = false + var suggestedAccounts: [Account] = [] + var suggestedAccountsRelationShips: [Relationship] = [] + var trendingTags: [Tag] = [] + var trendingStatuses: [Status] = [] + var trendingLinks: [Card] = [] + var searchScope: SearchScope = .all private var searchTask: Task? - private var cancellables = Set() - - init() { - $searchQuery - .removeDuplicates() - .debounce(for: .milliseconds(250), scheduler: DispatchQueue.main) - .sink(receiveValue: { [weak self] _ in - self?.search() - }) - .store(in: &cancellables) - } + + init() { } func fetchTrending() async { guard let client else { return } @@ -112,6 +103,7 @@ class ExploreViewModel: ObservableObject { searchTask = Task { guard let client else { return } do { + try await Task.sleep(for: .milliseconds(250)) var results: SearchResults = try await client.get(endpoint: Search.search(query: searchQuery, type: nil, offset: nil, diff --git a/Packages/Lists/Sources/Lists/AddAccounts/ListAddAccountView.swift b/Packages/Lists/Sources/Lists/AddAccounts/ListAddAccountView.swift index 2d4ccbbc..670da7ad 100644 --- a/Packages/Lists/Sources/Lists/AddAccounts/ListAddAccountView.swift +++ b/Packages/Lists/Sources/Lists/AddAccounts/ListAddAccountView.swift @@ -8,14 +8,14 @@ public struct ListAddAccountView: View { @Environment(\.dismiss) private var dismiss @Environment(Client.self) private var client @EnvironmentObject private var theme: Theme - @EnvironmentObject private var currentAccount: CurrentAccount - @StateObject private var viewModel: ListAddAccountViewModel + @Environment(CurrentAccount.self) private var currentAccount + @State private var viewModel: ListAddAccountViewModel @State private var isCreateListAlertPresented: Bool = false @State private var createListTitle: String = "" public init(account: Account) { - _viewModel = StateObject(wrappedValue: .init(account: account)) + _viewModel = .init(initialValue: .init(account: account)) } public var body: some View { diff --git a/Packages/Lists/Sources/Lists/AddAccounts/ListAddAccountViewModel.swift b/Packages/Lists/Sources/Lists/AddAccounts/ListAddAccountViewModel.swift index 910ae16a..451b3a3b 100644 --- a/Packages/Lists/Sources/Lists/AddAccounts/ListAddAccountViewModel.swift +++ b/Packages/Lists/Sources/Lists/AddAccounts/ListAddAccountViewModel.swift @@ -1,13 +1,14 @@ import Models import Network import SwiftUI +import Observation @MainActor -class ListAddAccountViewModel: ObservableObject { +@Observable class ListAddAccountViewModel { let account: Account - @Published var inLists: [Models.List] = [] - @Published var isLoadingInfo: Bool = true + var inLists: [Models.List] = [] + var isLoadingInfo: Bool = true var client: Client? diff --git a/Packages/Notifications/Sources/Notifications/NotificationsListView.swift b/Packages/Notifications/Sources/Notifications/NotificationsListView.swift index 37255c13..968cfa1b 100644 --- a/Packages/Notifications/Sources/Notifications/NotificationsListView.swift +++ b/Packages/Notifications/Sources/Notifications/NotificationsListView.swift @@ -11,7 +11,7 @@ public struct NotificationsListView: View { @Environment(StreamWatcher.self) private var watcher @Environment(Client.self) private var client @Environment(RouterPath.self) private var routerPath - @EnvironmentObject private var account: CurrentAccount + @Environment(CurrentAccount.self) private var account @StateObject private var viewModel = NotificationsViewModel() let lockedType: Models.Notification.NotificationType? diff --git a/Packages/Status/Sources/Status/Detail/StatusDetailView.swift b/Packages/Status/Sources/Status/Detail/StatusDetailView.swift index b9d394ab..012d04bd 100644 --- a/Packages/Status/Sources/Status/Detail/StatusDetailView.swift +++ b/Packages/Status/Sources/Status/Detail/StatusDetailView.swift @@ -7,7 +7,7 @@ import SwiftUI public struct StatusDetailView: View { @EnvironmentObject private var theme: Theme - @EnvironmentObject private var currentAccount: CurrentAccount + @Environment(CurrentAccount.self) private var currentAccount @Environment(StreamWatcher.self) private var watcher @Environment(Client.self) private var client @Environment(RouterPath.self) private var routerPath diff --git a/Packages/Status/Sources/Status/Editor/Components/StatusEditorAccessoryView.swift b/Packages/Status/Sources/Status/Editor/Components/StatusEditorAccessoryView.swift index b7e97738..0a3a4286 100644 --- a/Packages/Status/Sources/Status/Editor/Components/StatusEditorAccessoryView.swift +++ b/Packages/Status/Sources/Status/Editor/Components/StatusEditorAccessoryView.swift @@ -8,7 +8,7 @@ import SwiftUI struct StatusEditorAccessoryView: View { @EnvironmentObject private var preferences: UserPreferences @EnvironmentObject private var theme: Theme - @EnvironmentObject private var currentInstance: CurrentInstance + @Environment(CurrentInstance.self) private var currentInstance @Environment(\.colorScheme) private var colorScheme @FocusState.Binding var isSpoilerTextFocused: Bool diff --git a/Packages/Status/Sources/Status/Editor/Components/StatusEditorMediaEditView.swift b/Packages/Status/Sources/Status/Editor/Components/StatusEditorMediaEditView.swift index 5e626f13..b3c6dfac 100644 --- a/Packages/Status/Sources/Status/Editor/Components/StatusEditorMediaEditView.swift +++ b/Packages/Status/Sources/Status/Editor/Components/StatusEditorMediaEditView.swift @@ -7,7 +7,7 @@ import SwiftUI struct StatusEditorMediaEditView: View { @Environment(\.dismiss) private var dismiss @EnvironmentObject private var theme: Theme - @EnvironmentObject private var currentInstance: CurrentInstance + @Environment(CurrentInstance.self) private var currentInstance @ObservedObject var viewModel: StatusEditorViewModel let container: StatusEditorMediaContainer diff --git a/Packages/Status/Sources/Status/Editor/Components/StatusEditorMediaView.swift b/Packages/Status/Sources/Status/Editor/Components/StatusEditorMediaView.swift index 89315f40..b40c6438 100644 --- a/Packages/Status/Sources/Status/Editor/Components/StatusEditorMediaView.swift +++ b/Packages/Status/Sources/Status/Editor/Components/StatusEditorMediaView.swift @@ -7,7 +7,7 @@ import SwiftUI struct StatusEditorMediaView: View { @EnvironmentObject private var theme: Theme - @EnvironmentObject private var currentInstance: CurrentInstance + @Environment(CurrentInstance.self) private var currentInstance @ObservedObject var viewModel: StatusEditorViewModel @State private var editingContainer: StatusEditorMediaContainer? diff --git a/Packages/Status/Sources/Status/Editor/Components/StatusEditorPollView.swift b/Packages/Status/Sources/Status/Editor/Components/StatusEditorPollView.swift index 7cea6778..b7f60fef 100644 --- a/Packages/Status/Sources/Status/Editor/Components/StatusEditorPollView.swift +++ b/Packages/Status/Sources/Status/Editor/Components/StatusEditorPollView.swift @@ -12,7 +12,7 @@ struct StatusEditorPollView: View { @State private var currentFocusIndex: Int = 0 @EnvironmentObject private var theme: Theme - @EnvironmentObject private var currentInstance: CurrentInstance + @Environment(CurrentInstance.self) private var currentInstance @ObservedObject var viewModel: StatusEditorViewModel diff --git a/Packages/Status/Sources/Status/Editor/StatusEditorView.swift b/Packages/Status/Sources/Status/Editor/StatusEditorView.swift index 4f82bf46..63357ca7 100644 --- a/Packages/Status/Sources/Status/Editor/StatusEditorView.swift +++ b/Packages/Status/Sources/Status/Editor/StatusEditorView.swift @@ -16,7 +16,7 @@ public struct StatusEditorView: View { @EnvironmentObject private var preferences: UserPreferences @EnvironmentObject private var theme: Theme @Environment(Client.self) private var client - @EnvironmentObject private var currentAccount: CurrentAccount + @Environment(CurrentAccount.self) private var currentAccount @Environment(RouterPath.self) private var routerPath @Environment(\.dismiss) private var dismiss diff --git a/Packages/Status/Sources/Status/Poll/StatusPollView.swift b/Packages/Status/Sources/Status/Poll/StatusPollView.swift index 8974c2cd..a886e091 100644 --- a/Packages/Status/Sources/Status/Poll/StatusPollView.swift +++ b/Packages/Status/Sources/Status/Poll/StatusPollView.swift @@ -7,8 +7,8 @@ import SwiftUI public struct StatusPollView: View { @EnvironmentObject private var theme: Theme @Environment(Client.self) private var client - @EnvironmentObject private var currentInstance: CurrentInstance - @EnvironmentObject private var currentAccount: CurrentAccount + @Environment(CurrentInstance.self) private var currentInstance + @Environment(CurrentAccount.self) private var currentAccount @State private var viewModel: StatusPollViewModel diff --git a/Packages/Status/Sources/Status/Row/Subviews/StatusRowActionsView.swift b/Packages/Status/Sources/Status/Row/Subviews/StatusRowActionsView.swift index 5d3514c8..6b46e2ea 100644 --- a/Packages/Status/Sources/Status/Row/Subviews/StatusRowActionsView.swift +++ b/Packages/Status/Sources/Status/Row/Subviews/StatusRowActionsView.swift @@ -6,7 +6,7 @@ import SwiftUI struct StatusRowActionsView: View { @EnvironmentObject private var theme: Theme - @EnvironmentObject private var currentAccount: CurrentAccount + @Environment(CurrentAccount.self) private var currentAccount @EnvironmentObject private var statusDataController: StatusDataController @EnvironmentObject private var userPreferences: UserPreferences diff --git a/Packages/Status/Sources/Status/Row/Subviews/StatusRowContextMenu.swift b/Packages/Status/Sources/Status/Row/Subviews/StatusRowContextMenu.swift index 2f7c53eb..4203f711 100644 --- a/Packages/Status/Sources/Status/Row/Subviews/StatusRowContextMenu.swift +++ b/Packages/Status/Sources/Status/Row/Subviews/StatusRowContextMenu.swift @@ -10,8 +10,8 @@ struct StatusRowContextMenu: View { @Environment(Client.self) private var client @EnvironmentObject private var sceneDelegate: SceneDelegate @EnvironmentObject private var preferences: UserPreferences - @EnvironmentObject private var account: CurrentAccount - @EnvironmentObject private var currentInstance: CurrentInstance + @Environment(CurrentAccount.self) private var account + @Environment(CurrentInstance.self) private var currentInstance @EnvironmentObject private var statusDataController: StatusDataController var viewModel: StatusRowViewModel @@ -87,8 +87,8 @@ struct StatusRowContextMenu: View { .environment(\.isInCaptureMode, true) .environmentObject(Theme.shared) .environmentObject(preferences) - .environmentObject(account) - .environmentObject(currentInstance) + .environment(account) + .environment(currentInstance) .environmentObject(SceneDelegate()) .environmentObject(QuickLook()) .environment(viewModel.client) diff --git a/Packages/Status/Sources/Status/Row/Subviews/StatusRowSwipeView.swift b/Packages/Status/Sources/Status/Row/Subviews/StatusRowSwipeView.swift index 9dd66855..b028eaf5 100644 --- a/Packages/Status/Sources/Status/Row/Subviews/StatusRowSwipeView.swift +++ b/Packages/Status/Sources/Status/Row/Subviews/StatusRowSwipeView.swift @@ -6,7 +6,7 @@ import SwiftUI struct StatusRowSwipeView: View { @EnvironmentObject private var theme: Theme @EnvironmentObject private var preferences: UserPreferences - @EnvironmentObject private var currentAccount: CurrentAccount + @Environment(CurrentAccount.self) private var currentAccount @EnvironmentObject private var statusDataController: StatusDataController enum Mode { diff --git a/Packages/Timeline/Sources/Timeline/TimelineView.swift b/Packages/Timeline/Sources/Timeline/TimelineView.swift index aef0c305..6addfe3c 100644 --- a/Packages/Timeline/Sources/Timeline/TimelineView.swift +++ b/Packages/Timeline/Sources/Timeline/TimelineView.swift @@ -14,7 +14,7 @@ public struct TimelineView: View { @Environment(\.scenePhase) private var scenePhase @EnvironmentObject private var theme: Theme - @EnvironmentObject private var account: CurrentAccount + @Environment(CurrentAccount.self) private var account @Environment(StreamWatcher.self) private var watcher @Environment(Client.self) private var client @Environment(RouterPath.self) private var routerPath