Skip to content

armgit / ente

Public Imported from GitHub
0

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

Remove profile post date grouping

Anand Baburajan8ae547c3509b
diff --git a/web/apps/space/src/components/AuthenticatedFriendProfile.tsx b/web/apps/space/src/components/AuthenticatedFriendProfile.tsx
index b95d8f31dd..b321dfd534 100644
--- a/web/apps/space/src/components/AuthenticatedFriendProfile.tsx
+++ b/web/apps/space/src/components/AuthenticatedFriendProfile.tsx
@@ -24,7 +24,7 @@ import {
removeCachedSpaceFeedPostsBySpace,
} from "services/spaceFeedCache";
import { useSpaceAppState } from "state/spaceAppState";
-import { profilePostGroupsFromPosts } from "utils/spacePostDisplay";
+import { profilePostItemsFromPosts } from "utils/spacePostDisplay";
import { spaceDefaultCoverImagePath } from "utils/spacePostImage";
import { spaceRoutes } from "utils/spaceRoutes";
import {
@@ -51,8 +51,8 @@ export const AuthenticatedFriendProfile: React.FC<
const [openProfileImage, setOpenProfileImage] = React.useState<
"avatar" | "cover" | null
>(null);
- const postGroups = React.useMemo(
- () => profilePostGroupsFromPosts(posts),
+ const postItems = React.useMemo(
+ () => profilePostItemsFromPosts(posts),
[posts],
);
const cachedFriendProfile = friends.find(
@@ -191,7 +191,7 @@ export const AuthenticatedFriendProfile: React.FC<
onUnfriendComplete={() =>
window.location.replace(spaceRoutes.friends)
}
- postGroups={postGroups}
+ postItems={postItems}
profile={displayedProfile}
showPostLoadingIndicator={false}
/>
diff --git a/web/apps/space/src/pages/app/profile.tsx b/web/apps/space/src/pages/app/profile.tsx
index 6bca1de193..615df266e8 100644
--- a/web/apps/space/src/pages/app/profile.tsx
+++ b/web/apps/space/src/pages/app/profile.tsx
@@ -26,7 +26,7 @@ import {
createLocalFeedPostID,
failLocalFeedPost,
} from "utils/localFeedPost";
-import { profilePostGroupsFromPosts } from "utils/spacePostDisplay";
+import { profilePostItemsFromPosts } from "utils/spacePostDisplay";
import { prepareSpacePostImageFromEdit } from "utils/spacePostImage";
import { spaceRoutes } from "utils/spaceRoutes";
import { useSpaceRouter } from "utils/spaceRouteTransitions";
@@ -44,10 +44,7 @@ const Page: React.FC = () => {
showInitialPostLoadingIndicator,
setShowInitialPostLoadingIndicator,
] = useState(false);
- const postGroups = useMemo(
- () => profilePostGroupsFromPosts(posts),
- [posts],
- );
+ const postItems = useMemo(() => profilePostItemsFromPosts(posts), [posts]);
const isInitialPostsLoading =
profileLoadStatus == "ready" &&
Boolean(profile?.spaceId) &&
@@ -131,7 +128,7 @@ const Page: React.FC = () => {
friendsCount={friendsCount}
isPostsLoading={isPostsLoading}
isStatsLoading={isPostsLoading}
- postGroups={postGroups}
+ postItems={postItems}
profile={profile}
showPostLoadingIndicator={showInitialPostLoadingIndicator}
onBack={() => void router.push(spaceRoutes.home)}
diff --git a/web/apps/space/src/pages/index.tsx b/web/apps/space/src/pages/index.tsx
index 66a5b84e39..a76ec07f64 100644
--- a/web/apps/space/src/pages/index.tsx
+++ b/web/apps/space/src/pages/index.tsx
@@ -37,7 +37,7 @@ import {
useSpaceAppState,
type OnboardingEntrySource,
} from "state/spaceAppState";
-import { profilePostGroupsFromPosts } from "utils/spacePostDisplay";
+import { profilePostItemsFromPosts } from "utils/spacePostDisplay";
import { spaceRoutes } from "utils/spaceRoutes";
import { useSpaceRouter } from "utils/spaceRouteTransitions";
@@ -333,8 +333,8 @@ export const Page: React.FC<PageProps> = ({ invitePreview }) => {
const [pendingInviteIntent, setPendingInviteIntent] =
useState<SpaceInviteIntent>();
const [isAddingFriend, setIsAddingFriend] = useState(false);
- const publicPostGroups = useMemo(
- () => profilePostGroupsFromPosts(publicPosts),
+ const publicPostItems = useMemo(
+ () => profilePostItemsFromPosts(publicPosts),
[publicPosts],
);
@@ -652,7 +652,7 @@ export const Page: React.FC<PageProps> = ({ invitePreview }) => {
onBack={() => window.location.assign("/")}
onCreateSpace={createSpace}
onLoadPostImage={publicLink.loadPostImage}
- postGroups={publicPostGroups}
+ postItems={publicPostItems}
postsCount={publicLink.postsCount}
profile={publicLink.profile}
publicNotificationControl={
diff --git a/web/apps/space/src/screens/ProfileScreen.tsx b/web/apps/space/src/screens/ProfileScreen.tsx
index 1e8a12cde5..dfedc21a3d 100644
--- a/web/apps/space/src/screens/ProfileScreen.tsx
+++ b/web/apps/space/src/screens/ProfileScreen.tsx
@@ -92,11 +92,6 @@ export interface ProfilePostItem {
width?: number;
}
-export interface ProfilePostGroup {
- items: ProfilePostItem[];
- label: string;
-}
-
interface SelectedProfilePost {
draftFile?: File;
draftImageError?: string;
@@ -291,7 +286,6 @@ interface ProfilePostTileProps {
aspectRatio: number;
dimensions: ProfilePhotoDimensions;
displayName: string;
- groupLabel: string;
imageUrl?: string;
index: number;
isSingleItemRow: boolean;
@@ -308,7 +302,6 @@ const ProfilePostTile: React.FC<ProfilePostTileProps> = ({
aspectRatio,
dimensions,
displayName,
- groupLabel,
imageUrl,
index,
isSingleItemRow,
@@ -427,7 +420,7 @@ const ProfilePostTile: React.FC<ProfilePostTileProps> = ({
{!isUnavailable && imageUrl ? (
<Box
component="img"
- alt={`${groupLabel} post ${index + 1}`}
+ alt={`${displayName} post ${index + 1}`}
onLoad={(event) => {
setReadyImageUrl(imageUrl);
onRememberDimensions(item.id, event.currentTarget);
@@ -515,7 +508,7 @@ interface ProfileScreenProps {
onUnfriend?: () => Promise<void> | void;
onUnfriendComplete?: () => void;
onUpdatePostCaption?: (postId: number, caption: string) => Promise<void>;
- postGroups?: ProfilePostGroup[];
+ postItems?: ProfilePostItem[];
postsCount?: number;
profile: SetupProfile;
profileLink?: string;
@@ -548,7 +541,7 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
onUnfriend,
onUnfriendComplete,
onUpdatePostCaption,
- postGroups = [],
+ postItems = [],
postsCount,
profile,
profileLink,
@@ -609,13 +602,9 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
? undefined
: spaceDefaultCoverImagePath;
const firstName = firstNameFrom(displayName);
- const visiblePostGroups = postGroups
- .map((group) => ({
- ...group,
- items: group.items.filter((item) => !deletedPostIDs.has(item.id)),
- }))
- .filter((group) => group.items.length > 0);
- const visiblePostItems = visiblePostGroups.flatMap((group) => group.items);
+ const visiblePostItems = postItems.filter(
+ (item) => !deletedPostIDs.has(item.id),
+ );
const viewerPostItems = visiblePostItems.filter(
(item) =>
!item.isUnavailable &&
@@ -624,10 +613,7 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
const viewerPostIndexByID = new Map(
viewerPostItems.map((item, index) => [item.id, index]),
);
- const postsSharedCount = visiblePostGroups.reduce(
- (count, group) => count + group.items.length,
- 0,
- );
+ const postsSharedCount = visiblePostItems.length;
const displayedPostsCount = postsCount ?? postsSharedCount;
const canOpenFriends = isOwnerProfile && Boolean(onOpenFriends);
const canOpenProfileCover = Boolean(onOpenProfileCover);
@@ -647,6 +633,10 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
const postImageLoadRootMargin = isAnonymousPublicProfile
? publicPhotoMasonryLoadRootMargin
: photoMasonryLoadRootMargin;
+ const masonryRows = buildPostMasonryRows(
+ visiblePostItems,
+ loadedPhotoDimensionsByID,
+ );
const closeFriendActions = () => setFriendActionsAnchor(null);
@@ -1771,7 +1761,6 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
display: "flex",
flex: hasProfilePosts ? "0 0 auto" : "1 1 0",
flexDirection: "column",
- gap: "24px",
minHeight: hasProfilePosts ? undefined : 0,
mt: "24px",
pb: "16px",
@@ -1780,171 +1769,116 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
}}
>
{hasProfilePosts ? (
- visiblePostGroups.map((group) => {
- const masonryRows = buildPostMasonryRows(
- group.items,
- loadedPhotoDimensionsByID,
- );
-
- return (
- <Box
- component="section"
- key={group.label}
- sx={{ width: "100%" }}
- >
- <Box
- sx={{
- mb: "10px",
- px: "18px",
- width: "100%",
- }}
- >
- <Box
- component="h2"
- sx={{
- color: textStrong,
- fontFamily:
- '"Inter Variable", Inter, sans-serif',
- fontSize: 14,
- fontWeight: 650,
- letterSpacing: 0,
- lineHeight: "20px",
- m: 0,
- }}
- >
- {group.label}
- </Box>
- </Box>
+ <Box
+ sx={{
+ borderRadius: photoMasonryRadius,
+ display: "flex",
+ flexDirection: "column",
+ gap: photoMasonryGap,
+ mt: "6px",
+ mx: "16px",
+ overflow: "hidden",
+ width: "calc(100% - 32px)",
+ }}
+ >
+ {masonryRows.map((row, rowIndex) => {
+ const isSingleItemRow = row.tiles.length == 1;
+ return (
<Box
+ key={`row-${rowIndex}`}
sx={{
- borderRadius: photoMasonryRadius,
display: "flex",
- flexDirection: "column",
gap: photoMasonryGap,
- mx: "16px",
- overflow: "hidden",
- width: "calc(100% - 32px)",
+ aspectRatio: isSingleItemRow
+ ? undefined
+ : `${row.aspectRatio} / 1`,
+ width: "100%",
}}
>
- {masonryRows.map((row, rowIndex) => {
- const isSingleItemRow =
- row.tiles.length == 1;
- return (
- <Box
- key={`${group.label}-row-${rowIndex}`}
- sx={{
- display: "flex",
- gap: photoMasonryGap,
- aspectRatio:
+ {row.tiles.map(
+ ({
+ aspectRatio,
+ dimensions,
+ item,
+ index,
+ }) => {
+ const imageUrl =
+ loadedPostImageURLFor(item);
+ return (
+ <ProfilePostTile
+ key={`${item.id}-${index}`}
+ aspectRatio={
+ aspectRatio
+ }
+ dimensions={dimensions}
+ displayName={
+ displayName
+ }
+ imageUrl={imageUrl}
+ index={index}
+ isSingleItemRow={
isSingleItemRow
- ? undefined
- : `${row.aspectRatio} / 1`,
- width: "100%",
- }}
- >
- {row.tiles.map(
- ({
- aspectRatio,
- dimensions,
- item,
- index,
- }) => {
- const imageUrl =
- loadedPostImageURLFor(
- item,
+ }
+ isUnavailable={
+ Boolean(
+ item.isUnavailable,
+ ) ||
+ Boolean(
+ unavailablePostsByKey[
+ profilePostImageCacheKey(
+ item,
+ )
+ ],
+ )
+ }
+ item={item}
+ loadRootMargin={
+ postImageLoadRootMargin
+ }
+ onLoadImage={() =>
+ loadPostImage(item)
+ }
+ onImageDecodeError={() =>
+ setUnavailablePostsByKey(
+ (current) => ({
+ ...current,
+ [profilePostImageCacheKey(
+ item,
+ )]: true,
+ }),
+ )
+ }
+ onOpen={(
+ openedImageUrl,
+ ) => {
+ const postIndex =
+ viewerPostIndexByID.get(
+ item.id,
);
- return (
- <ProfilePostTile
- key={`${group.label}-${item.id}-${index}`}
- aspectRatio={
- aspectRatio
- }
- dimensions={
- dimensions
- }
- displayName={
- displayName
- }
- groupLabel={
- group.label
- }
- imageUrl={
- imageUrl
- }
- index={
- index
- }
- isSingleItemRow={
- isSingleItemRow
- }
- isUnavailable={
- Boolean(
- item.isUnavailable,
- ) ||
- Boolean(
- unavailablePostsByKey[
- profilePostImageCacheKey(
- item,
- )
- ],
- )
- }
- item={item}
- loadRootMargin={
- postImageLoadRootMargin
- }
- onLoadImage={() =>
- loadPostImage(
- item,
- )
- }
- onImageDecodeError={() =>
- setUnavailablePostsByKey(
- (
- current,
- ) => ({
- ...current,
- [profilePostImageCacheKey(
- item,
- )]:
- true,
- }),
- )
- }
- onOpen={(
- openedImageUrl,
- ) => {
- const postIndex =
- viewerPostIndexByID.get(
- item.id,
- );
- if (
- postIndex ==
- undefined
- )
- return;
- setSelectedPost(
- selectedPostForItem(
- item,
- postIndex,
- openedImageUrl,
- ),
- );
- }}
- onRememberDimensions={
- rememberLoadedPhotoDimensions
- }
- />
+ if (
+ postIndex ==
+ undefined
+ )
+ return;
+ setSelectedPost(
+ selectedPostForItem(
+ item,
+ postIndex,
+ openedImageUrl,
+ ),
);
- },
- )}
- </Box>
- );
- })}
+ }}
+ onRememberDimensions={
+ rememberLoadedPhotoDimensions
+ }
+ />
+ );
+ },
+ )}
</Box>
- </Box>
- );
- })
+ );
+ })}
+ </Box>
) : shouldShowPostLoadingIndicator ? (
<ProfilePostLoadingIndicator />
) : isPostsLoading ? null : (
diff --git a/web/apps/space/src/utils/spacePostDisplay.ts b/web/apps/space/src/utils/spacePostDisplay.ts
index 6468112124..a565b92478 100644
--- a/web/apps/space/src/utils/spacePostDisplay.ts
+++ b/web/apps/space/src/utils/spacePostDisplay.ts
@@ -1,44 +1,23 @@
-import type { ProfilePostGroup } from "screens/ProfileScreen";
+import type { ProfilePostItem } from "screens/ProfileScreen";
import type { SpaceProfilePost } from "services/space";
-const profilePostDateLabel = (timestampMs: number) => {
- const date = new Date(timestampMs);
- const today = new Date();
- const yesterday = new Date(today);
- yesterday.setDate(today.getDate() - 1);
- if (date.toDateString() == today.toDateString()) return "Today";
- if (date.toDateString() == yesterday.toDateString()) return "Yesterday";
- return date.toLocaleDateString(
- typeof navigator == "undefined" ? "en-US" : navigator.language,
- { day: "numeric", month: "short", weekday: "short" },
- );
-};
-
-export const profilePostGroupsFromPosts = (
+export const profilePostItemsFromPosts = (
posts: SpaceProfilePost[],
-): ProfilePostGroup[] => {
- const groups = new Map<string, ProfilePostGroup>();
- posts.forEach((post) => {
- const label = profilePostDateLabel(post.timestampMs);
- const group = groups.get(label) ?? { items: [], label };
- group.items.push({
- avatarUrl: post.avatarUrl,
- caption: post.caption,
- friendID: post.friendID,
- height: post.height,
- id: String(post.postId),
- imageAsset: post.imageAsset,
- imageUrl: post.imageUrl,
- isUnavailable: post.isUnavailable,
- name: post.name,
- postId: post.postId,
- spaceId: post.spaceId,
- timestampMs: post.timestampMs,
- thumbHash: post.thumbHash,
- viewerLiked: post.viewerLiked,
- width: post.width,
- });
- groups.set(label, group);
- });
- return [...groups.values()];
-};
+): ProfilePostItem[] =>
+ posts.map((post) => ({
+ avatarUrl: post.avatarUrl,
+ caption: post.caption,
+ friendID: post.friendID,
+ height: post.height,
+ id: String(post.postId),
+ imageAsset: post.imageAsset,
+ imageUrl: post.imageUrl,
+ isUnavailable: post.isUnavailable,
+ name: post.name,
+ postId: post.postId,
+ spaceId: post.spaceId,
+ timestampMs: post.timestampMs,
+ thumbHash: post.thumbHash,
+ viewerLiked: post.viewerLiked,
+ width: post.width,
+ }));