mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-11-04 08:08:55 +01:00 
			
		
		
		
	Use actual indexes instead of existing order number when reordering categories
Fixes #8738
This commit is contained in:
		@@ -28,26 +28,26 @@ class ReorderCategory(
 | 
			
		||||
                .filterNot(Category::isSystemCategory)
 | 
			
		||||
                .toMutableList()
 | 
			
		||||
 | 
			
		||||
            val newPosition = when (moveTo) {
 | 
			
		||||
                MoveTo.UP -> category.order - 1
 | 
			
		||||
                MoveTo.DOWN -> category.order + 1
 | 
			
		||||
            }.toInt()
 | 
			
		||||
 | 
			
		||||
            val currentIndex = categories.indexOfFirst { it.id == category.id }
 | 
			
		||||
            if (currentIndex == newPosition) {
 | 
			
		||||
            if (currentIndex == -1) {
 | 
			
		||||
                return@withNonCancellableContext Result.Unchanged
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            Collections.swap(categories, currentIndex, newPosition)
 | 
			
		||||
 | 
			
		||||
            val updates = categories.mapIndexed { index, category ->
 | 
			
		||||
                CategoryUpdate(
 | 
			
		||||
                    id = category.id,
 | 
			
		||||
                    order = index.toLong(),
 | 
			
		||||
                )
 | 
			
		||||
            }
 | 
			
		||||
            val newPosition = when (moveTo) {
 | 
			
		||||
                MoveTo.UP -> currentIndex - 1
 | 
			
		||||
                MoveTo.DOWN -> currentIndex + 1
 | 
			
		||||
            }.toInt()
 | 
			
		||||
 | 
			
		||||
            try {
 | 
			
		||||
                Collections.swap(categories, currentIndex, newPosition)
 | 
			
		||||
 | 
			
		||||
                val updates = categories.mapIndexed { index, category ->
 | 
			
		||||
                    CategoryUpdate(
 | 
			
		||||
                        id = category.id,
 | 
			
		||||
                        order = index.toLong(),
 | 
			
		||||
                    )
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                categoryRepository.updatePartial(updates)
 | 
			
		||||
                Result.Success
 | 
			
		||||
            } catch (e: Exception) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user