diff --git a/src/Titano.App/Sections/ArchiveViewModel.cs b/src/Titano.App/Sections/ArchiveViewModel.cs index e5b9e3c4..1384779f 100644 --- a/src/Titano.App/Sections/ArchiveViewModel.cs +++ b/src/Titano.App/Sections/ArchiveViewModel.cs @@ -135,19 +135,7 @@ public sealed class ArchiveViewModel : SectionViewModel _archive = value; _duplicates = null; _orphans = null; - if (other) - { - // Until the picked archive is read (IsRead), nothing of the previous one stays actionable: no tree to take - // a set from, no availability to allow a scan, no figures for the rebuild dialog or the health fixes, no - // search results. The tooltips say the archive is being read. - _search?.Cancel(); - _tree = null; - _stats = null; - _health = []; - RebuildRows(); - OnPropertyChanged(string.Empty); - CommandManager.InvalidateRequerySuggested(); - } + if (other) ForgetRead(); _ = LoadAsync(); } } @@ -430,8 +418,11 @@ public sealed class ArchiveViewModel : SectionViewModel { AttachJobEvents(); Archives = await db.Archives.ListAsync(); - _archive = _archive is { } current ? Archives.FirstOrDefault(a => a.Id == current.Id) : null; + var shown = _archive; + _archive = shown is { } current ? Archives.FirstOrDefault(a => a.Id == current.Id) : null; _archive ??= CurrentArchive.Pick(Archives, Services.Settings.LastArchivePath); + // The archive shown is gone from the index: another one (or none) takes its place, without its figures. + if (shown is not null && _archive?.Id != shown.Id) ForgetRead(); if (_archive is not { } archive) return; var root = archive.RootPath; var availability = await Task.Run(() => ArchiveVolume.Probe(new ArchivePaths(root))); @@ -459,6 +450,35 @@ public sealed class ArchiveViewModel : SectionViewModel } } + /// + /// Another archive is shown: until it is read (IsRead), nothing of the previous one stays actionable or on screen. No + /// tree to take a set from, no availability to allow a scan, no figures for the rebuild dialog or the health fixes, + /// no search results, and none of its tiles, charts, last scan, recent runs or rail badge under the new archive's + /// name, which a slow or failed read would leave there. The tooltips say the archive is being read. + /// + private void ForgetRead() + { + _search?.Cancel(); + _duplicates = null; + _orphans = null; + _tree = null; + _sequenceIds = []; + _stats = null; + _withoutProxies = 0; + _health = []; + _tiles = []; + _months = []; + _storage = []; + _cameras = []; + _formats = []; + _recent = []; + _lastScanText = string.Empty; + Badge = 0; + RebuildRows(); + OnPropertyChanged(string.Empty); + CommandManager.InvalidateRequerySuggested(); + } + /// Opens the rebuild dialog (BRIEF ยง12.5) and counts, off the UI thread, the sidecars the rebuild will read. public async Task OpenRebuildDialogAsync() { diff --git a/tests/Titano.App.Tests/Archive/ArchiveScreenSmokeTests.cs b/tests/Titano.App.Tests/Archive/ArchiveScreenSmokeTests.cs index 54984448..c201a746 100644 --- a/tests/Titano.App.Tests/Archive/ArchiveScreenSmokeTests.cs +++ b/tests/Titano.App.Tests/Archive/ArchiveScreenSmokeTests.cs @@ -182,11 +182,23 @@ public sealed class ArchiveScreenSmokeTests var archive = app.Shell.Archive; await ArchiveScenes.ShowAsync(app.Shell, "overview"); Assert.Contains(archive.TreeRows, r => r.Node.Kind == TreeNodeKind.Sequence); + Assert.NotEmpty(archive.Tiles); + Assert.NotEmpty(archive.CameraBars); var second = await app.Services.Archives!.CreateAsync(Path.Combine(app.Services.Environment.DataDirectory, "second-archive"), "Second"); var reading = archive.LoadAsync(); archive.SelectedArchive = second; Assert.Empty(archive.TreeRows); + // None of the first archive's figures stays on screen under the picked one's name while it is read (or if its read fails). + Assert.Empty(archive.Tiles); + Assert.Empty(archive.MonthRows); + Assert.Empty(archive.StorageBars); + Assert.Empty(archive.CameraBars); + Assert.Empty(archive.FormatBars); + Assert.Empty(archive.Recent); + Assert.False(archive.HasRecent); + Assert.Equal(string.Empty, archive.LastScanText); + Assert.Equal(0, archive.Badge, "the rail badge counts the picked archive's health, which is not read yet"); Assert.False(archive.AnalyseSetCommand.CanExecute(null), "nothing of the first archive can be acted on while the picked one is read"); Assert.False(archive.ScanCommand.CanExecute(null), "the picked archive is not known to be online yet"); Assert.Equal(Loc.L("Archive.Blocked.Reading"), archive.ScanToolTip, "not yet read is not offline");