fix: scope import ViewModel per-uri so a second import re-parses
ImportScreen has no nav backstack, so an unkeyed hiltViewModel() resolved to the Activity's ViewModelStore and was retained across imports. Its one-shot `load` guard then showed the *previous* file's parsed state on the next import — trivially reachable now that the in-app Restore button lets you export→restore or restore twice in one session (worst case: the picker still holds file A, so tapping Import writes A's events after you picked B). Keying the VM by the file uri hands each distinct file a fresh VM (fresh Loading state); the same uri (rotation) reuses it and holds the result. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -75,7 +75,13 @@ fun ImportScreen(
|
|||||||
onClose: () -> Unit,
|
onClose: () -> Unit,
|
||||||
onOpenSingle: (EventForm) -> Unit,
|
onOpenSingle: (EventForm) -> Unit,
|
||||||
forceMany: Boolean = false,
|
forceMany: Boolean = false,
|
||||||
viewModel: ImportViewModel = hiltViewModel(),
|
// Key the VM by the file uri. This screen has no nav backstack, so an
|
||||||
|
// unkeyed hiltViewModel() resolves to the Activity's store and is retained
|
||||||
|
// across imports — its one-shot `load` guard would then show the *previous*
|
||||||
|
// file's parsed state on the next import (a second restore, export→restore,
|
||||||
|
// etc.). Keying per uri hands each distinct file a fresh VM (fresh Loading
|
||||||
|
// state), while the same uri (rotation) reuses it and holds the result.
|
||||||
|
viewModel: ImportViewModel = hiltViewModel(key = uri.toString()),
|
||||||
) {
|
) {
|
||||||
LaunchedEffect(uri) { viewModel.load(uri, forceMany) }
|
LaunchedEffect(uri) { viewModel.load(uri, forceMany) }
|
||||||
val state by viewModel.state.collectAsStateWithLifecycle()
|
val state by viewModel.state.collectAsStateWithLifecycle()
|
||||||
|
|||||||
Reference in New Issue
Block a user