Move to use site

This commit is contained in:
Manav Rathi
2025-06-23 17:28:12 +05:30
parent 4b82516909
commit fa137dcccc
7 changed files with 52 additions and 67 deletions

View File

@@ -26,7 +26,7 @@ import {
} from "ente-new/photos/components/PlaceholderThumbnails";
import { TileBottomTextOverlay } from "ente-new/photos/components/Tiles";
import { PseudoCollectionID } from "ente-new/photos/services/collection-summary";
import { enteFileDeletionDate } from "ente-new/photos/services/trash";
import { type EnteTrashFile } from "ente-new/photos/services/trash";
import { t } from "i18next";
import memoize from "memoize-one";
import { GalleryContext } from "pages/gallery";
@@ -355,21 +355,19 @@ export const FileList: React.FC<FileListProps> = ({
const groupByTime = (timeStampList: TimeStampListItem[]) => {
let listItemIndex = 0;
let currentDate;
let lastCreationTime: number | undefined;
annotatedFiles.forEach((item, index) => {
const creationTime = fileCreationTime(item.file) / 1000;
if (
!currentDate ||
!isSameDay(
new Date(fileCreationTime(item.file) / 1000),
new Date(currentDate),
)
!lastCreationTime ||
!isSameDay(new Date(creationTime), new Date(lastCreationTime))
) {
currentDate = fileCreationTime(item.file) / 1000;
lastCreationTime = creationTime;
timeStampList.push({
tag: "date",
date: item.timelineDateString,
id: currentDate.toString(),
id: lastCreationTime.toString(),
});
timeStampList.push({
tag: "file",
@@ -1285,12 +1283,12 @@ const FileThumbnail: React.FC<FileThumbnailProps> = ({
{activeCollectionID == PseudoCollectionID.trash &&
// TODO(RE):
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
file.isTrashed && (
(file as EnteTrashFile).deleteBy && (
<TileBottomTextOverlay>
<Typography variant="small">
{formattedDateRelative(enteFileDeletionDate(file))}
{formattedDateRelative(
(file as EnteTrashFile).deleteBy,
)}
</Typography>
</TileBottomTextOverlay>
)}

View File

@@ -1,20 +1,3 @@
/**
* Convert an epoch microsecond value to a JavaScript date.
*
* [Note: Remote timestamps are epoch microseconds]
*
* This is a convenience API for dealing with optional epoch microseconds in
* various data structures. Remote talks in terms of epoch microseconds, but
* JavaScript dates are underlain by epoch milliseconds, and this does a
* conversion, with a convenience of short circuiting undefined values.
*/
export const dateFromEpochMicroseconds = (
epochMicroseconds: number | undefined,
) =>
epochMicroseconds === undefined
? undefined
: new Date(epochMicroseconds / 1000);
/**
* Return `true` if both the given dates have the same day.
*/

View File

@@ -57,11 +57,14 @@ export const formattedTime = (date: Date) => _timeFormat.format(date);
* @param dateOrEpochMicroseconds A JavaScript Date or a numeric epoch
* microseconds value.
*
* [Note: Remote timestamps are epoch microseconds]
*
* Remote talks in terms of epoch microseconds, while JavaScript dates are
* underlain by epoch milliseconds.
*
* As a convenience, this function can be either be directly passed a JavaScript
* date, or it can be given the raw epoch microseconds value and it'll convert
* internally.
*
* See: [Note: Remote timestamps are epoch microseconds]
*/
export const formattedDateTime = (dateOrEpochMicroseconds: Date | number) =>
_formattedDateTime(toDate(dateOrEpochMicroseconds));
@@ -74,7 +77,19 @@ const toDate = (dm: Date | number) =>
let _relativeTimeFormat: Intl.RelativeTimeFormat | undefined;
export const formattedDateRelative = (date: Date) => {
/**
* Return a locale aware relative version of the given date.
*
* Example: "in 23 days"
*
* @param dateOrEpochMicroseconds A JavaScript Date or a numeric epoch
* microseconds value.
*
* See: [Note: Remote timestamps are epoch microseconds]
*/
export const formattedDateRelative = (
dateOrEpochMicroseconds: Date | number,
) => {
const units: [Intl.RelativeTimeFormatUnit, number][] = [
["year", 24 * 60 * 60 * 1000 * 365],
["month", (24 * 60 * 60 * 1000 * 365) / 12],
@@ -84,6 +99,8 @@ export const formattedDateRelative = (date: Date) => {
["second", 1000],
];
const date = toDate(dateOrEpochMicroseconds);
// Math.abs accounts for both past and future scenarios.
const elapsed = Math.abs(date.getTime() - Date.now());

View File

@@ -13,8 +13,8 @@ import { uniqueFilesByID } from "ente-gallery/utils/files";
import { fileLogID, type EnteFile } from "ente-media/file";
import { FileType } from "ente-media/file-type";
import { updateFilePublicMagicMetadata } from "ente-new/photos/services/file";
import { getLocalTrashFileIDs } from "ente-new/photos/services/files";
import { savedFiles } from "ente-new/photos/services/photos-fdb";
import { getLocalTrashFileIDs } from "ente-new/photos/services/trash";
import { gunzip, gzip } from "ente-new/photos/utils/gzip";
import { randomSample } from "ente-utils/array";
import { ensurePrecondition } from "ente-utils/ensure";

View File

@@ -20,7 +20,7 @@ import {
isHiddenCollection,
} from "ente-new/photos/services/collection";
import { getLatestVersionFiles } from "ente-new/photos/services/files";
import { type TrashedEnteFile } from "ente-new/photos/services/trash";
import { type EnteTrashFile } from "ente-new/photos/services/trash";
import { splitByPredicate } from "ente-utils/array";
import { includes } from "ente-utils/type-guards";
import { t } from "i18next";
@@ -424,7 +424,7 @@ export type GalleryAction =
collections: Collection[];
normalFiles: EnteFile[];
hiddenFiles: EnteFile[];
trashedFiles: TrashedEnteFile[];
trashedFiles: EnteTrashFile[];
}
| {
type: "setCollections";

View File

@@ -8,8 +8,8 @@ import type { ElectronMLWorker } from "ente-base/types/ipc";
import { isNetworkDownloadError } from "ente-gallery/services/download";
import type { ProcessableUploadItem } from "ente-gallery/services/upload";
import { fileLogID, type EnteFile } from "ente-media/file";
import { getLocalTrashFileIDs } from "ente-new/photos/services/trash";
import { wait } from "ente-utils/promise";
import { getLocalTrashFileIDs } from "../files";
import { savedFiles } from "../photos-fdb";
import {
createImageBitmapAndData,

View File

@@ -1,4 +1,3 @@
import { dateFromEpochMicroseconds } from "ente-base/date";
import type { EnteFile, RemoteEnteFile } from "ente-media/file";
import { fileCreationTime } from "ente-media/file-metadata";
import localForage from "ente-shared/storage/localForage";
@@ -44,42 +43,31 @@ export async function getLocalTrashedFiles() {
return getTrashedFiles(await getLocalTrash());
}
export type TrashedEnteFile = EnteFile & {
/**
* A file augmented with the date when it will be permanently deleted.
*/
export type EnteTrashFile = EnteFile & {
/**
* `true` if this file is in trash (i.e. it has been deleted by the user,
* and will be permanently deleted after 30 days of being moved to trash).
*/
isTrashed?: boolean;
/**
* If {@link isTrashed} is `true`, then {@link deleteBy} contains the epoch
* microseconds when this file will be permanently deleted.
* Timestamp (epoch microseconds) when this file, which is already in trash,
* will be permanently deleted.
*
* On being deleted by the user, files move to trash, will be permanently
* deleted after 30 days of being moved to trash)
*/
deleteBy?: number;
};
/**
* Return the date when the file will be deleted permanently. Only valid for
* files that are in the user's trash.
*
* This is a convenience wrapper over the {@link deleteBy} property of a file,
* converting that epoch microsecond value into a JavaScript date.
*/
export const enteFileDeletionDate = (file: TrashedEnteFile) =>
dateFromEpochMicroseconds(file.deleteBy);
export function getTrashedFiles(trash: Trash): TrashedEnteFile[] {
return sortTrashFiles(
trash.map((trashedFile) => ({
...trashedFile.file,
updationTime: trashedFile.updatedAt,
deleteBy: trashedFile.deleteBy,
isTrashed: true,
export const getTrashedFiles = (trash: Trash): EnteTrashFile[] =>
sortTrashFiles(
trash.map(({ file, updatedAt, deleteBy }) => ({
...file,
updationTime: updatedAt,
deleteBy,
})),
);
}
const sortTrashFiles = (files: TrashedEnteFile[]) => {
return files.sort((a, b) => {
const sortTrashFiles = (files: EnteTrashFile[]) =>
files.sort((a, b) => {
if (a.deleteBy === b.deleteBy) {
const at = fileCreationTime(a);
const bt = fileCreationTime(b);
@@ -89,7 +77,6 @@ const sortTrashFiles = (files: TrashedEnteFile[]) => {
}
return (a.deleteBy ?? 0) - (b.deleteBy ?? 0);
});
};
/**
* Return the IDs of all the files that are part of the trash as per our local