Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
be94ba0520 | ||
|
|
29d437fb62 | ||
|
|
649521f7b4 | ||
|
|
8ba9f61619 |
No files matched your search
@@ -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");
|
||||
});
|
||||
});
|
||||
@@ -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}
|
||||
|
||||
@@ -41,6 +41,8 @@ function IngestState({ api, orgId, children }: { api: ReturnType<typeof useAuth>
|
||||
|
||||
/** Several megabytes through IPC. Dozens at once freeze the webview on "A enviar…" and the send never finishes. */
|
||||
const ORIGINAL_IPC_MS = 45_000;
|
||||
/** A few at a time: one is slow, all of them freeze the bar. */
|
||||
const MAX_PARALLEL_ORIGINALS = 3;
|
||||
|
||||
function withTimeout<T>(work: Promise<T>, ms: number): Promise<T | "timeout" | null> {
|
||||
return new Promise((resolve) => {
|
||||
@@ -62,41 +64,42 @@ function withTimeout<T>(work: Promise<T>, ms: number): Promise<T | "timeout" | n
|
||||
/**
|
||||
* Desktop app: when someone needs the full original of a photo this computer keeps (100% zoom on the web, an export
|
||||
* made on the server, delivery to ZeroZero), the server asks over the live channel and this sends it.
|
||||
* One original at a time, so the webview stays responsive and the next ask can run.
|
||||
* Up to three at a time, so the webview stays responsive and the next ask can run.
|
||||
*/
|
||||
function OriginalResponder({ api, add }: { api: ReturnType<typeof useAuth>["api"]; add: ReturnType<typeof useUploadQueue>["add"] }) {
|
||||
const sending = useRef(new Set<string>());
|
||||
const queue = useRef<{ sha256: string; photoId: string }[]>([]);
|
||||
const busy = useRef(false);
|
||||
const active = useRef(0);
|
||||
|
||||
const pump = useCallback(() => {
|
||||
if (busy.current) return;
|
||||
const next = queue.current.shift();
|
||||
if (!next) return;
|
||||
busy.current = true;
|
||||
const release = () => {
|
||||
sending.current.delete(next.sha256);
|
||||
busy.current = false;
|
||||
pump();
|
||||
};
|
||||
void (async () => {
|
||||
const bytes = await withTimeout(localOriginal(next.sha256), ORIGINAL_IPC_MS);
|
||||
if (bytes && bytes !== "timeout") {
|
||||
add([new File([bytes], `${next.sha256}.jpg`, { type: "image/jpeg" })], undefined, () => release());
|
||||
return;
|
||||
}
|
||||
if (bytes !== "timeout") {
|
||||
// The file is still here but changed since it arrived (Photo Mechanic wrote captions into it): sent as this
|
||||
// photo's original, which the server checks is the same photo.
|
||||
try {
|
||||
const changed = await withTimeout(localOriginalChanged(next.sha256), ORIGINAL_IPC_MS);
|
||||
if (changed && changed !== "timeout") await api.sendOriginal(next.photoId, new Blob([changed], { type: "image/jpeg" }), `${next.sha256}.jpg`);
|
||||
} catch {
|
||||
/* not the same photo, or offline: asked again later */
|
||||
while (active.current < MAX_PARALLEL_ORIGINALS) {
|
||||
const next = queue.current.shift();
|
||||
if (!next) return;
|
||||
active.current += 1;
|
||||
const release = () => {
|
||||
sending.current.delete(next.sha256);
|
||||
active.current -= 1;
|
||||
pump();
|
||||
};
|
||||
void (async () => {
|
||||
const bytes = await withTimeout(localOriginal(next.sha256), ORIGINAL_IPC_MS);
|
||||
if (bytes && bytes !== "timeout") {
|
||||
add([new File([bytes], `${next.sha256}.jpg`, { type: "image/jpeg" })], undefined, () => release());
|
||||
return;
|
||||
}
|
||||
}
|
||||
release();
|
||||
})();
|
||||
if (bytes !== "timeout") {
|
||||
// The file is still here but changed since it arrived (Photo Mechanic wrote captions into it): sent as this
|
||||
// photo's original, which the server checks is the same photo.
|
||||
try {
|
||||
const changed = await withTimeout(localOriginalChanged(next.sha256), ORIGINAL_IPC_MS);
|
||||
if (changed && changed !== "timeout") await api.sendOriginal(next.photoId, new Blob([changed], { type: "image/jpeg" }), `${next.sha256}.jpg`);
|
||||
} catch {
|
||||
/* not the same photo, or offline: asked again later */
|
||||
}
|
||||
}
|
||||
release();
|
||||
})();
|
||||
}
|
||||
}, [add, api]);
|
||||
|
||||
const onMessage = useCallback(
|
||||
|
||||
Reference in new issue
Block a user