Skip to content

Commit 5e7f374

Browse files
committed
feat: post labels for profiles
1 parent d723cd0 commit 5e7f374

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/components/post-card.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import { usePostLabels } from '@/lib/bluesky/hooks/use-post-labels';
4343
import { Accordion, AccordionItem, AccordionTrigger, AccordionContent } from '@radix-ui/react-accordion';
4444
import { ErrorBoundary } from './error-boundary';
4545
import { PostEmbed } from './post-embed';
46+
import { Badge } from './ui/badge';
4647

4748
const contextToText = (context: string) => {
4849
if (context === 'following') return 'following';
@@ -248,7 +249,8 @@ function PostCardInner({ post, context, className, parent = false }: PostCardInn
248249
// Hide post if it's filtered
249250
if (moderation?.ui('contentList').filter) return null;
250251
const contentMedia = moderation?.ui('contentMedia');
251-
const moderationLabel = contentMedia?.blurs[0]?.type === 'label' ? contentMedia.blurs[0]?.labelDef.locales[0] : null;
252+
const moderationMediaLabel = contentMedia?.blurs[0]?.type === 'label' ? contentMedia.blurs[0]?.labelDef.locales[0] : null;
253+
const profileLabels = moderation?.ui('profileList').informs.filter((label) => label.type === 'label');
252254
const moderationFilter = moderation?.ui('contentMedia').filter;
253255

254256
const onClick = () => {
@@ -311,6 +313,13 @@ function PostCardInner({ post, context, className, parent = false }: PostCardInn
311313
{!experiments.zenMode && <BetterContext context={context} />}
312314
</div>
313315
</div>
316+
<div className="flex gap-1 py-1">
317+
{profileLabels?.map((label) => (
318+
<Badge title={label.labelDef.locales[0]!.description} key={label.label.uri}>
319+
{label.labelDef.locales[0]!.name}
320+
</Badge>
321+
))}
322+
</div>
314323
<div className="flex flex-col gap-2">
315324
<p className="text-gray-800 dark:text-gray-200">
316325
{translatedText ? (
@@ -327,14 +336,14 @@ function PostCardInner({ post, context, className, parent = false }: PostCardInn
327336
)}
328337
</p>
329338
<ErrorBoundary>
330-
{moderationFilter ? null : moderationLabel ? (
339+
{moderationFilter ? null : moderationMediaLabel ? (
331340
<Accordion type="single" collapsible onClick={(event) => event.stopPropagation()}>
332341
<AccordionItem value="item-1">
333342
<AccordionTrigger className="w-full group">
334343
<div className="flex items-center space-x-2 rounded-sm hover:bg-neutral-500 hover:bg-opacity-10 gap-1 border justify-between p-2">
335344
<div className="flex items-center gap-1">
336345
<AlertTriangleIcon size={20} />
337-
{moderationLabel?.name}
346+
{moderationMediaLabel?.name}
338347
</div>
339348
<div className="group-data-[state=open]:hidden">{'show'}</div>
340349
<div className="hidden group-data-[state=open]:flex">{'hide'}</div>
@@ -436,8 +445,8 @@ type PostCardProps = {
436445
parent?: boolean;
437446
};
438447

439-
export const PostCard = memo(function PostCard(props: PostCardProps) {
440-
if (!props.post) return null;
448+
export const PostCard = memo(function PostCard({ post, ...props }: PostCardProps) {
449+
if (!post) return null;
441450

442-
return <PostCardInner {...props} />;
451+
return <PostCardInner {...props} post={post} />;
443452
});

src/components/ui/badge.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export function Badge({ children, title }: { children: React.ReactNode; title: s
22
if (!children) return null;
33
return (
44
<div className="flex items-center">
5-
<span title={title} className="bg-neutral-800 text-white p-1 text-xs rounded-md">
5+
<span title={title} className="border p-1 text-xs rounded-md">
66
{children}
77
</span>
88
</div>

0 commit comments

Comments
 (0)