Skip to content

Commit

Permalink
chore: Set files initial value to null
Browse files Browse the repository at this point in the history
  • Loading branch information
tevincent committed Dec 4, 2024
1 parent 11bc61d commit 568a6d3
Showing 1 changed file with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,26 @@ fun FilesDetailsScreen(
navigateBack: (() -> Unit),
) {
// If we don't have a folderUuid, it means we have to load files from importedFiles in ImportFilesViewModel
val files by importFilesViewModel.getFiles(folderUuid).collectAsStateWithLifecycle(emptyList())
val files by importFilesViewModel.getFiles(folderUuid).collectAsStateWithLifecycle(null)

if (files.isEmpty() == true) navigateBack()
if (files?.isEmpty() == true) navigateBack()

FilesDetailsScreen(
files = files,
navigateToDetails = navigateToDetails,
withFileSize = withFileSize,
withSpaceLeft = withSpaceLeft,
onFileRemoved = getOnFileRemoveCallback(withFileDelete, importFilesViewModel),
onCloseClicked = onCloseClicked,
navigateBack = navigateBack,
)
files?.let {
FilesDetailsScreen(
files = it,
navigateToDetails = navigateToDetails,
withFileSize = withFileSize,
withSpaceLeft = withSpaceLeft,
onFileRemoved = getOnFileRemoveCallback(importFilesViewModel, withFileDelete),
onCloseClicked = onCloseClicked,
navigateBack = navigateBack,
)
}
}

private fun getOnFileRemoveCallback(
withFileDelete: Boolean,
importFilesViewModel: ImportFilesViewModel,
withFileDelete: Boolean,
): ((String) -> Unit)? {
return if (withFileDelete) {
{ importFilesViewModel.removeFileByUid(it) }
Expand Down

0 comments on commit 568a6d3

Please sign in to comment.