Skip to content

armgit / ente

Public Imported from GitHub
0

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

Open friend profile photos

Anand Baburajan16000fba4f4d
diff --git a/web/apps/space/src/pages/app/friends/[spaceId].tsx b/web/apps/space/src/pages/app/friends/[spaceId].tsx
index 57d3ee3f90..9857a9969a 100644
--- a/web/apps/space/src/pages/app/friends/[spaceId].tsx
+++ b/web/apps/space/src/pages/app/friends/[spaceId].tsx
@@ -1,7 +1,12 @@
import { SpacePageMeta } from "components/SpacePageMeta";
import { SpaceRouteFallback } from "components/SpaceRouteFallback";
+import { useBrowserBackClose } from "hooks/useBrowserBackClose";
import React, { useEffect, useMemo, useState } from "react";
import { friendsBackground } from "screens/FriendsScreen";
+import {
+ FriendProfileImageViewerScreen,
+ friendProfileImageViewerBackground,
+} from "screens/ProfileImageViewerScreen";
import { ProfileScreen } from "screens/ProfileScreen";
import {
loadCurrentSpaceFriends,
@@ -47,6 +52,7 @@ const Page: React.FC = () => {
const [friendsLoadAttempted, setFriendsLoadAttempted] = useState(false);
const [isProfileLoading, setIsProfileLoading] = useState(false);
const [isPostsLoading, setIsPostsLoading] = useState(false);
+ const [isProfilePhotoOpen, setIsProfilePhotoOpen] = useState(false);
const [loadedProfileSpaceId, setLoadedProfileSpaceId] = useState<string>();
const [loadedPostsSpaceId, setLoadedPostsSpaceId] = useState<string>();
const [selectedProfile, setSelectedProfile] = useState(selectedFriend);
@@ -73,6 +79,20 @@ const Page: React.FC = () => {
selectedProfile?.spaceId == selectedFriendSpaceId
? selectedProfile
: undefined;
+ const friendAvatarUrl =
+ currentSelectedProfile?.avatarUrl ?? selectedFriend?.avatarUrl ?? null;
+ const friendDisplayName =
+ currentSelectedProfile?.fullName.trim() ||
+ selectedFriend?.fullName.trim() ||
+ currentSelectedProfile?.username.trim() ||
+ selectedFriend?.username.trim() ||
+ "Friend";
+
+ useBrowserBackClose({
+ open: isProfilePhotoOpen,
+ onClose: () => setIsProfilePhotoOpen(false),
+ stateKey: "space-friend-profile-photo",
+ });
useEffect(() => {
if (!router.isReady) return;
@@ -236,6 +256,11 @@ const Page: React.FC = () => {
}}
onBack={goBack}
onLoadPostImage={loadCurrentSpacePostAssetURL}
+ onOpenProfilePhoto={
+ friendAvatarUrl
+ ? () => setIsProfilePhotoOpen(true)
+ : undefined
+ }
onReplyToPost={(postSpaceId, postId, text) =>
replyToCurrentPost(actorSpaceId, postSpaceId, postId, text)
}
@@ -244,6 +269,18 @@ const Page: React.FC = () => {
}
showPostLoadingIndicator={false}
/>
+ {isProfilePhotoOpen && friendAvatarUrl && (
+ <>
+ <SpacePageMeta
+ themeColor={friendProfileImageViewerBackground}
+ />
+ <FriendProfileImageViewerScreen
+ displayName={friendDisplayName}
+ imageUrl={friendAvatarUrl}
+ onClose={() => setIsProfilePhotoOpen(false)}
+ />
+ </>
+ )}
</>
);
};
diff --git a/web/apps/space/src/screens/ProfileImageViewerScreen.tsx b/web/apps/space/src/screens/ProfileImageViewerScreen.tsx
index 478c536121..ec7167061d 100644
--- a/web/apps/space/src/screens/ProfileImageViewerScreen.tsx
+++ b/web/apps/space/src/screens/ProfileImageViewerScreen.tsx
@@ -1,9 +1,9 @@
-import { ArrowLeft02Icon } from "@hugeicons/core-free-icons";
+import { ArrowLeft02Icon, Cancel01Icon } from "@hugeicons/core-free-icons";
import { HugeiconsIcon } from "@hugeicons/react";
import { Box, Skeleton } from "@mui/material";
import { spaceAppAvatarCropSize } from "components/SpaceAvatarCropPage";
import { SpaceAvatarImage } from "components/SpaceAvatarImage";
-import React, { useRef } from "react";
+import React, { useEffect, useRef } from "react";
import type { SetupProfile } from "screens/SetupProfileScreen";
import { spaceTouchTargetSize } from "styles/touchTargets";
import {
@@ -18,6 +18,100 @@ const textBase = "#000";
const profileBackground = "#FFFFFF";
const profileCoverBackground = "#1F1F1F";
const profileAvatarSkeletonBackground = "#E6E6E6";
+export const friendProfileImageViewerBackground = "#000000";
+
+interface FriendProfileImageViewerScreenProps {
+ displayName: string;
+ imageUrl: string;
+ onClose: () => void;
+}
+
+export const FriendProfileImageViewerScreen: React.FC<
+ FriendProfileImageViewerScreenProps
+> = ({ displayName, imageUrl, onClose }) => {
+ useEffect(() => {
+ const previousOverflow = document.body.style.overflow;
+ document.body.style.overflow = "hidden";
+
+ const closeOnEscape = (event: KeyboardEvent) => {
+ if (event.key == "Escape") onClose();
+ };
+ window.addEventListener("keydown", closeOnEscape);
+
+ return () => {
+ document.body.style.overflow = previousOverflow;
+ window.removeEventListener("keydown", closeOnEscape);
+ };
+ }, [onClose]);
+
+ return (
+ <Box
+ role="dialog"
+ aria-label={`${displayName} profile picture`}
+ aria-modal="true"
+ onClick={onClose}
+ sx={{
+ alignItems: "center",
+ bgcolor: friendProfileImageViewerBackground,
+ display: "flex",
+ inset: 0,
+ justifyContent: "center",
+ overflow: "hidden",
+ position: "fixed",
+ zIndex: 1300,
+ }}
+ >
+ <Box
+ component="img"
+ alt={`${displayName}'s profile picture`}
+ src={imageUrl}
+ onClick={(event) => event.stopPropagation()}
+ sx={{
+ aspectRatio: "1 / 1",
+ borderRadius: "50%",
+ display: "block",
+ objectFit: "cover",
+ width: "min(calc(100vw - 48px), calc(100svh - 112px), 512px)",
+ }}
+ />
+ <Box
+ component="button"
+ type="button"
+ aria-label="Close profile picture"
+ autoFocus
+ onClick={(event) => {
+ event.stopPropagation();
+ onClose();
+ }}
+ sx={{
+ alignItems: "center",
+ bgcolor: "transparent",
+ border: 0,
+ color: "#D8D8D8",
+ cursor: "pointer",
+ display: "flex",
+ height: spaceTouchTargetSize,
+ justifyContent: "center",
+ p: 0,
+ position: "absolute",
+ right: "max(4px, env(safe-area-inset-right))",
+ top: "calc(2px + env(safe-area-inset-top))",
+ width: spaceTouchTargetSize,
+ "&:focus-visible": {
+ outline: `2px solid ${green}`,
+ outlineOffset: 2,
+ },
+ }}
+ >
+ <HugeiconsIcon
+ icon={Cancel01Icon}
+ size={18}
+ strokeWidth={1.8}
+ />
+ </Box>
+ </Box>
+ );
+};
interface ProfileImageViewerScreenProps {
onBack: () => void;
diff --git a/web/apps/space/src/screens/ProfileScreen.tsx b/web/apps/space/src/screens/ProfileScreen.tsx
index b53e782cde..98f4dfb2ae 100644
--- a/web/apps/space/src/screens/ProfileScreen.tsx
+++ b/web/apps/space/src/screens/ProfileScreen.tsx
@@ -621,7 +621,7 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
);
const canOpenFriends = isOwnerProfile && Boolean(onOpenFriends);
const canOpenProfileCover = isOwnerProfile && Boolean(onOpenProfileCover);
- const canOpenProfilePhoto = isOwnerProfile && Boolean(onOpenProfilePhoto);
+ const canOpenProfilePhoto = Boolean(onOpenProfilePhoto);
const hasProfilePosts = postsSharedCount > 0;
const shouldShowPostLoadingIndicator =
isPostsLoading && (showPostLoadingIndicator ?? true);