fix: retaining custom sort type after navigation (#424)

This commit is contained in:
Diego Beraldin 2024-01-06 11:20:35 +01:00 committed by GitHub
parent 4e966da936
commit 4c7f4282c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 4 deletions

View File

@ -87,7 +87,6 @@ class CommunityDetailViewModel(
blurNsfw = settings.blurNsfw,
swipeActionsEnabled = settings.enableSwipeActions,
doubleTapActionEnabled = settings.enableDoubleTapAction,
sortType = settings.defaultPostSortType.toSortType(),
fullHeightImages = settings.fullHeightImages,
voteFormat = settings.voteFormat,
autoLoadImages = settings.autoLoadImages,
@ -148,6 +147,9 @@ class CommunityDetailViewModel(
mvi.updateState { it.copy(currentUserId = user?.id ?: 0) }
}
if (mvi.uiState.value.posts.isEmpty()) {
val defaultPostSortType =
settingsRepository.currentSettings.value.defaultPostSortType
mvi.updateState { it.copy(sortType = defaultPostSortType.toSortType()) }
refresh()
}
}

View File

@ -102,7 +102,6 @@ class PostDetailViewModel(
it.copy(
swipeActionsEnabled = settings.enableSwipeActions,
doubleTapActionEnabled = settings.enableDoubleTapAction,
sortType = settings.defaultCommentSortType.toSortType(),
voteFormat = settings.voteFormat,
autoLoadImages = settings.autoLoadImages,
fullHeightImages = settings.fullHeightImages,
@ -183,7 +182,14 @@ class PostDetailViewModel(
if (mvi.uiState.value.comments.isEmpty()) {
val sortTypes =
getSortTypesUseCase.getTypesForComments(otherInstance = otherInstance)
mvi.updateState { it.copy(availableSortTypes = sortTypes) }
val defaultCommentSortType =
settingsRepository.currentSettings.value.defaultCommentSortType.toSortType()
mvi.updateState {
it.copy(
sortType = defaultCommentSortType,
availableSortTypes = sortTypes,
)
}
refresh()
}
}

View File

@ -93,7 +93,6 @@ class UserDetailViewModel(
blurNsfw = settings.blurNsfw,
swipeActionsEnabled = settings.enableSwipeActions,
doubleTapActionEnabled = settings.enableDoubleTapAction,
sortType = settings.defaultPostSortType.toSortType(),
voteFormat = settings.voteFormat,
autoLoadImages = settings.autoLoadImages,
fullHeightImages = settings.fullHeightImages,
@ -115,6 +114,10 @@ class UserDetailViewModel(
}
if (uiState.value.posts.isEmpty()) {
val defaultPostSortType =
settingsRepository.currentSettings.value.defaultPostSortType
mvi.updateState { it.copy(sortType = defaultPostSortType.toSortType()) }
withContext(Dispatchers.IO) {
refresh(initial = true)
}