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:
@@ -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