Refactor ViewModel
This commit is contained in:
@@ -22,7 +22,7 @@
|
||||
@Environment(\.profileEditor) private var profileEditor
|
||||
|
||||
public var body: some View {
|
||||
viewBuilder {
|
||||
Group {
|
||||
if viewModel.isLoading {
|
||||
ProgressView().onAppear {
|
||||
Task {
|
||||
@@ -104,7 +104,7 @@
|
||||
|
||||
@ViewBuilder
|
||||
private var defaultEditorView: some View {
|
||||
viewBuilder {
|
||||
Group {
|
||||
if readOnly {
|
||||
TextEditor(text: .constant(viewModel.profileContent))
|
||||
} else {
|
||||
|
||||
@@ -4,17 +4,17 @@
|
||||
import SwiftUI
|
||||
|
||||
@MainActor
|
||||
public final class EditProfileContentViewModel: ObservableObject {
|
||||
@Published public var isLoading = true
|
||||
public final class EditProfileContentViewModel: BaseViewModel {
|
||||
@Published public var profile: Profile?
|
||||
@Published public var profileContent = ""
|
||||
@Published public var isChanged = false
|
||||
@Published public var alert: Alert?
|
||||
|
||||
private let profileID: Int64?
|
||||
|
||||
public init(profileID: Int64?) {
|
||||
self.profileID = profileID
|
||||
super.init()
|
||||
isLoading = true
|
||||
}
|
||||
|
||||
public func markAsChanged() {
|
||||
|
||||
@@ -3,15 +3,11 @@ import Library
|
||||
import SwiftUI
|
||||
|
||||
@MainActor
|
||||
public final class EditProfileViewModel: ObservableObject {
|
||||
@Published public var isLoading = false
|
||||
public final class EditProfileViewModel: BaseViewModel {
|
||||
@Published public var isChanged = false
|
||||
@Published public var alert: Alert?
|
||||
@Published public var shareLinkPresented = false
|
||||
@Published public var shareLinkText: String?
|
||||
|
||||
public init() {}
|
||||
|
||||
public func markAsChanged() {
|
||||
isChanged = true
|
||||
}
|
||||
|
||||
@@ -7,17 +7,13 @@
|
||||
import SwiftUI
|
||||
|
||||
@MainActor
|
||||
public final class ImportProfileViewModel: ObservableObject {
|
||||
@Published public var isLoading = false
|
||||
public final class ImportProfileViewModel: BaseViewModel {
|
||||
@Published public var selected = false
|
||||
@Published public var alert: Alert?
|
||||
@Published public var connection: NWConnection?
|
||||
@Published public var socket: NWSocket?
|
||||
@Published public var profiles: [LibboxProfilePreview]?
|
||||
@Published public var isImporting = false
|
||||
|
||||
public init() {}
|
||||
|
||||
public func reset() {
|
||||
if let connection {
|
||||
connection.stateUpdateHandler = nil
|
||||
|
||||
@@ -57,7 +57,7 @@ public struct NewProfileView: View {
|
||||
#if os(tvOS)
|
||||
.disabled(true)
|
||||
#endif
|
||||
viewBuilder {
|
||||
Group {
|
||||
if viewModel.fileImport {
|
||||
HStack {
|
||||
Text("File Path")
|
||||
|
||||
@@ -4,7 +4,7 @@ import Library
|
||||
import SwiftUI
|
||||
|
||||
@MainActor
|
||||
public final class NewProfileViewModel: ObservableObject {
|
||||
public final class NewProfileViewModel: BaseViewModel {
|
||||
@Published public var isSaving = false
|
||||
@Published public var profileName = ""
|
||||
#if !os(tvOS)
|
||||
@@ -18,9 +18,9 @@ public final class NewProfileViewModel: ObservableObject {
|
||||
@Published public var autoUpdate = true
|
||||
@Published public var autoUpdateInterval: Int32 = 60
|
||||
@Published public var pickerPresented = false
|
||||
@Published public var alert: Alert?
|
||||
|
||||
public init(importRequest: NewProfileView.ImportRequest? = nil) {
|
||||
super.init()
|
||||
if let importRequest {
|
||||
profileName = importRequest.name
|
||||
profileType = .remote
|
||||
|
||||
@@ -67,7 +67,7 @@ public struct ProfileView: View {
|
||||
} else {
|
||||
List {
|
||||
ForEach(viewModel.profileList, id: \.id) { profile in
|
||||
viewBuilder {
|
||||
Group {
|
||||
#if os(iOS) || os(tvOS)
|
||||
if viewModel.editMode.isEditing == true {
|
||||
Text(profile.name)
|
||||
@@ -182,7 +182,7 @@ public struct ProfileView: View {
|
||||
}
|
||||
|
||||
private var draggableBody: some View {
|
||||
viewBuilder {
|
||||
Group {
|
||||
#if !os(macOS)
|
||||
FormNavigationLink {
|
||||
EditProfileView().environmentObject(profile.origin)
|
||||
|
||||
@@ -4,12 +4,10 @@ import Library
|
||||
import SwiftUI
|
||||
|
||||
@MainActor
|
||||
public class ProfileViewModel: ObservableObject {
|
||||
public class ProfileViewModel: BaseViewModel {
|
||||
@Published public var importRemoteProfileRequest: NewProfileView.ImportRequest?
|
||||
@Published public var importRemoteProfilePresented = false
|
||||
@Published public var isLoading = true
|
||||
@Published public var isUpdating = false
|
||||
@Published public var alert: Alert?
|
||||
@Published public var profileList: [ProfilePreview] = []
|
||||
|
||||
#if os(iOS) || os(tvOS)
|
||||
@@ -18,7 +16,10 @@ public class ProfileViewModel: ObservableObject {
|
||||
|
||||
private weak var environments: ExtensionEnvironments?
|
||||
|
||||
public init() {}
|
||||
public override init() {
|
||||
super.init()
|
||||
isLoading = true
|
||||
}
|
||||
|
||||
public func setEnvironments(_ environments: ExtensionEnvironments) {
|
||||
self.environments = environments
|
||||
|
||||
Reference in New Issue
Block a user