Fix migration dialog migrating to wrong entry (#2631)

This commit is contained in:
AntsyLich
2025-11-01 01:21:29 +06:00
committed by GitHub
parent 343074da5f
commit 5e7fecc2c1
2 changed files with 26 additions and 8 deletions

View File

@@ -26,7 +26,8 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co
- Fix migration progress not updating after manual search ([@Secozzi](https://github.com/Secozzi)) ([#2484](https://github.com/mihonapp/mihon/pull/2484)) - Fix migration progress not updating after manual search ([@Secozzi](https://github.com/Secozzi)) ([#2484](https://github.com/mihonapp/mihon/pull/2484))
- Fix category migration flag being ignored due to incorrect check against chapter flag ([@Secozzi](https://github.com/Secozzi)) ([#2484](https://github.com/mihonapp/mihon/pull/2484)) - Fix category migration flag being ignored due to incorrect check against chapter flag ([@Secozzi](https://github.com/Secozzi)) ([#2484](https://github.com/mihonapp/mihon/pull/2484))
- Fix disabling incognito mode from notification ([@NGB-Was-Taken](https://github.com/NGB-Was-Taken)) ([#2512](https://github.com/mihonapp/mihon/pull/2512)) - Fix disabling incognito mode from notification ([@NGB-Was-Taken](https://github.com/NGB-Was-Taken)) ([#2512](https://github.com/mihonapp/mihon/pull/2512))
- Fix mass migration advanced search query building ([@AntsyLich](https://github.com/AntsyLich)) ([#2629](https://github.com/mihonapp/mihon/pull/22629)) - Fix mass migration advanced search query building ([@AntsyLich](https://github.com/AntsyLich)) ([#2629](https://github.com/mihonapp/mihon/pull/2629))
- Fix migration dialog migrating to wrong entry ([@AntsyLich](https://github.com/AntsyLich)) ([#2631](https://github.com/mihonapp/mihon/pull/2631))
### Other ### Other
- Fix Kitsu tracker to conform to tracker data structure properly ([@cpiber](https://github.com/cpiber)) ([#2609](https://github.com/mihonapp/mihon/pull/2609)) - Fix Kitsu tracker to conform to tracker data structure properly ([@cpiber](https://github.com/cpiber)) ([#2609](https://github.com/mihonapp/mihon/pull/2609))

View File

@@ -12,6 +12,7 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.material3.TextButton import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.rememberCoroutineScope
@@ -49,9 +50,14 @@ internal fun Screen.MigrateMangaDialog(
) { ) {
val scope = rememberCoroutineScope() val scope = rememberCoroutineScope()
val screenModel = rememberScreenModel { MigrateDialogScreenModel(current, target) } val screenModel = rememberScreenModel { MigrateDialogScreenModel() }
LaunchedEffect(current, target) {
screenModel.init(current, target)
}
val state by screenModel.state.collectAsState() val state by screenModel.state.collectAsState()
if (state.isMigrated) return
if (state.isMigrating) { if (state.isMigrating) {
LoadingScreen( LoadingScreen(
modifier = Modifier.background(MaterialTheme.colorScheme.background.copy(alpha = 0.7f)), modifier = Modifier.background(MaterialTheme.colorScheme.background.copy(alpha = 0.7f)),
@@ -118,15 +124,13 @@ internal fun Screen.MigrateMangaDialog(
} }
private class MigrateDialogScreenModel( private class MigrateDialogScreenModel(
private val current: Manga,
private val target: Manga,
private val sourcePreference: SourcePreferences = Injekt.get(), private val sourcePreference: SourcePreferences = Injekt.get(),
private val coverCache: CoverCache = Injekt.get(), private val coverCache: CoverCache = Injekt.get(),
private val downloadManager: DownloadManager = Injekt.get(), private val downloadManager: DownloadManager = Injekt.get(),
private val migrateManga: MigrateMangaUseCase = Injekt.get(), private val migrateManga: MigrateMangaUseCase = Injekt.get(),
) : StateScreenModel<MigrateDialogScreenModel.State>(State()) { ) : StateScreenModel<MigrateDialogScreenModel.State>(State()) {
init { fun init(current: Manga, target: Manga) {
val applicableFlags = buildList { val applicableFlags = buildList {
MigrationFlag.entries.forEach { MigrationFlag.entries.forEach {
val applicable = when (it) { val applicable = when (it) {
@@ -140,7 +144,14 @@ private class MigrateDialogScreenModel(
} }
} }
val selectedFlags = sourcePreference.migrationFlags().get() val selectedFlags = sourcePreference.migrationFlags().get()
mutableState.update { it.copy(applicableFlags = applicableFlags, selectedFlags = selectedFlags) } mutableState.update {
it.copy(
current = current,
target = target,
applicableFlags = applicableFlags,
selectedFlags = selectedFlags,
)
}
} }
fun toggleSelection(flag: MigrationFlag) { fun toggleSelection(flag: MigrationFlag) {
@@ -153,15 +164,21 @@ private class MigrateDialogScreenModel(
} }
suspend fun migrateManga(replace: Boolean) { suspend fun migrateManga(replace: Boolean) {
sourcePreference.migrationFlags().set(state.value.selectedFlags) val state = state.value
val current = state.current ?: return
val target = state.target ?: return
sourcePreference.migrationFlags().set(state.selectedFlags)
mutableState.update { it.copy(isMigrating = true) } mutableState.update { it.copy(isMigrating = true) }
migrateManga(current, target, replace) migrateManga(current, target, replace)
mutableState.update { it.copy(isMigrating = false) } mutableState.update { it.copy(isMigrating = false, isMigrated = true) }
} }
data class State( data class State(
val current: Manga? = null,
val target: Manga? = null,
val applicableFlags: List<MigrationFlag> = emptyList(), val applicableFlags: List<MigrationFlag> = emptyList(),
val selectedFlags: Set<MigrationFlag> = emptySet(), val selectedFlags: Set<MigrationFlag> = emptySet(),
val isMigrating: Boolean = false, val isMigrating: Boolean = false,
val isMigrated: Boolean = false,
) )
} }