Skip to content

Commit 11981f0

Browse files
authored
Merge pull request #85 from indrazm/delete-post-admin
feat(posts): allow admin to access post dropdown menu
2 parents ca4d3f4 + e67c15c commit 11981f0

File tree

2 files changed

+45
-36
lines changed

2 files changed

+45
-36
lines changed

apps/platform/src/features/notifications/components/notificationItem.tsx

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Notification } from "@opencircle/core";
22
import { Avatar, Button } from "@opencircle/ui";
3-
import { useNavigate } from "@tanstack/react-router";
3+
import { Link, useNavigate } from "@tanstack/react-router";
44
import moment from "moment";
55
import { renderContent } from "../../posts/utils/contentRendering";
66
import { useMarkNotificationAsRead } from "../hooks/useNotifications";
@@ -27,16 +27,16 @@ export const NotificationItem = ({ notification }: NotificationItemProps) => {
2727
}
2828
};
2929

30-
const getNotificationMessage = () => {
30+
const getNotificationAction = () => {
3131
switch (notification.type) {
3232
case "mention":
33-
return `${notification.sender.username} mentioned you`;
33+
return "mentioned you";
3434
case "like":
35-
return `${notification.sender.username} liked your post`;
35+
return "liked your post";
3636
case "reply":
37-
return `${notification.sender.username} replied to your post`;
37+
return "replied to your post";
3838
default:
39-
return `${notification.sender.username} sent you a notification`;
39+
return "sent you a notification";
4040
}
4141
};
4242

@@ -54,44 +54,51 @@ export const NotificationItem = ({ notification }: NotificationItemProps) => {
5454
const isContentNotification = ["mention", "reply"].includes(
5555
notification.type,
5656
);
57-
const hasPostId = Boolean(notification.data?.post_id);
5857

5958
return (
60-
<main>
61-
<div
62-
className="flex gap-3 p-3 transition-colors duration-150 hover:bg-accent"
63-
style={{ opacity: notification.is_read ? "50%" : "100%" }}
64-
>
65-
<Avatar
66-
image_url={notification.sender.avatar_url || ""}
67-
initials={notification.sender.username.charAt(0).toUpperCase()}
68-
/>
59+
<main
60+
className="cursor-pointer transition-colors duration-150 hover:bg-accent"
61+
style={{ opacity: notification.is_read ? "50%" : "100%" }}
62+
onClick={handleViewPost}
63+
>
64+
<div className="flex gap-3 p-3">
65+
<Link
66+
to="/$username"
67+
params={{ username: notification.sender.username }}
68+
onClick={(e) => e.stopPropagation()}
69+
>
70+
<Avatar
71+
image_url={notification.sender.avatar_url || ""}
72+
initials={notification.sender.username.charAt(0).toUpperCase()}
73+
/>
74+
</Link>
6975
<div className="min-w-0 flex-1 space-y-1">
7076
<p className="truncate text-foreground text-sm">
71-
{getNotificationMessage()}
77+
<Link
78+
to="/$username"
79+
params={{ username: notification.sender.username }}
80+
className="font-medium hover:underline"
81+
onClick={(e) => e.stopPropagation()}
82+
>
83+
{notification.sender.username}
84+
</Link>{" "}
85+
{getNotificationAction()}
7286
</p>
7387

7488
<p className="text-muted-foreground text-xs">
7589
{getTimeAgo(notification.created_at)}
7690
</p>
7791
</div>
7892
<div className="flex items-start gap-2">
79-
{hasPostId && (
80-
<Button
81-
variant="secondary"
82-
size="sm"
83-
onClick={handleViewPost}
84-
className="text-xs"
85-
>
86-
View
87-
</Button>
88-
)}
8993
{!notification.is_read && (
9094
<>
9195
<Button
9296
variant="secondary"
9397
size="sm"
94-
onClick={handleMarkAsRead}
98+
onClick={(e) => {
99+
e.stopPropagation();
100+
handleMarkAsRead();
101+
}}
95102
disabled={isMarkingAsRead}
96103
className="text-xs"
97104
>

apps/platform/src/features/posts/components/postCard.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const PostCard = ({ post }: PostCardProps) => {
4545
<main className="relative max-w-2xl space-y-2 border-border border-b p-4">
4646
<div className="absolute top-4 right-4 flex items-center justify-center gap-2">
4747
{post.is_pinned && <PinIcon className="h-3 w-3 fill-foreground" />}
48-
{post.user_id === account?.id && (
48+
{(post.user_id === account?.id || account?.role === "admin") && (
4949
<DropdownMenu.Root>
5050
<DropdownMenu.Trigger asChild>
5151
<div className="flex h-6 w-6 items-center justify-center rounded-lg bg-background-secondary">
@@ -57,12 +57,14 @@ export const PostCard = ({ post }: PostCardProps) => {
5757
align="end"
5858
className="min-w-[80px] overflow-hidden rounded-lg border border-border bg-background-secondary font-medium text-xs shadow-2xl"
5959
>
60-
<DropdownMenu.Item
61-
className="p-3 focus-within:outline-none hover:bg-primary"
62-
onClick={() => setIsEditing(true)}
63-
>
64-
Edit
65-
</DropdownMenu.Item>
60+
{post.user_id === account?.id && (
61+
<DropdownMenu.Item
62+
className="p-3 focus-within:outline-none hover:bg-primary"
63+
onClick={() => setIsEditing(true)}
64+
>
65+
Edit
66+
</DropdownMenu.Item>
67+
)}
6668
<DropdownMenu.Item
6769
className="p-3 focus-within:outline-none hover:bg-primary"
6870
onClick={() => deletePost(post.id)}
@@ -157,8 +159,8 @@ export const PostCard = ({ post }: PostCardProps) => {
157159
navigate({ to: "/posts/$id", params: { id: post.id } }),
158160
)}
159161
</p>
160-
<UrlPreview content={post.content} />
161162
</div>
163+
<UrlPreview content={post.content} />
162164
<MediaGallery media={post.medias} />
163165
</>
164166
)}

0 commit comments

Comments
 (0)