Skip to content

armgit / ente

Public Imported from GitHub
0

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

Open post like notifications

Anand Baburajanc026f3e2ae55
diff --git a/web/apps/space/src/components/SpaceNotificationsPage.tsx b/web/apps/space/src/components/SpaceNotificationsPage.tsx
index fba29c1718..0b22a94389 100644
--- a/web/apps/space/src/components/SpaceNotificationsPage.tsx
+++ b/web/apps/space/src/components/SpaceNotificationsPage.tsx
@@ -84,7 +84,14 @@ export const SpaceNotificationsPage: React.FC = () => {
notifications={notifications}
onBack={() => void router.push(spaceRoutes.home)}
onOpenFriendMessages={(spaceId) =>
- void router.push(spaceRoutes.messageFromNotifications(spaceId))
+ void router.push(
+ spaceRoutes.messageFromNotifications(spaceId),
+ )
+ }
+ onOpenPost={(spaceId, postId) =>
+ void router.push(
+ spaceRoutes.postFromNotifications(spaceId, postId),
+ )
}
onShareProfileLink={async () => {
if (!profile.spaceId) throw new Error("Missing space.");
diff --git a/web/apps/space/src/pages/app/posts/[spaceId]/[postId].tsx b/web/apps/space/src/pages/app/posts/[spaceId]/[postId].tsx
index c3c81e84f0..c4fa200bd0 100644
--- a/web/apps/space/src/pages/app/posts/[spaceId]/[postId].tsx
+++ b/web/apps/space/src/pages/app/posts/[spaceId]/[postId].tsx
@@ -10,7 +10,7 @@ import {
type SpacePost,
} from "services/space";
import { useSpaceAppState } from "state/spaceAppState";
-import { spaceRoutes } from "utils/spaceRoutes";
+import { postRouteSourceFromQuery, spaceRoutes } from "utils/spaceRoutes";
const postBackground = "#000000";
@@ -64,6 +64,7 @@ const Page: React.FC = () => {
const spaceId =
valueFromQuery(router.query.spaceId) ?? pathParams.spaceId ?? "";
const postId = postIdFromQuery(router.query.postId) ?? pathParams.postId;
+ const postRouteSource = postRouteSourceFromQuery(router.query.from);
const [post, setPost] = React.useState<SpacePost | null>(null);
const [postLoadError, setPostLoadError] = React.useState<string>();
const [isPostLoading, setIsPostLoading] = React.useState(false);
@@ -120,8 +121,12 @@ const Page: React.FC = () => {
router.back();
return;
}
+ if (postRouteSource == "notifications") {
+ void router.push(spaceRoutes.notifications);
+ return;
+ }
void router.push(ownerProfileRoute());
- }, [ownerProfileRoute, router]);
+ }, [ownerProfileRoute, postRouteSource, router]);
if (
!router.isReady ||
diff --git a/web/apps/space/src/screens/NotificationsScreen.tsx b/web/apps/space/src/screens/NotificationsScreen.tsx
index dd5e83093c..379fa1f627 100644
--- a/web/apps/space/src/screens/NotificationsScreen.tsx
+++ b/web/apps/space/src/screens/NotificationsScreen.tsx
@@ -25,6 +25,7 @@ interface NotificationsScreenProps {
notifications: SpaceNotification[];
onBack?: () => void;
onOpenFriendMessages?: (spaceId: string) => void;
+ onOpenPost?: (spaceId: string, postId: number) => void;
onShareProfileLink?: () => Promise<string>;
}
@@ -252,7 +253,8 @@ const groupSectionNotifications = (items: SpaceNotification[]) => {
const NotificationRow: React.FC<{
group: NotificationGroup;
onOpenFriendMessages?: (spaceId: string) => void;
-}> = ({ group, onOpenFriendMessages }) => {
+ onOpenPost?: (spaceId: string, postId: number) => void;
+}> = ({ group, onOpenFriendMessages, onOpenPost }) => {
const postImageUrl = group.post?.imageUrl;
const avatarActors =
group.type == "post_like" && group.actors.length > 2
@@ -267,18 +269,33 @@ const NotificationRow: React.FC<{
const canOpenFriendMessages = Boolean(
friendActivitySpaceId && onOpenFriendMessages,
);
+ const canOpenPost = Boolean(
+ group.type == "post_like" &&
+ group.post &&
+ !group.post.isDeleted &&
+ onOpenPost,
+ );
+ const canOpen = canOpenFriendMessages || canOpenPost;
const openFriendMessages = () => {
if (!friendActivitySpaceId) return;
onOpenFriendMessages?.(friendActivitySpaceId);
};
+ const openRow = () => {
+ if (canOpenPost && group.post) {
+ onOpenPost?.(group.post.spaceId, group.post.postId);
+ return;
+ }
+ if (canOpenFriendMessages) openFriendMessages();
+ };
+
return (
<Box component="li">
<Box
- component={canOpenFriendMessages ? "button" : "div"}
- type={canOpenFriendMessages ? "button" : undefined}
- onClick={canOpenFriendMessages ? openFriendMessages : undefined}
+ component={canOpen ? "button" : "div"}
+ type={canOpen ? "button" : undefined}
+ onClick={canOpen ? openRow : undefined}
sx={{
alignItems: "center",
appearance: "none",
@@ -286,7 +303,7 @@ const NotificationRow: React.FC<{
border: 0,
borderRadius: "8px",
color: textBase,
- cursor: canOpenFriendMessages ? "pointer" : "default",
+ cursor: canOpen ? "pointer" : "default",
display: "grid",
gap: "10px",
gridTemplateColumns: postImageUrl
@@ -354,8 +371,9 @@ const NotificationRow: React.FC<{
const NotificationSection: React.FC<{
onOpenFriendMessages?: (spaceId: string) => void;
+ onOpenPost?: (spaceId: string, postId: number) => void;
section: NotificationSection;
-}> = ({ onOpenFriendMessages, section }) => {
+}> = ({ onOpenFriendMessages, onOpenPost, section }) => {
const groups = groupSectionNotifications(section.items);
if (groups.length == 0) return null;
@@ -382,6 +400,7 @@ const NotificationSection: React.FC<{
key={group.id}
group={group}
onOpenFriendMessages={onOpenFriendMessages}
+ onOpenPost={onOpenPost}
/>
))}
</Box>
@@ -394,6 +413,7 @@ export const NotificationsScreen: React.FC<NotificationsScreenProps> = ({
notifications,
onBack,
onOpenFriendMessages,
+ onOpenPost,
onShareProfileLink,
}) => {
const [isInviteDialogOpen, setIsInviteDialogOpen] = React.useState(false);
@@ -610,6 +630,7 @@ export const NotificationsScreen: React.FC<NotificationsScreenProps> = ({
<NotificationSection
key={section.title}
onOpenFriendMessages={onOpenFriendMessages}
+ onOpenPost={onOpenPost}
section={section}
/>
))
diff --git a/web/apps/space/src/utils/spaceRoutes.ts b/web/apps/space/src/utils/spaceRoutes.ts
index 49fba72a76..c16985d9b8 100644
--- a/web/apps/space/src/utils/spaceRoutes.ts
+++ b/web/apps/space/src/utils/spaceRoutes.ts
@@ -1,6 +1,7 @@
export type SetupProfileSource = "login" | "verify";
export type ProfileImageFlowSource = "profile" | "settings";
export type MessageThreadSource = "messages" | "notifications";
+export type PostRouteSource = "default" | "notifications";
export type VerifyFlow = "login" | "signup";
const valueFromQuery = (value: string | string[] | undefined) =>
@@ -28,6 +29,8 @@ export const spaceRoutes = {
passkeysVerify: "/passkeys/verify",
post: (spaceId: string, postId: number) =>
`/app/posts/${encodeURIComponent(spaceId)}/${encodeURIComponent(String(postId))}`,
+ postFromNotifications: (spaceId: string, postId: number) =>
+ `/app/posts/${encodeURIComponent(spaceId)}/${encodeURIComponent(String(postId))}?from=notifications`,
editProfileCover: "/app/profile/cover-edit",
editProfileCoverFrom: (source?: ProfileImageFlowSource) =>
routeWithProfileImageFlowSource("/app/profile/cover-edit", source),
@@ -72,5 +75,10 @@ export const messageThreadSourceFromQuery = (
): MessageThreadSource =>
valueFromQuery(value) == "notifications" ? "notifications" : "messages";
+export const postRouteSourceFromQuery = (
+ value: string | string[] | undefined,
+): PostRouteSource =>
+ valueFromQuery(value) == "notifications" ? "notifications" : "default";
+
export const friendSpaceIdFromQuery = (value: string | string[] | undefined) =>
valueFromQuery(value) ?? "";