Bladeren bron

Fix Move to pad / Copy to pad doing nothing

The picker closed itself before reading its props; closing clears
ui.picker, so picker.from threw in an async handler with no message.
Read the choice first, and show transfer errors in the banner.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude 1 dag geleden
bovenliggende
commit
48084f6df5

+ 5 - 1
frontend/src/lib/PadPicker.svelte

@@ -35,9 +35,13 @@
 
   async function go() {
     if (!action) return;
+    // Read everything before closing: closing clears ui.picker, and props
+    // are live, so `picker` is null from then on.
+    const what = kind;
+    const from = picker.from;
     const to = target;
     onclose();
-    await transfer(kind, picker.from, to);
+    await transfer(what, from, to);
   }
 
   function keydown(e: KeyboardEvent) {

+ 9 - 1
frontend/src/lib/pads.ts

@@ -1,7 +1,7 @@
 // Moving, copying and swapping pads (build plan M6), shared by drag and drop
 // and the "Move to pad" / "Copy to pad" buttons.
 import { Service, type Pad } from "./api";
-import { app, confirm, run, ui } from "./store.svelte";
+import { app, confirm, message, run, ui } from "./store.svelte";
 import { PER_BANK } from "./slots";
 
 export type Transfer = "move" | "swap" | "copy";
@@ -19,6 +19,14 @@ export function transferKind(from: Pad, to: Pad, copy: boolean): Transfer {
  * sample.
  */
 export async function transfer(kind: Transfer, from: number, to: number): Promise<void> {
+  try {
+    await doTransfer(kind, from, to);
+  } catch (e) {
+    app.error = message(e);
+  }
+}
+
+async function doTransfer(kind: Transfer, from: number, to: number): Promise<void> {
   const pads = app.state?.pads;
   if (!pads || from === to) return;
   const src = pads[from];

+ 3 - 1
pull-requests/m6-move-copy-swap/m6-move-copy-swap.md

@@ -16,11 +16,13 @@ Branch: `m6-move-copy-swap` → `main`
 
 **Go service**: `MovePad`, `CopyPad`, `SwapPads`, `Load` (dialog) and `LoadPath`. The `Dialogs` interface gains `OpenProject`.
 
+**Fix after the first laptop test:** the picker's Move/Copy button did nothing (step 7). The click handler closed the dialog before reading the dialog's choice. Closing clears `ui.picker`, and Svelte 5 props are live, so the following `picker.from` threw inside an async handler, which nothing reported. The handler now reads the choice first. `transfer` also shows any unexpected error in the banner instead of failing silently.
+
 ## Testing
 
 On the server: `go vet` and `go test ./...` pass. New service tests cover move/copy/swap across banks (tuning carried, sample shared, move onto a filled pad, out-of-range slot), and Load: cancelled dialog, DemoFile (name, 6 samples, notes on A01–A04 only, preview URL, 2 sequences), and a bad file keeping the current project.
 
-The frontend is untested here (no Node). **On the laptop** (create `C:\temp\m6` first):
+bajdev's laptop run (2026-11-11): steps 1–6 and 8 passed; step 7 failed and is fixed above. Re-run step 7. The frontend is untested here (no Node). **On the laptop** (create `C:\temp\m6` first):
 
 1. `npm run check` in `frontend`: 0 errors, 0 warnings.
 2. `wails3 dev`, **Load** `testdata\device\DemoFile.xpj`. A01–A04 show `notes`; B01 and B02 don't. Pads play when clicked.