Skip to content

armgit / ente

Public Imported from GitHub
0

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

Use layoutParams

Manav Rathia6e78ab732a8
diff --git a/web/apps/photos/src/components/FileList.tsx b/web/apps/photos/src/components/FileList.tsx
index 8b1fa0e01f..3083214b90 100644
--- a/web/apps/photos/src/components/FileList.tsx
+++ b/web/apps/photos/src/components/FileList.tsx
@@ -27,7 +27,6 @@ import {
import { TileBottomTextOverlay } from "ente-new/photos/components/Tiles";
import {
computeThumbnailGridLayoutParams,
- getShrinkRatio,
type ThumbnailGridLayoutParams,
} from "ente-new/photos/components/utils/thumbnail-grid-layout";
import { PseudoCollectionID } from "ente-new/photos/services/collection-summary";
@@ -235,9 +234,10 @@ export const FileList: React.FC<FileListProps> = ({
() => computeThumbnailGridLayoutParams(width),
[width],
);
+
const {
// containerWidth,
- isSmallerLayout,
+ // isSmallerLayout,
// paddingInline,
columns,
// itemWidth,
@@ -262,8 +262,22 @@ export const FileList: React.FC<FileListProps> = ({
timeStampList.push(asFullSpanListItem(header));
}
+ const { isSmallerLayout, columns } = layoutParams;
if (disableGrouping) {
- noGrouping(timeStampList);
+ let listItemIndex = columns;
+ annotatedFiles.forEach((item, index) => {
+ if (listItemIndex < columns) {
+ timeStampList[timeStampList.length - 1]!.items!.push(item);
+ listItemIndex++;
+ } else {
+ listItemIndex = 1;
+ timeStampList.push({
+ tag: "file",
+ items: [item],
+ itemStartIndex: index,
+ });
+ }
+ });
} else {
groupByTime(timeStampList);
}
@@ -302,7 +316,7 @@ export const FileList: React.FC<FileListProps> = ({
footer,
annotatedFiles,
disableGrouping,
- columns,
+ layoutParams,
]);
useEffect(() => {
@@ -348,23 +362,6 @@ export const FileList: React.FC<FileListProps> = ({
});
};
- const noGrouping = (timeStampList: TimeStampListItem[]) => {
- let listItemIndex = columns;
- annotatedFiles.forEach((item, index) => {
- if (listItemIndex < columns) {
- timeStampList[timeStampList.length - 1]!.items!.push(item);
- listItemIndex++;
- } else {
- listItemIndex = 1;
- timeStampList.push({
- tag: "file",
- items: [item],
- itemStartIndex: index,
- });
- }
- });
- };
-
const getVacuumItem = (
timeStampList: TimeStampListItem[],
footerHeight: number,
@@ -737,9 +734,7 @@ export const FileList: React.FC<FileListProps> = ({
const itemData = createItemData(
timeStampList,
- columns,
layoutParams,
- layoutParams.shrinkRatio,
renderListItem,
);
@@ -783,26 +778,15 @@ const ListItem = styled("div")`
`;
const getTemplateColumns = (
- columns: number,
- shrinkRatio: number,
+ { columns, itemWidth }: ThumbnailGridLayoutParams,
groups?: number[],
-): string => {
- if (groups) {
- return (
- groups
- .map(
- (x) =>
- `repeat(${x}, ${IMAGE_CONTAINER_MAX_WIDTH * shrinkRatio}px)`,
- )
- // Space between date groups
- .join(` 44px `)
- );
- } else {
- return `repeat(${columns},${
- IMAGE_CONTAINER_MAX_WIDTH * shrinkRatio
- }px)`;
- }
-};
+): string =>
+ groups
+ ? groups
+ .map((x) => `repeat(${x}, ${itemWidth}px)`)
+ // Space between date groups
+ .join(` 44px `)
+ : `repeat(${columns},${itemWidth}px)`;
const ListContainer = styled(Box, {
shouldForwardProp: (propName) => propName != "gridTemplateColumns",
@@ -866,9 +850,7 @@ const NoFilesContainer = styled(ListItemContainer)`
interface ItemData {
timeStampList: TimeStampListItem[];
- columns: number;
layoutParams: ThumbnailGridLayoutParams;
- shrinkRatio: number;
renderListItem: (
timeStampListItem: TimeStampListItem,
isScrolling?: boolean,
@@ -878,20 +860,12 @@ interface ItemData {
const createItemData = memoize(
(
timeStampList: TimeStampListItem[],
- columns: number,
layoutParams: ThumbnailGridLayoutParams,
- shrinkRatio: number,
renderListItem: (
timeStampListItem: TimeStampListItem,
isScrolling?: boolean,
) => React.JSX.Element,
- ): ItemData => ({
- timeStampList,
- columns,
- layoutParams,
- shrinkRatio,
- renderListItem,
- }),
+ ): ItemData => ({ timeStampList, layoutParams, renderListItem }),
);
const PhotoListRow = React.memo(
@@ -901,13 +875,12 @@ const PhotoListRow = React.memo(
isScrolling,
data,
}: ListChildComponentProps<ItemData>) => {
- const { timeStampList, columns, shrinkRatio, renderListItem } = data;
+ const { timeStampList, layoutParams, renderListItem } = data;
return (
<ListItem style={style}>
<ListContainer
gridTemplateColumns={getTemplateColumns(
- columns,
- shrinkRatio,
+ layoutParams,
timeStampList[index]!.groups,
)}
>
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 9e796ae8f1..58f6f12612 100644
--- a/web/packages/new/photos/components/utils/thumbnail-grid-layout.ts
+++ b/web/packages/new/photos/components/utils/thumbnail-grid-layout.ts
@@ -84,13 +84,13 @@ const IMAGE_CONTAINER_MAX_HEIGHT = 180;
const IMAGE_CONTAINER_MAX_WIDTH = 180;
const MIN_COLUMNS = 4;
-export const getFractionFittableColumns = (width: number): number =>
+const getFractionFittableColumns = (width: number): number =>
(width - 2 * getGapFromScreenEdge(width) + GAP_BTW_TILES) /
(IMAGE_CONTAINER_MAX_WIDTH + GAP_BTW_TILES);
-export const getGapFromScreenEdge = (width: number) =>
+const getGapFromScreenEdge = (width: number) =>
width > MIN_COLUMNS * IMAGE_CONTAINER_MAX_WIDTH ? 24 : 4;
-export const getShrinkRatio = (width: number, columns: number) =>
+const getShrinkRatio = (width: number, columns: number) =>
(width - 2 * getGapFromScreenEdge(width) - (columns - 1) * GAP_BTW_TILES) /
(columns * IMAGE_CONTAINER_MAX_WIDTH);