Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Rename

Manav Rathi943a524ba9ab
diff --git a/web/apps/photos/src/components/FileList.tsx b/web/apps/photos/src/components/FileList.tsx
index aa3a61c2e0..400f125027 100644
--- a/web/apps/photos/src/components/FileList.tsx
+++ b/web/apps/photos/src/components/FileList.tsx
@@ -13,7 +13,6 @@ import { downloadManager } from "ente-gallery/services/download";
import type { EnteFile } from "ente-media/file";
import { fileDurationString } from "ente-media/file-metadata";
import { FileType } from "ente-media/file-type";
-import { GAP_BTW_TILES } from "ente-new/photos/components/FileList";
import type { GalleryBarMode } from "ente-new/photos/components/gallery/reducer";
import {
LoadingThumbnail,
@@ -22,6 +21,7 @@ import {
import { TileBottomTextOverlay } from "ente-new/photos/components/Tiles";
import {
computeThumbnailGridLayoutParams,
+ thumbnailGap,
type ThumbnailGridLayoutParams,
} from "ente-new/photos/components/utils/thumbnail-grid-layout";
import { PseudoCollectionID } from "ente-new/photos/services/collection-summary";
@@ -1040,7 +1040,7 @@ const FileThumbnail: React.FC<FileThumbnailProps> = ({
const FileThumbnail_ = styled("div")<{ disabled: boolean }>`
display: flex;
width: fit-content;
- margin-bottom: ${GAP_BTW_TILES}px;
+ margin-bottom: ${thumbnailGap}px;
min-width: 100%;
overflow: hidden;
position: relative;
diff --git a/web/packages/new/photos/components/FileList.ts b/web/packages/new/photos/components/FileList.ts
deleted file mode 100644
index ce96218dad..0000000000
--- a/web/packages/new/photos/components/FileList.ts
+++ /dev/null
@@ -1,6 +0,0 @@
-export const GAP_BTW_TILES = 4;
-export const IMAGE_CONTAINER_MAX_HEIGHT = 180;
-export const IMAGE_CONTAINER_MAX_WIDTH = 180;
-export const MIN_COLUMNS = 4;
-
-// TODO: Move the FileList component here.
diff --git a/web/packages/new/photos/components/gallery/BarImpl.tsx b/web/packages/new/photos/components/gallery/BarImpl.tsx
index 757032f998..e7d6928f73 100644
--- a/web/packages/new/photos/components/gallery/BarImpl.tsx
+++ b/web/packages/new/photos/components/gallery/BarImpl.tsx
@@ -11,16 +11,16 @@ import { FilledIconButton } from "ente-base/components/mui";
import { Ellipsized2LineTypography } from "ente-base/components/Typography";
import { useIsSmallWidth } from "ente-base/components/utils/hooks";
import { CollectionsSortOptions } from "ente-new/photos/components/CollectionsSortOptions";
-import {
- IMAGE_CONTAINER_MAX_WIDTH,
- MIN_COLUMNS,
-} from "ente-new/photos/components/FileList";
import {
BarItemTile,
ItemCard,
TileTextOverlay,
} from "ente-new/photos/components/Tiles";
import { FocusVisibleUnstyledButton } from "ente-new/photos/components/UnstyledButton";
+import {
+ thumbnailLayoutMinColumns,
+ thumbnailMaxWidth,
+} from "ente-new/photos/components/utils/thumbnail-grid-layout";
import type {
CollectionSummary,
CollectionSummaryAttribute,
@@ -300,7 +300,7 @@ export const GalleryBarImpl: React.FC<GalleryBarImplProps> = ({
const BarWrapper = styled("div")`
padding-inline: 24px;
- @media (max-width: ${IMAGE_CONTAINER_MAX_WIDTH * MIN_COLUMNS}px) {
+ @media (max-width: ${thumbnailMaxWidth * thumbnailLayoutMinColumns}px) {
padding-inline: 4px;
}
margin-block-end: 16px;
diff --git a/web/packages/new/photos/components/utils/thumbnail-grid-layout.ts b/web/packages/new/photos/components/utils/thumbnail-grid-layout.ts
index 58f6f12612..5ab7f7935e 100644
--- a/web/packages/new/photos/components/utils/thumbnail-grid-layout.ts
+++ b/web/packages/new/photos/components/utils/thumbnail-grid-layout.ts
@@ -1,3 +1,8 @@
+export const thumbnailGap = 4;
+export const thumbnailMaxHeight = 180;
+export const thumbnailMaxWidth = 180;
+export const thumbnailLayoutMinColumns = 4;
+
export interface ThumbnailGridLayoutParams {
/**
* The overall width available to us.
@@ -47,20 +52,20 @@ export const computeThumbnailGridLayoutParams = (
): ThumbnailGridLayoutParams => {
const isSmallerLayout = !(
containerWidth >
- MIN_COLUMNS * IMAGE_CONTAINER_MAX_WIDTH
+ thumbnailLayoutMinColumns * thumbnailMaxWidth
);
const paddingInline = getGapFromScreenEdge(containerWidth);
const fittableColumns = getFractionFittableColumns(containerWidth);
let columns = Math.floor(fittableColumns);
- if (columns < MIN_COLUMNS) {
- columns = MIN_COLUMNS;
+ if (columns < thumbnailLayoutMinColumns) {
+ columns = thumbnailLayoutMinColumns;
}
const shrinkRatio = getShrinkRatio(containerWidth, columns);
- const itemHeight = IMAGE_CONTAINER_MAX_HEIGHT * shrinkRatio;
- const itemWidth = IMAGE_CONTAINER_MAX_WIDTH * shrinkRatio;
- const gap = GAP_BTW_TILES;
+ const itemHeight = thumbnailMaxHeight * shrinkRatio;
+ const itemWidth = thumbnailMaxWidth * shrinkRatio;
+ const gap = thumbnailGap;
return {
containerWidth,
@@ -73,24 +78,13 @@ export const computeThumbnailGridLayoutParams = (
};
};
-/* TODO: Some of this code is also duplicated elsewhere. See if those places can
- reuse the same function as above, with some extra params if needed.
-
- So that the duplication is easier to identify, keeping the duplication
- verbatim for now */
-
-const GAP_BTW_TILES = 4;
-const IMAGE_CONTAINER_MAX_HEIGHT = 180;
-const IMAGE_CONTAINER_MAX_WIDTH = 180;
-const MIN_COLUMNS = 4;
-
const getFractionFittableColumns = (width: number): number =>
- (width - 2 * getGapFromScreenEdge(width) + GAP_BTW_TILES) /
- (IMAGE_CONTAINER_MAX_WIDTH + GAP_BTW_TILES);
+ (width - 2 * getGapFromScreenEdge(width) + thumbnailGap) /
+ (thumbnailMaxWidth + thumbnailGap);
const getGapFromScreenEdge = (width: number) =>
- width > MIN_COLUMNS * IMAGE_CONTAINER_MAX_WIDTH ? 24 : 4;
+ width > thumbnailLayoutMinColumns * thumbnailMaxWidth ? 24 : 4;
const getShrinkRatio = (width: number, columns: number) =>
- (width - 2 * getGapFromScreenEdge(width) - (columns - 1) * GAP_BTW_TILES) /
- (columns * IMAGE_CONTAINER_MAX_WIDTH);
+ (width - 2 * getGapFromScreenEdge(width) - (columns - 1) * thumbnailGap) /
+ (columns * thumbnailMaxWidth);