fix(archive): clear the previous archive's figures when another is shown

Picking another archive, or the shown one leaving the index, now also
clears the previous archive's tiles, charts, last scan, recent runs and
rail badge until the new one is read, so a slow probe or a failed read
never shows them under the new archive's name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-12 15:53:58 +00:00
1 parent 5cf918ed66
commit 14bf5e753a
2 files changed
+46 -14

No files matched your search

+34 -14
View File
@@ -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
}
}
/// <summary>
/// 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.
/// </summary>
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();
}
/// <summary>Opens the rebuild dialog (BRIEF §12.5) and counts, off the UI thread, the sidecars the rebuild will read.</summary>
public async Task<RebuildDialogViewModel?> OpenRebuildDialogAsync()
{
@@ -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");