mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-12 12:08:56 +01:00
Add button to reorder categories alphabetically (#9369)
Closes #6459 Co-authored-by: arkon <arkon@users.noreply.github.com>
This commit is contained in:
@@ -12,6 +12,7 @@ import eu.kanade.presentation.category.CategoryScreen
|
||||
import eu.kanade.presentation.category.components.CategoryCreateDialog
|
||||
import eu.kanade.presentation.category.components.CategoryDeleteDialog
|
||||
import eu.kanade.presentation.category.components.CategoryRenameDialog
|
||||
import eu.kanade.presentation.category.components.CategorySortAlphabeticallyDialog
|
||||
import eu.kanade.presentation.util.Screen
|
||||
import eu.kanade.tachiyomi.util.system.toast
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
@@ -37,6 +38,7 @@ class CategoryScreen : Screen() {
|
||||
CategoryScreen(
|
||||
state = successState,
|
||||
onClickCreate = { screenModel.showDialog(CategoryDialog.Create) },
|
||||
onClickSortAlphabetically = { screenModel.showDialog(CategoryDialog.SortAlphabetically) },
|
||||
onClickRename = { screenModel.showDialog(CategoryDialog.Rename(it)) },
|
||||
onClickDelete = { screenModel.showDialog(CategoryDialog.Delete(it)) },
|
||||
onClickMoveUp = screenModel::moveUp,
|
||||
@@ -68,6 +70,12 @@ class CategoryScreen : Screen() {
|
||||
category = dialog.category,
|
||||
)
|
||||
}
|
||||
is CategoryDialog.SortAlphabetically -> {
|
||||
CategorySortAlphabeticallyDialog(
|
||||
onDismissRequest = screenModel::dismissDialog,
|
||||
onSort = { screenModel.sortAlphabetically() },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
|
||||
@@ -61,6 +61,15 @@ class CategoryScreenModel(
|
||||
}
|
||||
}
|
||||
|
||||
fun sortAlphabetically() {
|
||||
coroutineScope.launch {
|
||||
when (reorderCategory.sortAlphabetically()) {
|
||||
is ReorderCategory.Result.InternalError -> _events.send(CategoryEvent.InternalError)
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun moveUp(category: Category) {
|
||||
coroutineScope.launch {
|
||||
when (reorderCategory.moveUp(category)) {
|
||||
@@ -109,6 +118,7 @@ class CategoryScreenModel(
|
||||
|
||||
sealed interface CategoryDialog {
|
||||
data object Create : CategoryDialog
|
||||
data object SortAlphabetically : CategoryDialog
|
||||
data class Rename(val category: Category) : CategoryDialog
|
||||
data class Delete(val category: Category) : CategoryDialog
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user