Sketch 2
This commit is contained in:
@@ -26,77 +26,6 @@ import {
|
||||
} from "ente-new/photos/utils/native-fs";
|
||||
import { wait } from "ente-utils/promise";
|
||||
|
||||
/**
|
||||
* An object that keeps track of progress of a user-initiated download of a set
|
||||
* of files to the user's device.
|
||||
*
|
||||
* This "download" is distinct from the downloads the app does from remote (e.g.
|
||||
* when the user is viewing them).
|
||||
*
|
||||
* What we're doing here is perhaps more accurately described "a user initiated
|
||||
* download of files to the user's device", but that is too long, so we instead
|
||||
* refer to this process as "saving them".
|
||||
*
|
||||
* Note however that the app's UI itself takes the user perspective, so the
|
||||
* upper (UI) layers use the word "download", while this implementation layer
|
||||
* uses the word "save", and there is an unavoidable incongruity in the middle.
|
||||
*/
|
||||
export interface SaveGroup {
|
||||
/**
|
||||
* A unique identifier of this set of saves.
|
||||
*/
|
||||
id: number;
|
||||
/**
|
||||
* The total number of files to save to the user's device.
|
||||
*/
|
||||
total: number;
|
||||
/**
|
||||
* The number of files that have already been save.
|
||||
*/
|
||||
success: number;
|
||||
/**
|
||||
* The number of failures.
|
||||
*/
|
||||
failed: number;
|
||||
folderName: string;
|
||||
collectionID: number;
|
||||
isHidden: boolean;
|
||||
/**
|
||||
* The path to a directory on the user's file system that was selected by
|
||||
* the user to save the files in when they initiated the download on the
|
||||
* desktop app.
|
||||
*
|
||||
* This property is only set when running in the context of the desktop app.
|
||||
* The web app downloads to the user's default downloads folder, and when
|
||||
* running in the web app this property will not be set.
|
||||
*/
|
||||
downloadDirPath?: string;
|
||||
/**
|
||||
* An {@link AbortController} that can be used to cancel the save.
|
||||
*/
|
||||
canceller: AbortController;
|
||||
}
|
||||
|
||||
export const isSaveStarted = (group: SaveGroup) => group.total > 0;
|
||||
|
||||
/**
|
||||
* Return `true` if there are no files in this save group that are pending.
|
||||
*/
|
||||
export const isSaveComplete = ({ total, success, failed }: SaveGroup) =>
|
||||
total == success + failed;
|
||||
|
||||
/**
|
||||
* Return `true` if there are no files in this save group that are pending, but
|
||||
* one or more files had failed to download.
|
||||
*/
|
||||
export const isSaveCompleteWithErrors = (group: SaveGroup) =>
|
||||
group.failed > 0 && isSaveComplete(group);
|
||||
|
||||
/**
|
||||
* Return `true` if this save was cancelled on a user request.
|
||||
*/
|
||||
export const isSaveCancelled = (group: SaveGroup) =>
|
||||
group.canceller.signal.aborted;
|
||||
|
||||
export type SetFilesDownloadProgressAttributes = (
|
||||
value: Partial<SaveGroup> | ((prev: SaveGroup) => SaveGroup),
|
||||
|
||||
Reference in New Issue
Block a user