Compare commits

...
Author SHA1 Message Date
spark be94ba0520 Library: remember the chosen delivery target across tab switches
ci / rust (pull_request) Successful in 6m36s
ci / typescript (pull_request) Successful in 10m23s
SendButton wrote the selected target to prefs only on a successful send, so
picking a target and then leaving the Library tab unmounted the button, and on
return it reloaded the last *sent* target from prefs: a target chosen but not
yet sent silently reverted (e.g. FPA back to ZZ), risking a send to the wrong
client. Persist the choice the moment the dropdown changes, and also when a
stored-but-removed target falls back to the first. Test covers survival across
a remount.

Claude-Session: https://claude.ai/code/session_01RAkmwWv6L5KmpX4h9JPD2i
2026-10-17 11:23:01 +00:00
2 changed files with 31 additions and 2 deletions

No files matched your search

+26
View File
@@ -24,4 +24,30 @@ describe("send button", () => {
fireEvent.click(await screen.findByRole("button", { name: "Enviar de novo a que já tinha ido" }));
await waitFor(() => expect(calls).toEqual([[["a", "b"], false], [["a"], true]]));
});
it("remembers the chosen destination across a remount (tab switch)", () => {
try {
window.localStorage.clear();
} catch {
/* jsdom without storage */
}
const api = {} as unknown as ApiClient;
const targets = [
{ id: "zz", name: "ZZ", kind: "ZEROZERO" },
{ id: "fpa", name: "FPA", kind: "NEXTCLOUD" },
] as unknown as DeliveryTarget[];
const view = render(
<MemoryRouter>
<SendButton api={api} orgId="org" selection={[]} targets={targets} onQueued={() => {}} />
</MemoryRouter>,
);
fireEvent.change(screen.getByRole("combobox"), { target: { value: "fpa" } });
view.unmount();
render(
<MemoryRouter>
<SendButton api={api} orgId="org" selection={[]} targets={targets} onQueued={() => {}} />
</MemoryRouter>,
);
expect((screen.getByRole("combobox") as HTMLSelectElement).value).toBe("fpa");
});
});
+5 -2
View File
@@ -26,7 +26,10 @@ export function SendButton(props: { api: ApiClient; orgId: string; selection: Ph
const [busy, setBusy] = useState(false);
const [note, setNote] = useState<string | null>(null);
useEffect(() => {
if (targets.length && !targets.some((x) => x.id === targetId)) setTargetId(targets[0]!.id);
if (targets.length && !targets.some((x) => x.id === targetId)) {
setTargetId(targets[0]!.id);
prefs.set(LAST_TARGET, targets[0]!.id);
}
}, [targets, targetId]);
useEffect(() => setAlready([]), [targetId, eventId]);
useEffect(() => {
@@ -84,7 +87,7 @@ export function SendButton(props: { api: ApiClient; orgId: string; selection: Ph
<span className="relative flex items-center gap-1">
{target?.kind === "ZEROZERO" && eventId && <ZerozeroGamePicker api={api} orgId={orgId} targetId={targetId} eventId={eventId} compact />}
{targets.length > 1 && (
<select aria-label={t.deliverTo} value={targetId} onChange={(e) => setTargetId(e.target.value)} className="h-6 max-w-[140px] border border-black bg-cell px-1 text-[12px] text-ink">
<select aria-label={t.deliverTo} value={targetId} onChange={(e) => { setTargetId(e.target.value); prefs.set(LAST_TARGET, e.target.value); }} className="h-6 max-w-[140px] border border-black bg-cell px-1 text-[12px] text-ink">
{targets.map((x) => (
<option key={x.id} value={x.id}>
{x.name}