Refactor to MVVM architecture

This commit is contained in:
世界
2025-11-26 22:25:48 +08:00
parent 61f1036f57
commit b71cbae382
31 changed files with 1551 additions and 1229 deletions
@@ -0,0 +1,60 @@
import Libbox
import Library
import SwiftUI
@MainActor
public final class EditProfileViewModel: ObservableObject {
@Published public var isLoading = false
@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
}
public func updateProfile(_ profile: Profile, environments: ExtensionEnvironments) async {
defer {
isLoading = false
}
do {
try await Task.sleep(nanoseconds: UInt64(100 * Double(NSEC_PER_MSEC)))
try await profile.updateRemoteProfile()
environments.profileUpdate.send()
} catch {
alert = Alert(error)
}
}
public func deleteProfile(_ profile: Profile, environments: ExtensionEnvironments, dismiss: DismissAction) async {
do {
try await ProfileManager.delete(profile)
} catch {
alert = Alert(error)
return
}
environments.profileUpdate.send()
dismiss()
}
public func saveProfile(_ profile: Profile, environments: ExtensionEnvironments) async {
do {
_ = try await ProfileManager.update(profile)
#if os(iOS) || os(tvOS)
try UIProfileUpdateTask.configure()
#else
try await ProfileUpdateTask.configure()
#endif
try await profile.onProfileUpdated()
} catch {
alert = Alert(error)
return
}
isChanged = false
isLoading = false
environments.profileUpdate.send()
}
}