Skip to content

armgit / ente

Public Imported from GitHub
0

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

Open social profiles from feed

Anand Baburajane2555b29b961
diff --git a/web/apps/social/src/components/SocialFileViewer.tsx b/web/apps/social/src/components/SocialFileViewer.tsx
index e1fdf32744..9b23f334ff 100644
--- a/web/apps/social/src/components/SocialFileViewer.tsx
+++ b/web/apps/social/src/components/SocialFileViewer.tsx
@@ -26,6 +26,7 @@ const defaultPhotoHeight = 680;
export interface SocialViewerPhoto {
alt?: string;
avatarUrl?: string | null;
+ friendID?: string;
height?: number;
imageUrl: string;
name: string;
@@ -35,11 +36,13 @@ export interface SocialViewerPhoto {
interface SocialFileViewerProps {
onClose: () => void;
+ onOpenProfile?: () => void;
photo: SocialViewerPhoto;
}
export const SocialFileViewer: React.FC<SocialFileViewerProps> = ({
onClose,
+ onOpenProfile,
photo,
}) => {
const displayName = firstNameFrom(photo.name);
@@ -185,19 +188,35 @@ export const SocialFileViewer: React.FC<SocialFileViewerProps> = ({
}}
>
<Box
+ component={onOpenProfile ? "button" : "div"}
+ type={onOpenProfile ? "button" : undefined}
+ aria-label={
+ onOpenProfile
+ ? `Open ${displayName}'s profile`
+ : undefined
+ }
+ onClick={onOpenProfile}
sx={{
+ appearance: "none",
alignItems: "center",
bgcolor: photo.avatarUrl
? "transparent"
: paleGreen,
+ border: 0,
borderRadius: "50%",
color: green,
+ cursor: onOpenProfile ? "pointer" : "default",
display: "flex",
flexShrink: 0,
height: 32,
justifyContent: "center",
overflow: "hidden",
+ p: 0,
width: 32,
+ "&:focus-visible": {
+ outline: `2px solid ${green}`,
+ outlineOffset: 2,
+ },
}}
>
{photo.avatarUrl ? (
@@ -241,12 +260,35 @@ export const SocialFileViewer: React.FC<SocialFileViewerProps> = ({
}}
>
<Box
- component="span"
+ component={onOpenProfile ? "button" : "span"}
+ type={onOpenProfile ? "button" : undefined}
+ aria-label={
+ onOpenProfile
+ ? `Open ${displayName}'s profile`
+ : undefined
+ }
+ onClick={onOpenProfile}
sx={{
+ appearance: "none",
+ bgcolor: "transparent",
+ border: 0,
+ color: "inherit",
+ cursor: onOpenProfile ? "pointer" : "default",
+ fontFamily: "inherit",
+ fontSize: "inherit",
fontWeight: 650,
+ lineHeight: "inherit",
minWidth: 0,
overflow: "hidden",
+ p: 0,
+ textAlign: "left",
textOverflow: "ellipsis",
+ whiteSpace: "nowrap",
+ "&:focus-visible": {
+ borderRadius: "4px",
+ outline: `2px solid ${green}`,
+ outlineOffset: 2,
+ },
}}
>
{displayName}
diff --git a/web/apps/social/src/pages/index.tsx b/web/apps/social/src/pages/index.tsx
index 79856be085..b09273afff 100644
--- a/web/apps/social/src/pages/index.tsx
+++ b/web/apps/social/src/pages/index.tsx
@@ -45,6 +45,7 @@ type Screen =
| "settings";
type ProfileBackScreen = "login" | "verify-email";
+type FriendProfileBackScreen = "friends" | "home";
const samplePublicProfileData = {
avatarUrl: "/images/sample-avatar.jpg",
@@ -89,6 +90,8 @@ const Page: React.FC = () => {
const [profile, setProfile] = useState<SetupProfile | null>(null);
const [profileBackScreen, setProfileBackScreen] =
useState<ProfileBackScreen>("verify-email");
+ const [friendProfileBackScreen, setFriendProfileBackScreen] =
+ useState<FriendProfileBackScreen>("friends");
const [selectedFriendID, setSelectedFriendID] = useState<string | null>(
null,
);
@@ -98,6 +101,15 @@ const Page: React.FC = () => {
setScreen("setup-profile");
};
+ const openFriendProfile = (
+ friendID: string,
+ backScreen: FriendProfileBackScreen,
+ ) => {
+ setSelectedFriendID(friendID);
+ setFriendProfileBackScreen(backScreen);
+ setScreen("friend-profile");
+ };
+
useEffect(() => {
const publicProfileLink = parsePublicProfileLink();
setRouteMode(
@@ -108,7 +120,8 @@ const Page: React.FC = () => {
}, []);
const selectedFriend = selectedFriendID
- ? friends.find((friend) => friend.id == selectedFriendID)
+ ? (friends.find((friend) => friend.id == selectedFriendID) ??
+ sampleFriends.find((friend) => friend.id == selectedFriendID))
: undefined;
const themeColor =
@@ -206,6 +219,9 @@ const Page: React.FC = () => {
{screen == "home" && profile && (
<HomeScreen
profile={profile}
+ onOpenFriend={(friendID) =>
+ openFriendProfile(friendID, "home")
+ }
onOpenProfile={() => setScreen("profile")}
/>
)}
@@ -222,10 +238,9 @@ const Page: React.FC = () => {
<FriendsScreen
friends={friends}
onBack={() => setScreen("profile")}
- onOpenFriend={(friendID) => {
- setSelectedFriendID(friendID);
- setScreen("friend-profile");
- }}
+ onOpenFriend={(friendID) =>
+ openFriendProfile(friendID, "friends")
+ }
onUnfriend={(friendID) =>
setFriends((currentFriends) =>
currentFriends.filter(
@@ -244,7 +259,7 @@ const Page: React.FC = () => {
fullName: selectedFriend.fullName,
username: selectedFriend.username,
}}
- onBack={() => setScreen("friends")}
+ onBack={() => setScreen(friendProfileBackScreen)}
/>
)}
{screen == "settings" && profile && (
diff --git a/web/apps/social/src/screens/HomeScreen.tsx b/web/apps/social/src/screens/HomeScreen.tsx
index 2fa5dedc71..c36aca93eb 100644
--- a/web/apps/social/src/screens/HomeScreen.tsx
+++ b/web/apps/social/src/screens/HomeScreen.tsx
@@ -24,6 +24,7 @@ const sampleFeedItems = [
{
aspectRatio: sampleFeedPhotoAspectRatio,
avatarUrl: "/images/sample-feed-4.jpg",
+ friendID: "aparna-bhatnagar",
imageUrl: "/images/sample-feed-1.jpg",
name: "Aparna Bhatnagar",
timestampMs: minutesAgo(22),
@@ -31,6 +32,7 @@ const sampleFeedItems = [
{
aspectRatio: sampleFeedPhotoAspectRatio,
avatarUrl: "/images/sample-feed-3.jpg",
+ friendID: "mira-sen",
imageUrl: "/images/sample-feed-2.jpg",
name: "Mira Sen",
timestampMs: hoursAgo(3),
@@ -38,6 +40,7 @@ const sampleFeedItems = [
{
aspectRatio: sampleFeedPhotoAspectRatio,
avatarUrl: "/images/sample-feed-5.jpg",
+ friendID: "nikhil-rao",
imageUrl: "/images/sample-feed-3.jpg",
name: "Nikhil Rao",
timestampMs: daysAgo(1),
@@ -45,6 +48,7 @@ const sampleFeedItems = [
{
aspectRatio: sampleFeedPhotoAspectRatio,
avatarUrl: "/images/sample-feed-6.jpg",
+ friendID: "riya-kapoor",
imageUrl: "/images/sample-feed-4.jpg",
name: "Riya Kapoor",
timestampMs: daysAgo(2),
@@ -52,6 +56,7 @@ const sampleFeedItems = [
{
aspectRatio: sampleFeedPhotoAspectRatio,
avatarUrl: "/images/sample-feed-4.jpg",
+ friendID: "aparna-bhatnagar",
imageUrl: "/images/sample-feed-5.jpg",
name: "Aparna Bhatnagar",
timestampMs: daysAgo(4),
@@ -59,6 +64,7 @@ const sampleFeedItems = [
{
aspectRatio: sampleFeedPhotoAspectRatio,
avatarUrl: "/images/sample-feed-3.jpg",
+ friendID: "mira-sen",
imageUrl: "/images/sample-feed-6.jpg",
name: "Mira Sen",
timestampMs: daysAgo(8),
@@ -66,6 +72,7 @@ const sampleFeedItems = [
{
aspectRatio: sampleFeedPhotoAspectRatio,
avatarUrl: "/images/sample-feed-5.jpg",
+ friendID: "nikhil-rao",
imageUrl: "/images/sample-feed-2.jpg",
name: "Nikhil Rao",
timestampMs: new Date(new Date().getFullYear() - 1, 10, 18).getTime(),
@@ -73,6 +80,7 @@ const sampleFeedItems = [
];
interface HomeScreenProps {
+ onOpenFriend?: (friendID: string) => void;
onOpenProfile?: () => void;
profile: SetupProfile;
}
@@ -80,8 +88,10 @@ interface HomeScreenProps {
interface FeedItemProps {
aspectRatio: number;
avatarUrl: string;
+ friendID: string;
imageUrl: string;
name: string;
+ onOpenFriend?: (friendID: string) => void;
onOpenPhoto?: (photo: SocialViewerPhoto) => void;
timestampMs: number;
}
@@ -107,13 +117,16 @@ const PlusIcon: React.FC = () => (
const FeedItem: React.FC<FeedItemProps> = ({
aspectRatio,
avatarUrl,
+ friendID,
imageUrl,
name,
+ onOpenFriend,
onOpenPhoto,
timestampMs,
}) => {
const firstName = firstNameFrom(name);
const dateLabel = formatSocialDate(timestampMs);
+ const openFriend = () => onOpenFriend?.(friendID);
return (
<Box
@@ -132,13 +145,26 @@ const FeedItem: React.FC<FeedItemProps> = ({
}}
>
<Box
+ component="button"
+ type="button"
+ aria-label={`Open ${firstName}'s profile`}
+ onClick={openFriend}
sx={{
+ appearance: "none",
bgcolor: paleGreen,
borderRadius: "50%",
+ border: 0,
+ cursor: onOpenFriend ? "pointer" : "default",
+ display: "block",
flexShrink: 0,
height: 28,
overflow: "hidden",
+ p: 0,
width: 28,
+ "&:focus-visible": {
+ outline: `2px solid ${green}`,
+ outlineOffset: 2,
+ },
}}
>
<Box
@@ -169,12 +195,31 @@ const FeedItem: React.FC<FeedItemProps> = ({
}}
>
<Box
- component="span"
+ component="button"
+ type="button"
+ aria-label={`Open ${firstName}'s profile`}
+ onClick={openFriend}
sx={{
+ appearance: "none",
+ bgcolor: "transparent",
+ border: 0,
+ color: "inherit",
+ cursor: onOpenFriend ? "pointer" : "default",
+ fontFamily: "inherit",
+ fontSize: "inherit",
fontWeight: 650,
+ lineHeight: "inherit",
minWidth: 0,
overflow: "hidden",
+ p: 0,
+ textAlign: "left",
textOverflow: "ellipsis",
+ whiteSpace: "nowrap",
+ "&:focus-visible": {
+ borderRadius: "4px",
+ outline: `2px solid ${green}`,
+ outlineOffset: 2,
+ },
}}
>
{firstName}
@@ -212,6 +257,7 @@ const FeedItem: React.FC<FeedItemProps> = ({
onOpenPhoto?.({
alt: `${name} post`,
avatarUrl,
+ friendID,
imageUrl,
name,
timestampMs,
@@ -253,11 +299,13 @@ const FeedItem: React.FC<FeedItemProps> = ({
};
export const HomeScreen: React.FC<HomeScreenProps> = ({
+ onOpenFriend,
onOpenProfile,
profile,
}) => {
const [selectedPhoto, setSelectedPhoto] =
useState<SocialViewerPhoto | null>(null);
+ const selectedPhotoFriendID = selectedPhoto?.friendID;
const initialsSource = profile.fullName.trim() || profile.username.trim();
const initials = initialsSource
.split(/\s+/)
@@ -394,8 +442,10 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
key={`${item.name}-${item.imageUrl}`}
aspectRatio={item.aspectRatio}
avatarUrl={item.avatarUrl}
+ friendID={item.friendID}
imageUrl={item.imageUrl}
name={item.name}
+ onOpenFriend={onOpenFriend}
onOpenPhoto={setSelectedPhoto}
timestampMs={item.timestampMs}
/>
@@ -405,6 +455,14 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({
<SocialFileViewer
photo={selectedPhoto}
onClose={() => setSelectedPhoto(null)}
+ onOpenProfile={
+ selectedPhotoFriendID && onOpenFriend
+ ? () => {
+ setSelectedPhoto(null);
+ onOpenFriend(selectedPhotoFriendID);
+ }
+ : undefined
+ }
/>
)}
</Box>
diff --git a/web/apps/social/src/screens/ProfileScreen.tsx b/web/apps/social/src/screens/ProfileScreen.tsx
index fb52e86072..eaf8886d4c 100644
--- a/web/apps/social/src/screens/ProfileScreen.tsx
+++ b/web/apps/social/src/screens/ProfileScreen.tsx
@@ -882,6 +882,7 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({
<SocialFileViewer
photo={selectedPhoto}
onClose={() => setSelectedPhoto(null)}
+ onOpenProfile={() => setSelectedPhoto(null)}
/>
)}
</Box>