Bug fixes

This commit is contained in:
2025-03-19 01:55:58 -06:00
parent 292180b204
commit bbad8d6948
5 changed files with 195 additions and 166 deletions

View File

@ -31,6 +31,47 @@ class PDSViewModel: ObservableObject {
pdsService.inviteCodes
}
// Add listeners for PDSService changes
init() {
// Subscribe to PDSService objectWillChange events
pdsService.objectWillChange.sink { [weak self] _ in
// Forward the change notification to our own objectWillChange
DispatchQueue.main.async {
self?.objectWillChange.send()
}
}
.store(in: &cancellables)
}
// Storage for cancellables
private var cancellables = Set<AnyCancellable>()
// Method to manually refresh UI data
func refreshUI() {
DispatchQueue.main.async {
self.objectWillChange.send()
}
}
// Refresh invite codes with UI update
func refreshInviteCodes() async {
await pdsService.fetchInviteCodes()
refreshUI()
}
// Refresh users with UI update
func refreshUsers() async {
await pdsService.fetchUsers()
refreshUI()
}
// Disable invite code with guaranteed UI update
func disableInviteCode(_ code: String) async -> Bool {
let result = await pdsService.disableInviteCode(code)
refreshUI()
return result
}
func login(serverURL: String, username: String, password: String) async {
print("PDSViewModel: login called")
if let credentials = PDSCredentials(serverURL: serverURL, username: username, password: password) {