fix(files): an upload is said once in any order, copy buttons speak, a link list that failed says so
- The queue holds an upload it sees land done while this tab's upload still waits for its answer, so the dialog's notice is the only one whichever comes first; another device's upload follows after. - One `useCopyFeedback` for every Copy beside a value (token, share link, set-password link): Copied for a moment, a notice a screen reader hears, a warning when the clipboard refuses; the token dialog's two Copy buttons are named by what they copy. - The share dialog's link list shows loading, and a load error with Retry, never "no links" — and no New link beside a list it has not seen. - The settings texts say that signing out elsewhere or a password change revokes the API tokens. - DESIGN.md logs the folder-link decisions; the design lab keeps only the chosen renderings of the Links, Tokens and Files rounds.
This commit is contained in:
@@ -7,15 +7,18 @@ import type { QueueJob } from "./api";
|
||||
import {
|
||||
clearFinished,
|
||||
forgetFinished,
|
||||
noteAnnounced,
|
||||
noteQueue,
|
||||
resetQueueWatch,
|
||||
takeUnannounced,
|
||||
uploadEnded,
|
||||
uploadStarted,
|
||||
useFinished,
|
||||
} from "./downloadQueue";
|
||||
import { renderHook } from "@testing-library/react";
|
||||
|
||||
const job = (id: number, status: string) => ({ id, status }) as unknown as QueueJob;
|
||||
const upload = (id: number) =>
|
||||
({ id, status: "done", source_kind: "upload" }) as unknown as QueueJob;
|
||||
const finishedIds = () => renderHook(() => useFinished()).result.current.map((j) => j.id);
|
||||
|
||||
beforeEach(resetQueueWatch);
|
||||
@@ -44,12 +47,39 @@ describe("downloadQueue · a finish", () => {
|
||||
|
||||
it("a finish its own action announced is kept for the tray but not announced again", () => {
|
||||
noteQueue([]);
|
||||
noteAnnounced(7); // an upload, done in the answer that made it
|
||||
noteQueue([job(7, "done"), job(8, "done")]);
|
||||
uploadStarted();
|
||||
uploadEnded(7); // an upload, done in the answer that made it
|
||||
noteQueue([upload(7), job(8, "done")]);
|
||||
expect(takeUnannounced().map((j) => j.id)).toEqual([8]);
|
||||
expect(finishedIds()).toEqual([7, 8]);
|
||||
});
|
||||
|
||||
it("an upload the queue sees done before its own answer arrives is still said once, by it", () => {
|
||||
noteQueue([]);
|
||||
uploadStarted();
|
||||
noteQueue([upload(7)]); // the server committed it; the answer is still on its way
|
||||
expect(takeUnannounced()).toEqual([]);
|
||||
uploadEnded(7);
|
||||
expect(takeUnannounced()).toEqual([]);
|
||||
expect(finishedIds()).toEqual([7]);
|
||||
});
|
||||
|
||||
it("another device's upload landing meanwhile is announced once this tab's upload answers", () => {
|
||||
noteQueue([]);
|
||||
uploadStarted();
|
||||
noteQueue([upload(7), upload(9)]);
|
||||
uploadEnded(7);
|
||||
expect(takeUnannounced().map((j) => j.id)).toEqual([9]);
|
||||
});
|
||||
|
||||
it("an upload that failed announced nothing: what landed meanwhile is announced", () => {
|
||||
noteQueue([]);
|
||||
uploadStarted();
|
||||
noteQueue([upload(9)]);
|
||||
uploadEnded(null);
|
||||
expect(takeUnannounced().map((j) => j.id)).toEqual([9]);
|
||||
});
|
||||
|
||||
it("a failure is not a finish; closing the tray forgets what finished", () => {
|
||||
noteQueue([job(1, "running"), job(2, "running")]);
|
||||
noteQueue([job(1, "error"), job(2, "done")]);
|
||||
|
||||
@@ -35,6 +35,11 @@ const unannounced = createStore<QueueJob[]>([]);
|
||||
const revealing = createStore<Reveal | null>(null);
|
||||
// Finishes this tab already said out loud where they happened: an upload that answered done.
|
||||
const announcedHere = new Set<number>();
|
||||
// This tab's uploads still waiting for their answer, and the uploads the queue saw land done
|
||||
// meanwhile: one of them may be the answer's own job, done before the answer arrived. Whose it is,
|
||||
// only the answer can tell (`uploadEnded`), so until then none of them is announced.
|
||||
let uploading = 0;
|
||||
let held: QueueJob[] = [];
|
||||
|
||||
/** A job to show in the tray, asked for at `at` (ms). */
|
||||
export interface Reveal {
|
||||
@@ -54,15 +59,35 @@ export function noteQueue(jobs: QueueJob[]): void {
|
||||
finished.set((list) => [...done, ...list.filter((j) => !ids.has(j.id))]);
|
||||
// `delete` answers whether it was there: each id is spent on the one look that finds it done.
|
||||
const news = done.filter((j) => !announcedHere.delete(j.id));
|
||||
if (news.length) unannounced.set((list) => [...list, ...news]);
|
||||
const landed = (j: QueueJob) =>
|
||||
uploading > 0 && j.source_kind === "upload" && before.get(j.id) === undefined;
|
||||
held = [...held, ...news.filter(landed)];
|
||||
const now = news.filter((j) => !landed(j));
|
||||
if (now.length) unannounced.set((list) => [...list, ...now]);
|
||||
}
|
||||
|
||||
/** A finish its own action announced already (an upload done in the answer that made it): the tray
|
||||
* still keeps it, but the done notice would say it a second time — and as a download. */
|
||||
export const noteAnnounced = (id: number): void => {
|
||||
announcedHere.add(id);
|
||||
/** An upload from this tab is on its way: what the queue sees land done may be its own job. */
|
||||
export const uploadStarted = (): void => {
|
||||
uploading += 1;
|
||||
};
|
||||
|
||||
/** An upload's answer came: `said` is the job it announced itself (done in that answer — the tray
|
||||
* still keeps it, but its done notice would say it a second time, and as a download), null when it
|
||||
* announced none (still converting, failed, cancelled). In whichever order the queue saw it. The
|
||||
* rest held meanwhile (another device's uploads) are announced once no upload is waiting. */
|
||||
export function uploadEnded(said: number | null): void {
|
||||
uploading = Math.max(0, uploading - 1);
|
||||
if (said !== null) {
|
||||
const before = held.length;
|
||||
held = held.filter((j) => j.id !== said);
|
||||
if (held.length === before) announcedHere.add(said);
|
||||
}
|
||||
if (uploading > 0 || held.length === 0) return;
|
||||
const release = held;
|
||||
held = [];
|
||||
unannounced.set((list) => [...list, ...release]);
|
||||
}
|
||||
|
||||
/** The queue, noted (see above). Every reader of `qk.downloads()` fetches with this. */
|
||||
export async function fetchQueue(): Promise<QueueJob[]> {
|
||||
const jobs = await api.downloads();
|
||||
@@ -107,5 +132,7 @@ export function resetQueueWatch(): void {
|
||||
finished.set([]);
|
||||
unannounced.set([]);
|
||||
announcedHere.clear();
|
||||
uploading = 0;
|
||||
held = [];
|
||||
revealing.set(null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user