Skip to content

armgit / ente

Public Imported from GitHub
0

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

Open seen and own Space post tiles at the latest profile section

Anand Baburajanc91f28420755
diff --git a/web/apps/space/src/components/AuthenticatedFriendProfile.tsx b/web/apps/space/src/components/AuthenticatedFriendProfile.tsx
index 3d32ff8179..1508e7e693 100644
--- a/web/apps/space/src/components/AuthenticatedFriendProfile.tsx
+++ b/web/apps/space/src/components/AuthenticatedFriendProfile.tsx
@@ -39,6 +39,8 @@ export const AuthenticatedFriendProfile: React.FC<
AuthenticatedFriendProfileProps
> = ({ friendSpaceId, username }) => {
const router = useSpaceRouter();
+ const initialSection =
+ router.query.section == "latest" ? "latest" : undefined;
const { friends, profile, profileLoadError, profileLoadStatus } =
useSpaceAppState();
const [friendProfile, setFriendProfile] =
@@ -152,7 +154,8 @@ export const AuthenticatedFriendProfile: React.FC<
);
}
if (
- !hadCachedFriendProfileOnMount.current &&
+ (!hadCachedFriendProfileOnMount.current ||
+ initialSection == "latest") &&
(isProfileLoading || isPostsLoading)
) {
return <SpaceRouteFallback background={spaceAppBackgroundColor} />;
@@ -165,6 +168,7 @@ export const AuthenticatedFriendProfile: React.FC<
<ProfileScreen
friendsCount={displayedProfile.friendsCount}
headerVariant="friend"
+ initialSection={initialSection}
isCoverLoading={isProfileLoading}
isNameLoading={isProfileLoading && !immediateFriendProfile}
isPostsLoading={isPostsLoading}
diff --git a/web/apps/space/src/components/OwnPostTile.tsx b/web/apps/space/src/components/OwnPostTile.tsx
index 0456cafbd0..22ee31541c 100644
--- a/web/apps/space/src/components/OwnPostTile.tsx
+++ b/web/apps/space/src/components/OwnPostTile.tsx
@@ -106,7 +106,7 @@ interface SpaceOwnPostTileProps {
isUnavailable?: boolean;
isNewPostDisabled?: boolean;
onLoadPostImage?: SpacePostAssetURLLoader;
- onOpenPost?: (imageUrl: string) => void;
+ onOpenPost?: () => void;
onOpenProfile?: () => void;
onNewPost: () => void;
}
@@ -145,10 +145,7 @@ export const SpaceOwnPostTile: React.FC<SpaceOwnPostTileProps> = ({
const unavailable =
isUnavailable || post?.isUnavailable || postImage?.failed;
const canOpenPost = Boolean(
- imageUrl &&
- !unavailable &&
- onOpenPost &&
- (!publishPhase || publishPhase == "posted"),
+ post && onOpenPost && (!publishPhase || publishPhase == "posted"),
);
const loading =
isLoading || Boolean(post?.imageAsset && !imageUrl && !unavailable);
@@ -202,7 +199,7 @@ export const SpaceOwnPostTile: React.FC<SpaceOwnPostTileProps> = ({
type="button"
aria-label="Open your posts"
disabled={!canOpenPost}
- onClick={() => imageUrl && onOpenPost?.(imageUrl)}
+ onClick={onOpenPost}
sx={{
appearance: "none",
bgcolor: "transparent",
diff --git a/web/apps/space/src/pages/app/index.tsx b/web/apps/space/src/pages/app/index.tsx
index 7381fc88d2..6b0858c034 100644
--- a/web/apps/space/src/pages/app/index.tsx
+++ b/web/apps/space/src/pages/app/index.tsx
@@ -347,7 +347,7 @@ const Page: React.FC = () => {
}
onDeletePost={deleteOwnPost}
onUpdatePostCaption={updateOwnPostCaption}
- onOpenFriend={(friendID, username) => {
+ onOpenFriend={(friendID, username, section) => {
const friend = friends.find(
(candidate) =>
candidate.id == friendID ||
@@ -355,9 +355,11 @@ const Page: React.FC = () => {
);
const friendUsername = username || friend?.username;
if (friendUsername) {
+ const query = section ? "?section=latest" : "";
void router.push(
- spaceRoutes.friendPage,
- spaceRoutes.friend(friendUsername),
+ `${spaceRoutes.friendPage}${query}`,
+ `${spaceRoutes.friend(friendUsername)}${query}`,
+ { scroll: section != "latest" },
);
}
}}
@@ -425,6 +427,13 @@ const Page: React.FC = () => {
);
await refreshUnreadStatus(profile.spaceId);
}}
+ onOpenOwnPost={() =>
+ void router.push(
+ `${spaceRoutes.profile}?section=latest`,
+ undefined,
+ { scroll: false },
+ )
+ }
onOpenProfile={
profile
? () => void router.push(spaceRoutes.profile)
diff --git a/web/apps/space/src/pages/app/profile.tsx b/web/apps/space/src/pages/app/profile.tsx
index b4ce4e9fd6..e68b34c9a3 100644
--- a/web/apps/space/src/pages/app/profile.tsx
+++ b/web/apps/space/src/pages/app/profile.tsx
@@ -23,6 +23,8 @@ const initialPostLoadingIndicatorDelayMs = 350;
const Page: React.FC = () => {
const router = useSpaceRouter();
+ const initialSection =
+ router.query.section == "latest" ? "latest" : undefined;
const {
profile,
profileLoadError,
@@ -96,7 +98,11 @@ const Page: React.FC = () => {
return () => window.clearTimeout(timeoutID);
}, [isInitialPostsLoading]);
- if (profileLoadStatus != "ready" || !profile) {
+ if (
+ profileLoadStatus != "ready" ||
+ !profile ||
+ (initialSection == "latest" && isPostsLoading)
+ ) {
return (
<SpaceRouteFallback
background={spaceAppBackgroundColor}
@@ -119,6 +125,7 @@ const Page: React.FC = () => {
<SpacePageMeta themeColor={spaceAppBackgroundColor} />
<ProfileScreen
friendsCount={friendsCount}
+ initialSection={initialSection}
isPostsLoading={isPostsLoading}
isStatsLoading={isPostsLoading}
postItems={postItems}
diff --git a/web/apps/space/src/screens/HomeScreen.tsx b/web/apps/space/src/screens/HomeScreen.tsx
index d928a832a9..ec729605f4 100644
--- a/web/apps/space/src/screens/HomeScreen.tsx
+++ b/web/apps/space/src/screens/HomeScreen.tsx
@@ -104,11 +104,16 @@ interface HomeScreenProps {
onAcceptFriendRequest?: (requestID: number) => Promise<void>;
onAddFriend: () => void;
onDiscardFriendRequest?: (requestID: number) => Promise<void>;
- onOpenFriend?: (friendID: string, username?: string) => void;
+ onOpenFriend?: (
+ friendID: string,
+ username?: string,
+ section?: "latest",
+ ) => void;
onOpenFriendRequests?: () => void;
onOpenMessages?: () => void;
onMessageFriend: (friend: FriendProfile) => void;
onPokeFriend: (friend: FriendProfile) => Promise<void>;
+ onOpenOwnPost?: () => void;
onOpenProfile?: () => void;
onReplyToPost?: (
postSpaceId: string,
@@ -269,7 +274,7 @@ interface FriendPostTileProps {
onLoadImage?: () => Promise<string | undefined>;
onAcceptFriendRequest?: () => Promise<void>;
onDiscardFriendRequest?: () => Promise<void>;
- onOpenFriend?: (friendID: string, username?: string) => void;
+ onOpenFriend?: HomeScreenProps["onOpenFriend"];
onOpenAvatar?: (anchorRect: DOMRect) => void;
onOpenFriendRequest?: () => void;
onOpenPosts: (
@@ -344,7 +349,7 @@ export const FriendPostTile: React.FC<FriendPostTileProps> = ({
isLoading ||
isFriendRequestActionBusy ||
(isRequestPending && !canOpenFriendRequest) ||
- Boolean(post && !postUnavailable && !isPhotoReady);
+ Boolean(post && !isRead && !postUnavailable && !isPhotoReady);
const tileSize = Math.min(placement.width, placement.height);
const tileRadius = Math.min(spacePostTileRadius, tileSize * 0.2);
const avatarSize = spaceTileAvatarSize(placement);
@@ -428,6 +433,10 @@ export const FriendPostTile: React.FC<FriendPostTileProps> = ({
onOpenFriend?.(friend.id, friend.username);
return;
}
+ if (isRead) {
+ onOpenFriend?.(friend.id, friend.username, "latest");
+ return;
+ }
if (!canOpenPost || !displayImageUrl) return;
onOpenPosts(friend, posts, {
@@ -1011,6 +1020,7 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
onOpenMessages,
onMessageFriend,
onPokeFriend,
+ onOpenOwnPost,
onOpenProfile,
onReplyToPost,
onSetPostLiked,
@@ -1770,25 +1780,7 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
onLoadPostImage={onLoadPostImage}
onNewPost={openPostPhotoPicker}
onOpenProfile={onOpenProfile}
- onOpenPost={(imageUrl) => {
- if (!ownLatestPost || !profile) return;
-
- const self = {
- ...profile,
- id: ownLatestPost.spaceId,
- friendsCount: friends.length,
- };
- openPostPhotos(
- self,
- [ownLatestPost],
- viewerPhotoForPost(
- ownLatestPost,
- self,
- profile.avatarUrl,
- imageUrl,
- ),
- );
- }}
+ onOpenPost={onOpenOwnPost}
/>
</Box>
{selectedContact && (
diff --git a/web/apps/space/src/screens/ProfileScreen.tsx b/web/apps/space/src/screens/ProfileScreen.tsx
index 786f8bfc2e..bb1277a789 100644
--- a/web/apps/space/src/screens/ProfileScreen.tsx
+++ b/web/apps/space/src/screens/ProfileScreen.tsx
@@ -492,6 +492,7 @@ const ProfilePostTile: React.FC<ProfilePostTileProps> = ({
interface ProfileScreenProps {
friendsCount?: number;
headerVariant?: "friend" | "owner" | "public" | "public-anonymous";
+ initialSection?: "latest";
isAddingFriend?: boolean;
showAddingFriendSpinner?: boolean;
isCoverLoading?: boolean;
@@ -535,6 +536,7 @@ interface ProfileScreenProps {
export const ProfileScreen: React.FC<ProfileScreenProps> = ({
friendsCount = 0,
headerVariant = "owner",
+ initialSection,
isAddingFriend = false,
isCoverLoading = false,
isNameLoading = false,
@@ -597,6 +599,7 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
const [loadedCoverUrl, setLoadedCoverUrl] = useState<string | null>(null);
const [postGridWidth, setPostGridWidth] = useState(0);
const postGridRef = React.useRef<HTMLDivElement | null>(null);
+ const hasScrolledToLatestPost = React.useRef(false);
const postInputRef = React.useRef<HTMLInputElement | null>(null);
const postImageLoadsInFlightRef = React.useRef<
Map<string, Promise<string | undefined>>
@@ -650,6 +653,23 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
observer.observe(grid);
return () => observer.disconnect();
}, [hasProfilePosts]);
+ React.useLayoutEffect(() => {
+ if (
+ initialSection != "latest" ||
+ !postGridWidth ||
+ hasScrolledToLatestPost.current
+ ) {
+ return;
+ }
+ const grid = postGridRef.current;
+ if (!grid) return;
+
+ window.scrollTo({
+ top: window.scrollY + grid.getBoundingClientRect().top - 16,
+ behavior: "instant",
+ });
+ hasScrolledToLatestPost.current = true;
+ }, [initialSection, postGridWidth]);
const shouldShowPostLoadingIndicator =
isPostsLoading && (showPostLoadingIndicator ?? true);
const isCoverImageLoading = Boolean(
@@ -1875,7 +1895,11 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
display: "flex",
flex: hasProfilePosts ? "0 0 auto" : "1 1 0",
flexDirection: "column",
- minHeight: hasProfilePosts ? undefined : 0,
+ minHeight: hasProfilePosts
+ ? initialSection == "latest"
+ ? "100svh"
+ : undefined
+ : 0,
mt: "24px",
pb: "16px",
px: 0,