π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
wip speed up
Manav Rathi49f9caac90ef
diff --git a/web/apps/photos/src/components/PhotoFrame.tsx b/web/apps/photos/src/components/PhotoFrame.tsxindex 1535713ed6..c9968905dd 100644--- a/web/apps/photos/src/components/PhotoFrame.tsx+++ b/web/apps/photos/src/components/PhotoFrame.tsx@@ -1,3 +1,4 @@+import { formattedDate } from "@/base/i18n-date";import log from "@/base/log";import type { FileInfoProps } from "@/gallery/components/FileInfo";import {@@ -13,6 +14,7 @@ import type { GalleryBarMode } from "@/new/photos/components/gallery/reducer";import { TRASH_SECTION } from "@/new/photos/services/collection";import { styled } from "@mui/material";import { PhotoViewer } from "components/PhotoViewer";+import { t } from "i18next";import { useRouter } from "next/router";import { GalleryContext } from "pages/gallery";import PhotoSwipe from "photoswipe";@@ -66,6 +68,11 @@ export type DisplayFile = EnteFile & {isSourceLoaded?: boolean;conversionFailed?: boolean;canForceConvert?: boolean;+ /**+ * The formatted date string under which this file should be grouped in the+ * gallery listing.+ */+ timelineDateString?: string;};export type PhotoFrameProps = Pick<@@ -178,6 +185,7 @@ const PhotoFrame = ({w: window.innerWidth,h: window.innerHeight,title: file.pubMagicMetadata?.data.caption,+ timelineDateString: fileTimelineDateString(file),}));setDisplayFiles(result);setFetching({});@@ -664,3 +672,19 @@ const updateDisplayFileSource = (file.src = url as string;}};++const A_DAY = 24 * 60 * 60 * 1000;++const fileTimelineDateString = (item: EnteFile) => {+ const date = new Date(item.metadata.creationTime / 1000);+ return isSameDay(date, new Date())+ ? t("TODAY")+ : isSameDay(date, new Date(Date.now() - A_DAY))+ ? t("YESTERDAY")+ : formattedDate(date);+};++const isSameDay = (first: Date, second: Date) =>+ first.getFullYear() === second.getFullYear() &&+ first.getMonth() === second.getMonth() &&+ first.getDate() === second.getDate();diff --git a/web/apps/photos/src/components/PhotoList/index.tsx b/web/apps/photos/src/components/PhotoList/index.tsxindex 152df2e306..261831637b 100644--- a/web/apps/photos/src/components/PhotoList/index.tsx+++ b/web/apps/photos/src/components/PhotoList/index.tsx@@ -185,7 +185,9 @@ const NothingContainer = styled(ListItemContainer)`type Props = Pick<PhotoFrameProps, "mode" | "modePlus"> & {height: number;width: number;- displayFiles: EnteFile[];+ displayFiles: (EnteFile & {+ timelineDateString?: string;+ })[];showAppDownloadBanner: boolean;getThumbnail: (file: EnteFile,@@ -432,9 +434,12 @@ export function PhotoList({) {currentDate = item.metadata.creationTime / 1000;+ const a = _getDate(currentDate);+ const b = item.timelineDateString;+ if (a !== b) console.error("mismatch", a, b);timeStampList.push({itemType: ITEM_TYPE.TIME,- date: _getDate(currentDate),+ date: b,id: currentDate.toString(),});timeStampList.push({@@ -737,10 +742,17 @@ export function PhotoList({if (!galleryContext.selectedFile) return;console.time("t0");- const datedDisplayFiles = displayFiles?.map((item) => ({- ...item,- date: getDate(item),- }));+ const datedDisplayFiles = displayFiles?.map((item) => {+ const a = getDate(item);+ const b = item.timelineDateString;+ if (a !== b) console.error("mismatch", a, b);++ return {+ ...item,+ date: a,+ };+ });+console.timeEnd("t0");console.time("t1");const notSelectedFiles = datedDisplayFiles?.filter(diff --git a/web/packages/shared/time/format.ts b/web/packages/shared/time/format.tsdeleted file mode 100644index 46589ba4ab..0000000000--- a/web/packages/shared/time/format.ts+++ /dev/null@@ -1,45 +0,0 @@-import i18n, { t } from "i18next";--// TODO: Move to @/base/date--const dateTimeFullFormatter1 = new Intl.DateTimeFormat(i18n.language, {- weekday: "short",- month: "short",- day: "numeric",-});--const dateTimeFullFormatter2 = new Intl.DateTimeFormat(i18n.language, {- year: "numeric",-});--const timeFormatter = new Intl.DateTimeFormat(i18n.language, {- timeStyle: "short",-});--function formatDateFull(date: number | Date) {- return [dateTimeFullFormatter1, dateTimeFullFormatter2]- .map((f) => f.format(date))- .join(" ");-}--export function formatDate(date: number | Date) {- const withinYear =- new Date().getFullYear() === new Date(date).getFullYear();- const dateTimeFormat2 = !withinYear ? dateTimeFullFormatter2 : null;- return [dateTimeFullFormatter1, dateTimeFormat2]- .filter((f): f is Intl.DateTimeFormat => !!f)- .map((f) => f.format(date))- .join(" ");-}--function formatTime(date: number | Date) {- return timeFormatter.format(date).toUpperCase();-}--// function formatDateTimeFull(dateTime: number | Date): string {-// return [formatDateFull(dateTime), t("at"), formatTime(dateTime)].join(" ");-// }--function formatDateTime(dateTime: number | Date): string {- return [formatDate(dateTime), t("at"), formatTime(dateTime)].join(" ");-}