Skip to content

armgit / ente

Public Imported from GitHub
0

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

Refine Space grid layout and fix PWA interactions

Anand Baburajan61858e0e1054
diff --git a/web/apps/space/public/manifest-public.webmanifest b/web/apps/space/public/manifest-public.webmanifest
index 15ecf8277c..0e254eddf8 100644
--- a/web/apps/space/public/manifest-public.webmanifest
+++ b/web/apps/space/public/manifest-public.webmanifest
@@ -5,7 +5,7 @@
"id": "/app",
"scope": "/",
"display": "standalone",
- "background_color": "#000000",
+ "background_color": "#08C225",
"theme_color": "#000000",
"icons": [
{
diff --git a/web/apps/space/public/manifest.webmanifest b/web/apps/space/public/manifest.webmanifest
index 888024ffdd..efa85ddb41 100644
--- a/web/apps/space/public/manifest.webmanifest
+++ b/web/apps/space/public/manifest.webmanifest
@@ -6,7 +6,7 @@
"start_url": "/app",
"scope": "/",
"display": "standalone",
- "background_color": "#000000",
+ "background_color": "#08C225",
"theme_color": "#000000",
"icons": [
{
diff --git a/web/apps/space/src/components/AddFriendDialog.tsx b/web/apps/space/src/components/AddFriendDialog.tsx
index 3314d00fa4..b9d04df47a 100644
--- a/web/apps/space/src/components/AddFriendDialog.tsx
+++ b/web/apps/space/src/components/AddFriendDialog.tsx
@@ -1,9 +1,8 @@
-import { Box, Dialog, useMediaQuery } from "@mui/material";
+import { Box, Dialog } from "@mui/material";
import {
SpaceActionFeedbackIcon,
spaceActionDoneDurationMs,
} from "components/ActionFeedback";
-import { SpaceBottomSheetTransition } from "components/BottomSheetTransition";
import { SpaceShareInviteButton } from "components/ShareInviteButton";
import type { FriendProfile } from "data/friends";
import log from "ente-base/log";
@@ -44,7 +43,6 @@ export const SpaceAddFriendDialog: React.FC<SpaceAddFriendDialogProps> = ({
username: currentUsername,
}) => {
const titleID = React.useId();
- const isBottomSheet = useMediaQuery("(max-width: 599px)");
const [username, setUsername] = React.useState("");
const [isSubmitting, setIsSubmitting] = React.useState(false);
const [isSent, setIsSent] = React.useState(false);
@@ -119,11 +117,6 @@ export const SpaceAddFriendDialog: React.FC<SpaceAddFriendDialogProps> = ({
onClose={isSubmitting ? undefined : onClose}
maxWidth={false}
aria-labelledby={titleID}
- slots={
- isBottomSheet
- ? { transition: SpaceBottomSheetTransition }
- : undefined
- }
slotProps={{
paper: {
sx: {
diff --git a/web/apps/space/src/components/PostAvatar.tsx b/web/apps/space/src/components/PostAvatar.tsx
index 981068d32f..dbd4b366d7 100644
--- a/web/apps/space/src/components/PostAvatar.tsx
+++ b/web/apps/space/src/components/PostAvatar.tsx
@@ -3,12 +3,14 @@ import { SpaceAvatarImage } from "components/AvatarImage";
import React from "react";
interface SpacePostAvatarProps {
+ outerRing?: boolean;
ready: boolean;
size: number;
src?: string | null;
}
export const SpacePostAvatar: React.FC<SpacePostAvatarProps> = ({
+ outerRing = false,
ready,
size,
src,
@@ -48,10 +50,12 @@ export const SpacePostAvatar: React.FC<SpacePostAvatarProps> = ({
<Box
aria-hidden
sx={{
- border: "1px solid rgba(255, 255, 255, 0.16)",
+ border: outerRing
+ ? "1px solid rgba(255, 255, 255, 0.4)"
+ : "1px solid rgba(255, 255, 255, 0.16)",
borderRadius: "50%",
- boxShadow: "0 1px 4px rgba(0, 0, 0, 0.24)",
- inset: 0,
+ boxShadow: outerRing ? "none" : "0 1px 4px rgba(0, 0, 0, 0.24)",
+ inset: outerRing ? -1 : 0,
pointerEvents: "none",
position: "absolute",
}}
diff --git a/web/apps/space/src/components/PostGrid.tsx b/web/apps/space/src/components/PostGrid.tsx
index 695e8ce535..9506d26b5f 100644
--- a/web/apps/space/src/components/PostGrid.tsx
+++ b/web/apps/space/src/components/PostGrid.tsx
@@ -13,10 +13,12 @@ interface PostGridItem {
export const SpacePostGrid = <Item extends PostGridItem>({
items,
postCount,
+ fixedRows = false,
renderTile,
}: {
items: Item[];
postCount?: number;
+ fixedRows?: boolean;
renderTile: (
item: Item,
index: number,
@@ -25,7 +27,7 @@ export const SpacePostGrid = <Item extends PostGridItem>({
}) => {
const [width, setWidth] = React.useState(0);
const [previousLayout, setLayout] = React.useState(() => ({
- ...postPhotoLayout([], 0),
+ ...postPhotoLayout([], 0, undefined, postCount, fixedRows),
items,
postCount,
}));
@@ -43,6 +45,7 @@ export const SpacePostGrid = <Item extends PostGridItem>({
const layout =
previousLayout.items == items &&
previousLayout.width == width &&
+ previousLayout.fixedRows == fixedRows &&
previousLayout.postCount == postCount
? previousLayout
: {
@@ -56,6 +59,7 @@ export const SpacePostGrid = <Item extends PostGridItem>({
width,
previousLayout,
postCount,
+ fixedRows,
),
items,
postCount,
diff --git a/web/apps/space/src/components/PostPhotosBadge.tsx b/web/apps/space/src/components/PostPhotosBadge.tsx
index e763a18db2..3dddc6d1ee 100644
--- a/web/apps/space/src/components/PostPhotosBadge.tsx
+++ b/web/apps/space/src/components/PostPhotosBadge.tsx
@@ -3,9 +3,11 @@ import { Box } from "@mui/material";
export const SpacePostPhotosBadge = ({
count,
inset = 10,
+ subtle = false,
}: {
count: number;
inset?: number;
+ subtle?: boolean;
}) =>
count > 1 ? (
<Box
@@ -18,6 +20,7 @@ export const SpacePostPhotosBadge = ({
filter: "drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5))",
height: 24,
justifyContent: "center",
+ opacity: subtle ? 0.7 : 1,
pointerEvents: "none",
position: "absolute",
right: inset,
@@ -28,8 +31,8 @@ export const SpacePostPhotosBadge = ({
>
<svg
aria-hidden
- width={18}
- height={18}
+ width={subtle ? 15 : 18}
+ height={subtle ? 15 : 18}
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
diff --git a/web/apps/space/src/components/PostTile.tsx b/web/apps/space/src/components/PostTile.tsx
index d607840b0c..2a5233449b 100644
--- a/web/apps/space/src/components/PostTile.tsx
+++ b/web/apps/space/src/components/PostTile.tsx
@@ -37,6 +37,7 @@ export interface SpacePostTileItem {
interface SpacePostTileProps {
displayName: string;
showAvatar?: boolean;
+ subtlePhotosBadge?: boolean;
onLoadAvatar?: () => Promise<string | null>;
flexGrow: number;
imageUrl?: string;
@@ -55,6 +56,7 @@ interface SpacePostTileProps {
export const SpacePostTile: React.FC<SpacePostTileProps> = ({
displayName,
showAvatar = false,
+ subtlePhotosBadge,
onLoadAvatar,
flexGrow,
imageUrl,
@@ -236,7 +238,11 @@ export const SpacePostTile: React.FC<SpacePostTileProps> = ({
) : null}
{!isUnavailable && (
<>
- <SpacePostPhotosBadge count={photoCount} inset={8} />
+ <SpacePostPhotosBadge
+ count={photoCount}
+ inset={8}
+ subtle={subtlePhotosBadge}
+ />
<SpacePostVideoBadge
durationMs={item.photos?.[0]?.video?.durationMs}
size={18}
@@ -288,6 +294,7 @@ export const SpacePostTile: React.FC<SpacePostTileProps> = ({
}}
>
<SpacePostAvatar
+ outerRing
ready={!isAvatarPending && decodedAvatar.ready}
size={26}
src={
diff --git a/web/apps/space/src/screens/HomeScreen.tsx b/web/apps/space/src/screens/HomeScreen.tsx
index 971121196d..dc796f0b83 100644
--- a/web/apps/space/src/screens/HomeScreen.tsx
+++ b/web/apps/space/src/screens/HomeScreen.tsx
@@ -2311,6 +2311,7 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
{hasFeedItems ? (
<>
<SpacePostGrid
+ fixedRows
postCount={
isFeedComplete
? latestFeedEntries.length +
@@ -2351,6 +2352,7 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
item={{ ...item, avatarUrl }}
displayName={item.name}
showAvatar
+ subtlePhotosBadge
flexGrow={flexGrow}
index={index}
imageUrl={imageUrl}
diff --git a/web/apps/space/src/utils/profile-photo-layout.ts b/web/apps/space/src/utils/profile-photo-layout.ts
index 85b647d9c2..9fe5251121 100644
--- a/web/apps/space/src/utils/profile-photo-layout.ts
+++ b/web/apps/space/src/utils/profile-photo-layout.ts
@@ -2,6 +2,33 @@ import { minimumPostPhotoFrameAspectRatio } from "../styles/tiles";
export const profilePhotoGap = 6;
const profilePhotoMinRowHeight = 100;
+const fixedPhotoMinTileWidth = 100;
+const fixedRowPattern = [
+ { heightRatio: 0.62, weights: [1.16, 0.84] },
+ { heightRatio: 0.34, weights: [0.88, 1.18, 0.94] },
+ { heightRatio: 0.49, weights: [0.78, 1.22] },
+ { heightRatio: 0.72, weights: [1.28, 0.72] },
+ { heightRatio: 0.66, weights: [1] },
+ { heightRatio: 0.3, weights: [1.16, 0.8, 1.04] },
+ { heightRatio: 0.58, weights: [0.9, 1.1] },
+ { heightRatio: 0.9, weights: [1] },
+ { heightRatio: 0.46, weights: [1.24, 0.76] },
+ { heightRatio: 0.38, weights: [1.03, 1.08, 0.89] },
+ { heightRatio: 0.32, weights: [0.82, 1.04, 1.14] },
+ { heightRatio: 0.67, weights: [0.76, 1.24] },
+ { heightRatio: 0.54, weights: [1] },
+ { heightRatio: 0.55, weights: [1.08, 0.92] },
+ { heightRatio: 0.36, weights: [1.12, 0.86, 1.02] },
+ { heightRatio: 0.76, weights: [0.86, 1.14] },
+ { heightRatio: 0.51, weights: [1.3, 0.7] },
+ { heightRatio: 0.78, weights: [1] },
+ { heightRatio: 0.29, weights: [0.94, 1.22, 0.84] },
+ { heightRatio: 0.64, weights: [1.04, 0.96] },
+ { heightRatio: 0.6, weights: [1] },
+ { heightRatio: 0.48, weights: [0.82, 1.18] },
+ { heightRatio: 0.35, weights: [1.2, 0.96, 0.84] },
+ { heightRatio: 0.69, weights: [1.2, 0.8] },
+];
interface PhotoRow<Tile> {
aspectRatio: number;
@@ -17,6 +44,7 @@ interface PostPhotoTile {
interface PostPhotoLayout {
width: number;
+ fixedRows: boolean;
fullWidth?: boolean;
rows: PhotoRow<PostPhotoTile>[];
}
@@ -26,6 +54,7 @@ export const postPhotoLayout = (
width: number,
previous?: PostPhotoLayout,
postCount?: number,
+ fixedRows = false,
): PostPhotoLayout => {
const fullWidth =
previous?.fullWidth ??
@@ -34,7 +63,7 @@ export const postPhotoLayout = (
: undefined);
const rows: PhotoRow<PostPhotoTile>[] = [];
let retainedCount = 0;
- if (previous?.width == width) {
+ if (previous?.width == width && previous.fixedRows == fixedRows) {
for (const row of previous.rows) {
if (
!row.tiles.every(
@@ -51,9 +80,66 @@ export const postPhotoLayout = (
rows.push(
...(fullWidth
? remaining.flatMap((tile) => profilePhotoRows([tile], width))
- : profilePhotoRows(remaining, width)),
+ : fixedRows
+ ? fixedPhotoRows(remaining, width, rows.length)
+ : profilePhotoRows(remaining, width)),
);
- return { width, fullWidth, rows };
+ return { width, fixedRows, fullWidth, rows };
+};
+
+const fixedPhotoRows = (
+ tiles: PostPhotoTile[],
+ width: number,
+ startRow: number,
+) => {
+ const rows: PhotoRow<PostPhotoTile>[] = [];
+ if (width <= 0) return rows;
+
+ const minTileWidth = Math.min(fixedPhotoMinTileWidth, width);
+ const maxRowSize = Math.floor(
+ (width + profilePhotoGap) / (minTileWidth + profilePhotoGap),
+ );
+ for (let index = 0; index < tiles.length; ) {
+ const pattern =
+ fixedRowPattern[(startRow + rows.length) % fixedRowPattern.length]!;
+ const rowSize = Math.min(
+ pattern.weights.length,
+ maxRowSize,
+ tiles.length - index,
+ );
+ const weights = pattern.weights.slice(0, rowSize);
+ const totalWeight = weights.reduce((sum, weight) => sum + weight, 0);
+ const availableWidth = width - (rowSize - 1) * profilePhotoGap;
+ const extraWidths = weights.map((weight) =>
+ Math.max(0, (availableWidth * weight) / totalWeight - minTileWidth),
+ );
+ const totalExtraWidth = extraWidths.reduce(
+ (sum, extra) => sum + extra,
+ 0,
+ );
+ const remainingWidth = availableWidth - rowSize * minTileWidth;
+ const height = width * pattern.heightRatio;
+ const aspectRatio = availableWidth / height;
+ rows.push({
+ aspectRatio,
+ height,
+ width,
+ tiles: tiles
+ .slice(index, index + rowSize)
+ .map((tile, tileIndex) => ({
+ ...tile,
+ aspectRatio:
+ (minTileWidth +
+ (totalExtraWidth > 0
+ ? (remainingWidth * extraWidths[tileIndex]!) /
+ totalExtraWidth
+ : 0)) /
+ height,
+ })),
+ });
+ index += rowSize;
+ }
+ return rows;
};
const profilePhotoRows = <Tile extends { aspectRatio: number }>(
diff --git a/web/apps/space/tests/profile-photo-layout.test.ts b/web/apps/space/tests/profile-photo-layout.test.ts
index 8ef3c89e0e..5e8a6cbcaf 100644
--- a/web/apps/space/tests/profile-photo-layout.test.ts
+++ b/web/apps/space/tests/profile-photo-layout.test.ts
@@ -287,3 +287,193 @@ test("resizing recalculates rows to fit the new width", () => {
expect(next.rows).toEqual(postPhotoLayout(tiles, 600).rows);
expect(next.rows).not.toEqual(initial.rows);
});
+
+test.each([288, 328, 358])(
+ "fixed rows fill a %ipx grid independently of photo dimensions",
+ (width) => {
+ const tiles = photos(
+ Array.from({ length: 80 }, (_, index) =>
+ index % 2 == 0 ? 8 : 0.1,
+ ),
+ );
+ const layout = postPhotoLayout(
+ tiles,
+ width,
+ undefined,
+ undefined,
+ true,
+ );
+ const squareLayout = postPhotoLayout(
+ tiles.map((tile) => ({ ...tile, aspectRatio: 1 })),
+ width,
+ undefined,
+ undefined,
+ true,
+ );
+ expect(layout).toEqual(squareLayout);
+ const rowSizes = new Set(layout.rows.map((row) => row.tiles.length));
+ expect(rowSizes).toEqual(new Set(width < 312 ? [1, 2] : [1, 2, 3]));
+ expect(
+ layout.rows.flatMap((row) => row.tiles.map((tile) => tile.id)),
+ ).toEqual(tiles.map((tile) => tile.id));
+ for (const rowSize of rowSizes) {
+ const heights = layout.rows
+ .filter((row) => row.tiles.length == rowSize)
+ .map((row) => row.height);
+ expect(new Set(heights).size).toBeGreaterThan(3);
+ expect(Math.max(...heights) / Math.min(...heights)).toBeGreaterThan(
+ 1.25,
+ );
+ }
+ for (const row of layout.rows) {
+ expect(row.width).toBe(width);
+ expect(row.height).toBeGreaterThan(0);
+ expect(
+ new Set(row.tiles.map((tile) => tile.aspectRatio)).size,
+ ).toBeGreaterThanOrEqual(row.tiles.length > 1 ? 2 : 1);
+ if (row.tiles.length == 3) {
+ for (const tile of row.tiles) {
+ expect(tile.aspectRatio).toBeGreaterThan(0.7);
+ expect(tile.aspectRatio).toBeLessThan(1.5);
+ }
+ }
+ expect(
+ row.tiles.reduce(
+ (sum, tile) => sum + tile.aspectRatio * row.height,
+ (row.tiles.length - 1) * profilePhotoGap,
+ ),
+ ).toBeCloseTo(width);
+ }
+ },
+);
+
+test.each([99, 100, 205, 206, 288, 311, 312, 328, 358, 600])(
+ "fixed rows respect the minimum tile width and fill a %ipx grid",
+ (width) => {
+ const tiles = photos(new Array<number>(80).fill(1));
+ const layout = postPhotoLayout(
+ tiles,
+ width,
+ undefined,
+ undefined,
+ true,
+ );
+ expect(Math.max(...layout.rows.map((row) => row.tiles.length))).toBe(
+ width < 206 ? 1 : width < 312 ? 2 : 3,
+ );
+ expect(
+ layout.rows.flatMap((row) => row.tiles.map((tile) => tile.id)),
+ ).toEqual(tiles.map((tile) => tile.id));
+ for (const row of layout.rows) {
+ const tileWidths = row.tiles.map(
+ (tile) => tile.aspectRatio * row.height,
+ );
+ for (const tileWidth of tileWidths) {
+ expect(tileWidth).toBeGreaterThanOrEqual(
+ Math.min(width, 100) - 0.000001,
+ );
+ }
+ expect(
+ tileWidths.reduce(
+ (sum, tileWidth) => sum + tileWidth,
+ (row.tiles.length - 1) * profilePhotoGap,
+ ),
+ ).toBeCloseTo(width);
+ }
+ },
+);
+
+test.each([
+ { initialCount: 1, lastRowSize: 1, nextRowSize: 3 },
+ { initialCount: 3, lastRowSize: 1, nextRowSize: 2 },
+ { initialCount: 4, lastRowSize: 2, nextRowSize: 2 },
+])(
+ "a partial row after $initialCount photos stays filled and frozen when more arrive",
+ ({ initialCount, lastRowSize, nextRowSize }) => {
+ const tiles = photos(new Array<number>(30).fill(1));
+ const initial = postPhotoLayout(
+ tiles.slice(0, initialCount),
+ 358,
+ undefined,
+ undefined,
+ true,
+ );
+ expect(initial.rows.at(-1)!.tiles).toHaveLength(lastRowSize);
+ expect(initial.rows.at(-1)!.width).toBe(358);
+ expect(initial.rows.flatMap((row) => row.tiles)).toHaveLength(
+ initialCount,
+ );
+
+ const appended = postPhotoLayout(tiles, 358, initial, 30, true);
+ initial.rows.forEach((row, index) => {
+ expect(appended.rows[index]).toBe(row);
+ });
+ expect(appended.rows[initial.rows.length]!.tiles).toHaveLength(
+ nextRowSize,
+ );
+ expect(
+ appended.rows.flatMap((row) => row.tiles.map((tile) => tile.id)),
+ ).toEqual(tiles.map((tile) => tile.id));
+ },
+);
+
+test("fixed rows retain their dimensions and pattern position across feed pages", () => {
+ const tiles = photos(new Array<number>(90).fill(3 / 2));
+ let layout = postPhotoLayout([], 358, undefined, undefined, true);
+ for (let count = 20; count <= tiles.length; count += 10) {
+ const next = postPhotoLayout(
+ tiles.slice(0, count),
+ 358,
+ layout,
+ count == tiles.length ? count : undefined,
+ true,
+ );
+ layout.rows.forEach((row, index) => {
+ expect(next.rows[index]).toBe(row);
+ });
+ expect(
+ next.rows.flatMap((row) => row.tiles.map((tile) => tile.id)),
+ ).toEqual(tiles.slice(0, count).map((tile) => tile.id));
+ expect(next.rows.every((row) => row.width == 358)).toBe(true);
+ layout = next;
+ }
+});
+
+test.each([1, 2, 3, 4, 5, 6, 7])(
+ "fixed rows preserve the existing layout for a complete collection of %i posts",
+ (count) => {
+ const tiles = photos([16 / 9, 3 / 4, 1, 9 / 16, 2, 0.3, 1.5]).slice(
+ 0,
+ count,
+ );
+ const layout = postPhotoLayout(tiles, 358, undefined, count, true);
+ expect(layout.fullWidth).toBe(true);
+ expect(layout.rows).toEqual(
+ postPhotoLayout(tiles, 358, undefined, count).rows,
+ );
+ },
+);
+
+test("a small collection does not switch to fixed rows during the same visit", () => {
+ const tiles = photos(new Array<number>(8).fill(3 / 4));
+ const initial = postPhotoLayout(tiles.slice(0, 7), 358, undefined, 7, true);
+ const appended = postPhotoLayout(tiles, 358, initial, 8, true);
+ expect(appended.fullWidth).toBe(true);
+ initial.rows.forEach((row, index) => {
+ expect(appended.rows[index]).toBe(row);
+ });
+ expect(appended.rows.every((row) => row.tiles.length == 1)).toBe(true);
+ const reopened = postPhotoLayout(tiles, 358, undefined, 8, true);
+ expect(reopened.fullWidth).toBe(false);
+ expect(reopened.rows.some((row) => row.tiles.length > 1)).toBe(true);
+});
+
+test("late photo dimensions do not change fixed rows", () => {
+ const tiles = photos(new Array<number>(20).fill(1));
+ const initial = postPhotoLayout(tiles, 358, undefined, undefined, true);
+ const changed = tiles.map((tile) => ({ ...tile, aspectRatio: 0.1 }));
+ const next = postPhotoLayout(changed, 358, initial, undefined, true);
+ initial.rows.forEach((row, index) => {
+ expect(next.rows[index]).toBe(row);
+ });
+});