π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Use default profile picture for missing Space avatars
Anand Baburajanda45318ee7dc
diff --git a/web/apps/space/public/images/default-profile-pic.png b/web/apps/space/public/images/default-profile-pic.pngnew file mode 100644index 0000000000..6e69e613c2Binary files /dev/null and b/web/apps/space/public/images/default-profile-pic.png differdiff --git a/web/apps/space/src/components/SpaceAvatarImage.tsx b/web/apps/space/src/components/SpaceAvatarImage.tsxnew file mode 100644index 0000000000..35afca9431--- /dev/null+++ b/web/apps/space/src/components/SpaceAvatarImage.tsx@@ -0,0 +1,40 @@+import { Box } from "@mui/material";+import React from "react";++export const spaceDefaultProfilePicPath = "/images/default-profile-pic.png";++const avatarImageSx = {+ display: "block",+ height: "100%",+ objectFit: "cover",+ objectPosition: "center",+ width: "100%",+} as const;++interface SpaceAvatarImageProps {+ alt?: string;+ "aria-hidden"?: boolean;+ border?: string;+ borderRadius?: string | number;+ src?: string | null;+}++export const SpaceAvatarImage: React.FC<SpaceAvatarImageProps> = ({+ alt = "",+ "aria-hidden": ariaHidden,+ border,+ borderRadius,+ src,+}) => (+ <Box+ component="img"+ alt={alt}+ aria-hidden={ariaHidden}+ src={src || spaceDefaultProfilePicPath}+ sx={{+ ...avatarImageSx,+ ...(border ? { border } : {}),+ ...(borderRadius !== undefined ? { borderRadius } : {}),+ }}+ />+);diff --git a/web/apps/space/src/components/SpaceFileViewer.tsx b/web/apps/space/src/components/SpaceFileViewer.tsxindex 2651b3bac0..d69d27f5b3 100644--- a/web/apps/space/src/components/SpaceFileViewer.tsx+++ b/web/apps/space/src/components/SpaceFileViewer.tsx@@ -8,9 +8,10 @@ import {Tick02Icon,} from "@hugeicons/core-free-icons";import { HugeiconsIcon } from "@hugeicons/react";-import { Box, Menu, MenuItem, Skeleton } from "@mui/material";+import { Box, Menu, MenuItem } from "@mui/material";import { keyframes } from "@mui/material/styles";import { ConfirmationActionSheet } from "components/ConfirmationActionSheet";+import { SpaceAvatarImage } from "components/SpaceAvatarImage";import {spaceActionDoneDurationMs,type SpaceActionPhase,@@ -31,7 +32,6 @@ import { clampSpaceMessageText } from "utils/spaceMessageLimits";import type { SpaceImageCropArea } from "utils/spacePostImage";const green = "#08C225";-const avatarSkeletonBackground = "#E6E6E6";const textBase = "#F4F4F4";const viewerLikeCountText = "#D8D8D8";const textSecondary = "#A6A6A6";@@ -1025,37 +1025,13 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({><Boxsx={{- bgcolor: avatarSkeletonBackground,borderRadius: "50%",height: viewerHeaderAvatarSize,overflow: "hidden",width: viewerHeaderAvatarSize,}}>- {activePhoto.avatarUrl ? (- <Box- component="img"- alt=""- src={activePhoto.avatarUrl}- sx={{- display: "block",- height: "100%",- objectFit: "cover",- objectPosition: "center",- width: "100%",- }}- />- ) : (- <Skeleton- variant="circular"- sx={{- bgcolor: avatarSkeletonBackground,- height: "100%",- transform: "none",- width: "100%",- }}- />- )}+ <SpaceAvatarImage src={activePhoto.avatarUrl} /></Box></Box><Boxdiff --git a/web/apps/space/src/components/SpacePostLikersDialog.tsx b/web/apps/space/src/components/SpacePostLikersDialog.tsxindex c377613d30..251969afe1 100644--- a/web/apps/space/src/components/SpacePostLikersDialog.tsx+++ b/web/apps/space/src/components/SpacePostLikersDialog.tsx@@ -1,4 +1,5 @@import { Box, CircularProgress, Dialog, useMediaQuery } from "@mui/material";+import { SpaceAvatarImage } from "components/SpaceAvatarImage";import { SpaceBottomSheetTransition } from "components/SpaceBottomSheetTransition";import React from "react";import type { SpacePostLiker } from "services/space";@@ -210,20 +211,7 @@ const SpacePostLikerRow: React.FC<{width: 28,}}>- {profile.avatarUrl ? (- <Box- component="img"- alt=""- src={profile.avatarUrl}- sx={{- display: "block",- height: "100%",- objectFit: "cover",- objectPosition: "center",- width: "100%",- }}- />- ) : null}+ <SpaceAvatarImage src={profile.avatarUrl} /></Box><Boxsx={{diff --git a/web/apps/space/src/screens/FriendsScreen.tsx b/web/apps/space/src/screens/FriendsScreen.tsxindex b11280f7ba..0af070f675 100644--- a/web/apps/space/src/screens/FriendsScreen.tsx+++ b/web/apps/space/src/screens/FriendsScreen.tsx@@ -11,6 +11,7 @@ import {spaceActionDoneDurationMs,type SpaceActionPhase,} from "components/SpaceActionFeedback";+import { SpaceAvatarImage } from "components/SpaceAvatarImage";import { SpaceInviteFriendsDialog } from "components/SpaceInviteFriendsDialog";import type { FriendProfile } from "data/friends";import React, { useState } from "react";@@ -168,19 +169,8 @@ const FriendRow: React.FC<FriendRowProps> = ({width: 48,}}>- {avatarUrl ? (- <Box- component="img"- alt=""- src={avatarUrl}- sx={{- display: "block",- height: "100%",- objectFit: "cover",- objectPosition: "center",- width: "100%",- }}- />+ {avatarUrl || !friend.avatarObjectKey ? (+ <SpaceAvatarImage src={avatarUrl} />) : (<Skeletonvariant="circular"diff --git a/web/apps/space/src/screens/HomeScreen.tsx b/web/apps/space/src/screens/HomeScreen.tsxindex cdfa4bd36a..6bd5442ef8 100644--- a/web/apps/space/src/screens/HomeScreen.tsx+++ b/web/apps/space/src/screens/HomeScreen.tsx@@ -13,6 +13,7 @@ import {type SpaceViewerPhoto,type SpaceViewerPostActionMode,} from "components/SpaceFileViewer";+import { SpaceAvatarImage } from "components/SpaceAvatarImage";import { SpaceInviteFriendsDialog } from "components/SpaceInviteFriendsDialog";import { SpacePostFloatingActionButton } from "components/SpacePostFloatingActionButton";import {@@ -171,10 +172,11 @@ type FeedTimestampStatus = "failed" | "posted" | "posting";interface FeedItemProps {aspectRatio: number;- avatarUrl?: string | null;+ avatarUrl: string | null;caption?: string;friendID: string;imageUrl?: string;+ isAvatarPending: boolean;isOwnPost: boolean;likeCount?: number;name: string;@@ -637,6 +639,7 @@ const FeedItem: React.FC<FeedItemProps> = ({caption,friendID,imageUrl,+ isAvatarPending,isOwnPost,likeCount = 0,name,@@ -655,7 +658,7 @@ const FeedItem: React.FC<FeedItemProps> = ({const [isLiked, setIsLiked] = useState(viewerLiked);const [likePopID, setLikePopID] = useState(0);const [shouldLoadMedia, setShouldLoadMedia] = useState(- Boolean(imageUrl) && avatarUrl !== undefined,+ Boolean(imageUrl) && !isAvatarPending,);const rootRef = React.useRef<HTMLElement | null>(null);const firstName = firstNameFrom(name);@@ -686,7 +689,7 @@ const FeedItem: React.FC<FeedItemProps> = ({(decodedPhoto.ready ? decodedPhoto.src : imageUrl) ?? undefined;const displayAvatarUrl =(decodedAvatar.ready ? decodedAvatar.src : avatarUrl) ?? undefined;- const isAvatarReady = avatarUrl !== undefined && decodedAvatar.ready;+ const isAvatarReady = !isAvatarPending && decodedAvatar.ready;const photoDimensions =loadedPhotoDimensions && loadedPhotoDimensions.src == displayImageUrl? loadedPhotoDimensions@@ -789,10 +792,10 @@ const FeedItem: React.FC<FeedItemProps> = ({if (!imageUrl) {void onLoadImage?.();}- if (avatarUrl === undefined) {+ if (isAvatarPending) {void onLoadAvatar?.();}- }, [avatarUrl, imageUrl, onLoadAvatar, onLoadImage, shouldLoadMedia]);+ }, [imageUrl, isAvatarPending, onLoadAvatar, onLoadImage, shouldLoadMedia]);React.useEffect(() => {if (!decodedPhotoHeight || !decodedPhotoWidth) return;@@ -967,31 +970,10 @@ const FeedItem: React.FC<FeedItemProps> = ({},}}>- {displayAvatarUrl ? (- <Box- component="img"- alt=""- src={displayAvatarUrl}- sx={{- borderRadius: "50%",- display: "block",- height: "100%",- objectFit: "cover",- objectPosition: "center",- width: "100%",- }}- />- ) : (- <Skeleton- variant="circular"- sx={{- bgcolor: feedSkeletonElementBackground,- height: "100%",- transform: "none",- width: "100%",- }}- />- )}+ <SpaceAvatarImage+ src={displayAvatarUrl}+ borderRadius="50%"+ /><Boxaria-hiddensx={{@@ -1654,23 +1636,25 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({) => {const imageUrl = loadedFeedImageURLFor(item);const avatarUrl = loadedFeedAvatarURLFor(item);+ const isAvatarPending = avatarUrl === undefined;return (<FeedItemkey={key}aspectRatio={item.width && item.height ? item.width / item.height : 1}- avatarUrl={avatarUrl}+ avatarUrl={avatarUrl ?? null}caption={item.caption}friendID={item.friendID}imageUrl={imageUrl}+ isAvatarPending={isAvatarPending}isOwnPost={Boolean(profileSpaceId) && item.spaceId == profileSpaceId}likeCount={item.likeCount}name={item.name}onLoadAvatar={- avatarUrl === undefined+ isAvatarPending? () => loadFeedPostAvatar(item): undefined}@@ -1708,6 +1692,7 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({caption={item.caption}friendID={item.friendID}imageUrl={item.imageUrl}+ isAvatarPending={false}isOwnPostname={item.name}onOpenProfile={onOpenProfile}@@ -2029,19 +2014,11 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({width: headerAvatarSize,}}>- {profile?.avatarUrl ? (- <Box- component="img"- alt=""+ {profile &&+ (profile.avatarUrl || !profile.avatarObjectKey) ? (+ <SpaceAvatarImagesrc={profile.avatarUrl}- sx={{- borderRadius: "50%",- display: "block",- height: "100%",- objectFit: "cover",- objectPosition: "center",- width: "100%",- }}+ borderRadius="50%"/>) : (<Skeletondiff --git a/web/apps/space/src/screens/MessagesScreen.tsx b/web/apps/space/src/screens/MessagesScreen.tsxindex 524444cad5..dadc162b9f 100644--- a/web/apps/space/src/screens/MessagesScreen.tsx+++ b/web/apps/space/src/screens/MessagesScreen.tsx@@ -11,9 +11,9 @@ import {MenuItem,MenuList,Popper,- Skeleton,Tooltip,} from "@mui/material";+import { SpaceAvatarImage } from "components/SpaceAvatarImage";import { SpaceInviteFriendsDialog } from "components/SpaceInviteFriendsDialog";import { SpaceLoadingSpinner } from "components/SpaceRouteFallback";import { formatTimeAgo } from "ente-base/date";@@ -33,7 +33,6 @@ import { clampSpaceMessageText } from "utils/spaceMessageLimits";export const messagesBackground = "#FFFFFF";const green = "#08C225";-const avatarSkeletonBackground = "#E6E6E6";const textBase = "#000000";const textSecondary = "#777777";const lightSurface = "#F2F2F2";@@ -129,7 +128,6 @@ const Avatar: React.FC<{ avatarUrl?: string | null; size: number }> = ({<Boxsx={{alignItems: "center",- bgcolor: avatarSkeletonBackground,borderRadius: "50%",display: "flex",flexShrink: 0,@@ -139,30 +137,7 @@ const Avatar: React.FC<{ avatarUrl?: string | null; size: number }> = ({width: size,}}>- {avatarUrl ? (- <Box- component="img"- alt=""- src={avatarUrl}- sx={{- display: "block",- height: "100%",- objectFit: "cover",- objectPosition: "center",- width: "100%",- }}- />- ) : (- <Skeleton- variant="circular"- sx={{- bgcolor: avatarSkeletonBackground,- height: "100%",- transform: "none",- width: "100%",- }}- />- )}+ <SpaceAvatarImage src={avatarUrl} /></Box>);diff --git a/web/apps/space/src/screens/ProfileImageViewerScreen.tsx b/web/apps/space/src/screens/ProfileImageViewerScreen.tsxindex 446b8e14b7..8d88e000cc 100644--- a/web/apps/space/src/screens/ProfileImageViewerScreen.tsx+++ b/web/apps/space/src/screens/ProfileImageViewerScreen.tsx@@ -1,6 +1,7 @@import { ArrowLeft02Icon } from "@hugeicons/core-free-icons";import { HugeiconsIcon } from "@hugeicons/react";import { Box, Skeleton } from "@mui/material";+import { SpaceAvatarImage } from "components/SpaceAvatarImage";import React, { useRef } from "react";import type { SetupProfile } from "screens/SetupProfileScreen";import { spaceTouchTargetSize } from "styles/touchTargets";@@ -35,6 +36,8 @@ export const ProfileImageViewerScreen: React.FC<: "Change profile picture";const imageUrl = isCover ? profile.coverUrl : profile.avatarUrl;const isCoverURLPending = isCover && Boolean(profile.coverObjectKey);+ const isAvatarURLPending =+ !isCover && Boolean(profile.avatarObjectKey) && !imageUrl;const displayImageUrl =isCover && !imageUrl? isCoverURLPending@@ -203,20 +206,7 @@ export const ProfileImageViewerScreen: React.FC<width: "min(64vw, 240px)",}}>- {displayImageUrl ? (- <Box- component="img"- alt=""- src={displayImageUrl}- sx={{- display: "block",- height: "100%",- objectFit: "cover",- objectPosition: "center",- width: "100%",- }}- />- ) : (+ {isAvatarURLPending ? (<Skeletonvariant="circular"sx={{@@ -227,6 +217,8 @@ export const ProfileImageViewerScreen: React.FC<width: "100%",}}/>+ ) : (+ <SpaceAvatarImage src={displayImageUrl} />)}</Box>)}diff --git a/web/apps/space/src/screens/ProfileScreen.tsx b/web/apps/space/src/screens/ProfileScreen.tsxindex 5126f1ced8..2977fa6f71 100644--- a/web/apps/space/src/screens/ProfileScreen.tsx+++ b/web/apps/space/src/screens/ProfileScreen.tsx@@ -5,6 +5,7 @@ import {} from "@hugeicons/core-free-icons";import { HugeiconsIcon } from "@hugeicons/react";import { Box, Skeleton } from "@mui/material";+import { SpaceAvatarImage } from "components/SpaceAvatarImage";import {SpaceFileViewer,SpaceViewerFeedBackdrop,@@ -1198,19 +1199,8 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({},}}>- {profile.avatarUrl ? (- <Box- component="img"- alt=""- src={profile.avatarUrl}- sx={{- display: "block",- height: "100%",- objectFit: "cover",- objectPosition: "center",- width: "100%",- }}- />+ {profile.avatarUrl || !profile.avatarObjectKey ? (+ <SpaceAvatarImage src={profile.avatarUrl} />) : (<Skeletonvariant="circular"diff --git a/web/apps/space/src/screens/SetupProfileScreen.tsx b/web/apps/space/src/screens/SetupProfileScreen.tsxindex c57443341e..35d673c9d5 100644--- a/web/apps/space/src/screens/SetupProfileScreen.tsx+++ b/web/apps/space/src/screens/SetupProfileScreen.tsx@@ -1,6 +1,5 @@-import { User02Icon } from "@hugeicons/core-free-icons";-import { HugeiconsIcon, type IconSvgElement } from "@hugeicons/react";import { Box } from "@mui/material";+import { SpaceAvatarImage } from "components/SpaceAvatarImage";import { SpaceAvatarCropPage } from "components/SpaceAvatarCropPage";import { SpaceAvatarEditButton } from "components/SpaceAvatarEditButton";import { SpaceButtonSpinner } from "components/SpaceButtonSpinner";@@ -21,17 +20,6 @@ const textBase = "#000";const textLight = "#969696";const warning = "#F63A3A";const setupProfileFormID = "space-setup-profile-form";-const filledUser02BodyPath =- "M18.5 20V16.5C18.5 15.2577 17.9407 14.0395 16.8103 13.5242C15.4315 12.8957 13.7779 12.5296 12 12.5296C10.2221 12.5296 8.5685 12.8957 7.18968 13.5242C6.05927 14.0395 5.5 15.2577 5.5 16.5V20";-const filledUserIcon = User02Icon.map(([tag, attrs]) => [- tag,- {- ...attrs,- d: attrs.key == "0" ? filledUser02BodyPath : attrs.d,- fill: "currentColor",- stroke: "none",- },-]) as IconSvgElement;export interface SetupProfile {avatarUrl: string | null;@@ -94,27 +82,11 @@ const BackIcon: React.FC = () => ();const AvatarPlaceholder: React.FC = () => (- <Box+ <SpaceAvatarImagearia-hidden- sx={{- alignItems: "center",- bgcolor: "#C8D2DB",- border: "4px solid white",- borderRadius: "50%",- color: "white",- display: "flex",- height: "100%",- justifyContent: "center",- overflow: "hidden",- width: "100%",- }}- >- <HugeiconsIcon- icon={filledUserIcon}- size={120}- style={{ transform: "translateY(18px)" }}- />- </Box>+ border="4px solid white"+ borderRadius="50%"+ />);const CheckIcon: React.FC = () => (diff --git a/web/apps/space/src/screens/ShareProfileLinkScreen.tsx b/web/apps/space/src/screens/ShareProfileLinkScreen.tsxindex 08f54b815e..7fbc08f6a1 100644--- a/web/apps/space/src/screens/ShareProfileLinkScreen.tsx+++ b/web/apps/space/src/screens/ShareProfileLinkScreen.tsx@@ -1,6 +1,7 @@import { Share08Icon } from "@hugeicons/core-free-icons";import { HugeiconsIcon } from "@hugeicons/react";import { Box, Skeleton } from "@mui/material";+import { SpaceAvatarImage } from "components/SpaceAvatarImage";import React, { useState } from "react";import type { SetupProfile } from "screens/SetupProfileScreen";import { spaceTouchTargetSize } from "styles/touchTargets";@@ -313,19 +314,8 @@ export const ShareProfileLinkScreen: React.FC<ShareProfileLinkScreenProps> = ({width: 112,}}>- {profile.avatarUrl ? (- <Box- component="img"- alt=""- src={profile.avatarUrl}- sx={{- display: "block",- height: "100%",- objectFit: "cover",- objectPosition: "center",- width: "100%",- }}- />+ {profile.avatarUrl || !profile.avatarObjectKey ? (+ <SpaceAvatarImage src={profile.avatarUrl} />) : (<Skeletonvariant="circular"