Files
Chronos/src/Titano.App/Import/ImportScenes.cs
T
Claude 29c82eba5c fix(app): import gates, partial results and plan editing after review
- a card that leaves needs a new check; formatting re-lists the card and refuses
  one that changed since its check; files that are not photos are named in the
  format confirmation
- an import never stays stuck in Running; Retry never resumes an older job
- server imports list refused files and keep what was uploaded when stopped
- the archive result matches each copy to its job's record and shows the job's
  own error per file
- refreshing devices keeps typed titles and choices; titles lock while copying
- three destination names, merge and split of sessions, camera profiles shared
  by the cards of a camera, photo counts and a new-card toast
- disabled controls say why; keyboard focus follows the nickname field and
  Show plan (Esc closes it); label column fits longer languages
- capture states for insertion, running, failed and a new card

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
2026-10-03 10:44:22 +00:00

93 lines
4.2 KiB
C#

using Titano.App.Sections;
using Titano.App.Shell;
using Titano.Core.Import;
using Titano.Core.Localization;
using Titano.Data;
namespace Titano.App.Import;
/// <summary>
/// The Import states that <c>--capture</c> renders (<c>import-&lt;state&gt;-&lt;theme&gt;.png</c>) and the screen smoke
/// tests check, on the cards of <see cref="SampleCards"/>: the card just inserted (with its toast) and its plan and
/// sessions, "Show plan", the import copying, an import that stopped, the verification result with the after-import
/// actions, and a card seen for the first time (its nickname field and toast). The caller dismisses toasts before each
/// state, and after it unless <see cref="ShowsToast"/>.
/// </summary>
public static class ImportScenes
{
public static readonly IReadOnlyList<string> States = ["inserted", "plan", "showplan", "running", "failed", "done", "newcard"];
/// <summary>States that show a toast on purpose (the insertion toasts); the caller dismisses the others' toasts.</summary>
public static bool ShowsToast(string state) => state is "inserted" or "newcard";
public static async Task ShowAsync(ShellViewModel shell, string state)
{
var import = shell.Import;
var data = shell.Services.Environment.DataDirectory;
shell.Navigate(SectionKey.Import);
switch (state)
{
case "inserted":
await ShowPlanAsync(import, SampleCards.Card(data));
await import.CardInsertedAsync(SampleCards.Card(data));
break;
case "plan":
await ShowPlanAsync(import, SampleCards.Card(data));
break;
case "showplan":
import.ShowPlanCommand.Execute(null);
break;
case "running":
import.CloseDetailsCommand.Execute(null);
var plan = Plan(import);
import.ShowRunning(new ImportProgress(31, plan.FileCount, plan.CopyBytes * 31 / plan.FileCount, plan.CopyBytes, 31, 0, 0, null));
break;
case "failed":
import.ShowFailed(Loc.L("Archive.Error.SourceGone", SampleCards.Card(data).Root));
break;
case "done":
await ShowPlanAsync(import, SampleCards.Card(data));
import.DeleteImported = true;
var done = Plan(import);
var card = SampleCards.Card(data);
import.ShowResult(SampleCards.Outcome(done)).ShowErase(SampleCards.Erase(done), CardSnapshot.Take(card.Root, card.Identity));
break;
case "newcard":
// Inserted first (its toast says it is new), then chosen: its first plan registers it and asks for a nickname.
var fresh = SampleCards.NewCard(data);
await ForgetAsync(shell, fresh.Identity);
await import.CardInsertedAsync(fresh);
await ShowPlanAsync(import, fresh);
break;
default:
throw new ArgumentOutOfRangeException(nameof(state), state, "Unknown Import state.");
}
}
/// <summary>The card selected, its plan ready, the sunset session titled.</summary>
private static async Task ShowPlanAsync(ImportViewModel import, CardDevice card)
{
if (import.Result is not null) import.NewImportCommand.Execute(null);
import.CloseDetailsCommand.Execute(null);
await import.RefreshSourcesAsync();
import.SelectSource(card.Identity);
import.KeepCard = true;
await import.WaitForPlanAsync();
if (import.Sessions.Count == 3)
{
var sunset = import.Sessions[^1].Title;
sunset.Text = "Harbour sunset";
sunset.Commit();
}
}
private static ImportPlan Plan(ImportViewModel import) => import.Plan ?? throw new InvalidOperationException("The sample card has no plan.");
/// <summary>The new card stays new in every theme: an earlier state registered it on its first plan.</summary>
private static async Task ForgetAsync(ShellViewModel shell, string identity)
{
if (shell.Services.Database is not { } db || await db.MediaCards.FindByIdentityAsync(identity) is not { } known) return;
await db.MediaCards.DeleteAsync(known.Id);
}
}