Skip to content

Commit

Permalink
Merge pull request #1295 from Infomaniak/fix-empty-state
Browse files Browse the repository at this point in the history
fix: Correctly observe parent directory for empty files
  • Loading branch information
PhilippeWeidmann authored Sep 20, 2024
2 parents 20e1838 + 12d40b0 commit f2a2c51
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion kDrive/UI/Controller/Files/File List/FileListViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class FileListViewModel: SelectDelegate {
}

var realmObservationToken: NotificationToken?
var currentDirectoryObservationToken: NotificationToken?

var currentDirectory: File
var driveFileManager: DriveFileManager {
Expand Down Expand Up @@ -226,10 +227,28 @@ class FileListViewModel: SelectDelegate {
files = resultFiles
isShowingEmptyView = shouldShowEmptyView()
}

currentDirectoryObservationToken?.invalidate()
guard currentDirectory.isManagedByRealm,
!currentDirectory.isInvalidated,
let liveCurrentDirectory = currentDirectory.thaw() else { return }
currentDirectoryObservationToken = liveCurrentDirectory
.observe(keyPaths: ["lastCursor", "fullyDownloaded"],
on: .main) { [weak self] change in
guard let self else { return }

switch change {
case .change:
currentDirectory = getRefreshedCurrentDirectory()
isShowingEmptyView = shouldShowEmptyView()
default:
break
}
}
}

func shouldShowEmptyView() -> Bool {
currentDirectory.children.isEmpty && currentDirectory.fullyDownloaded
files.isEmpty && currentDirectory.fullyDownloaded
}

func startObservation() {
Expand Down

0 comments on commit f2a2c51

Please sign in to comment.