Refactor ViewModel
This commit is contained in:
@@ -7,7 +7,7 @@ import SwiftUI
|
||||
@Environment(\.scenePhase) private var scenePhase
|
||||
@EnvironmentObject private var environments: ExtensionEnvironments
|
||||
@EnvironmentObject private var profile: ExtensionProfile
|
||||
@StateObject private var coordinator = DashboardCoordinator()
|
||||
@StateObject private var coordinator = DashboardViewModel()
|
||||
@State private var cardConfigurationVersion = 0
|
||||
#if os(iOS) || os(tvOS)
|
||||
@State private var showCardManagement = false
|
||||
|
||||
@@ -25,7 +25,7 @@ public struct ExtensionStatusView: View {
|
||||
}
|
||||
|
||||
public var body0: some View {
|
||||
viewBuilder {
|
||||
Group {
|
||||
VStack {
|
||||
LazyVGrid(columns: Array(repeating: GridItem(.flexible()), count: columnCount), alignment: .leading) {
|
||||
if ApplicationLibrary.inPreview {
|
||||
|
||||
@@ -9,7 +9,7 @@ public struct StartStopButton: View {
|
||||
public init() {}
|
||||
|
||||
public var body: some View {
|
||||
viewBuilder {
|
||||
Group {
|
||||
if ApplicationLibrary.inPreview {
|
||||
Button {} label: {
|
||||
#if os(tvOS)
|
||||
|
||||
@@ -52,7 +52,7 @@ public extension DashboardPage {
|
||||
|
||||
@MainActor
|
||||
func contentView(_ profileList: Binding<[ProfilePreview]>, _ selectedProfileID: Binding<Int64>, _ systemProxyAvailable: Binding<Bool>, _ systemProxyEnabled: Binding<Bool>, _ cardConfigurationVersion: Int) -> some View {
|
||||
viewBuilder {
|
||||
Group {
|
||||
switch self {
|
||||
case .overview:
|
||||
OverviewView(profileList, selectedProfileID, systemProxyAvailable, systemProxyEnabled, cardConfigurationVersion: cardConfigurationVersion)
|
||||
|
||||
@@ -9,7 +9,7 @@ public struct DashboardView: View {
|
||||
@Environment(\.importProfile) private var importProfile
|
||||
@Environment(\.importRemoteProfile) private var importRemoteProfile
|
||||
@EnvironmentObject private var environments: ExtensionEnvironments
|
||||
@StateObject private var coordinator = DashboardCoordinator()
|
||||
@StateObject private var coordinator = DashboardViewModel()
|
||||
@State private var importRemoteProfileRequest: NewProfileView.ImportRequest?
|
||||
|
||||
#if os(macOS)
|
||||
|
||||
+5
-4
@@ -5,11 +5,9 @@ import NetworkExtension
|
||||
import SwiftUI
|
||||
|
||||
@MainActor
|
||||
public final class DashboardCoordinator: ObservableObject {
|
||||
@Published public var isLoading = true
|
||||
public final class DashboardViewModel: BaseViewModel {
|
||||
@Published public var profileList: [ProfilePreview] = []
|
||||
@Published public var selectedProfileID: Int64 = 0
|
||||
@Published public var alert: Alert?
|
||||
@Published public var selection = DashboardPage.overview
|
||||
@Published public var systemProxyAvailable = false
|
||||
@Published public var systemProxyEnabled = false
|
||||
@@ -22,7 +20,10 @@ public final class DashboardCoordinator: ObservableObject {
|
||||
public var onEmptyProfilesChange: ((Bool) -> Void)?
|
||||
private var openURL: ((URL) -> Void)?
|
||||
|
||||
public init() {}
|
||||
public override init() {
|
||||
super.init()
|
||||
isLoading = true
|
||||
}
|
||||
|
||||
public func setOpenURL(_ openURL: @escaping (URL) -> Void) {
|
||||
self.openURL = openURL
|
||||
@@ -7,7 +7,7 @@ import SwiftUI
|
||||
public struct OverviewView: View {
|
||||
@EnvironmentObject private var environments: ExtensionEnvironments
|
||||
@EnvironmentObject private var profile: ExtensionProfile
|
||||
@StateObject private var coordinator = OverviewCoordinator()
|
||||
@StateObject private var coordinator = OverviewViewModel()
|
||||
@StateObject private var configuration = DashboardCardConfiguration()
|
||||
|
||||
@Binding private var profileList: [ProfilePreview]
|
||||
|
||||
+1
-4
@@ -4,12 +4,9 @@ import Library
|
||||
import SwiftUI
|
||||
|
||||
@MainActor
|
||||
public final class OverviewCoordinator: ObservableObject {
|
||||
@Published public var alert: Alert?
|
||||
public final class OverviewViewModel: BaseViewModel {
|
||||
@Published public var reasserting = false
|
||||
|
||||
public init() {}
|
||||
|
||||
public func switchProfile(_ profileID: Int64, profile: ExtensionProfile, environments: ExtensionEnvironments) async {
|
||||
await SharedPreferences.selectedProfileID.set(profileID)
|
||||
environments.selectedProfileUpdate.send()
|
||||
Reference in New Issue
Block a user