Skip to content

Commit

Permalink
feat: post labels for profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
ImLunaHey committed Jan 13, 2025
1 parent d723cd0 commit 5e7f374
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
21 changes: 15 additions & 6 deletions src/components/post-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { usePostLabels } from '@/lib/bluesky/hooks/use-post-labels';
import { Accordion, AccordionItem, AccordionTrigger, AccordionContent } from '@radix-ui/react-accordion';
import { ErrorBoundary } from './error-boundary';
import { PostEmbed } from './post-embed';
import { Badge } from './ui/badge';

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

const onClick = () => {
Expand Down Expand Up @@ -311,6 +313,13 @@ function PostCardInner({ post, context, className, parent = false }: PostCardInn
{!experiments.zenMode && <BetterContext context={context} />}
</div>
</div>
<div className="flex gap-1 py-1">
{profileLabels?.map((label) => (
<Badge title={label.labelDef.locales[0]!.description} key={label.label.uri}>
{label.labelDef.locales[0]!.name}
</Badge>
))}
</div>
<div className="flex flex-col gap-2">
<p className="text-gray-800 dark:text-gray-200">
{translatedText ? (
Expand All @@ -327,14 +336,14 @@ function PostCardInner({ post, context, className, parent = false }: PostCardInn
)}
</p>
<ErrorBoundary>
{moderationFilter ? null : moderationLabel ? (
{moderationFilter ? null : moderationMediaLabel ? (
<Accordion type="single" collapsible onClick={(event) => event.stopPropagation()}>
<AccordionItem value="item-1">
<AccordionTrigger className="w-full group">
<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">
<div className="flex items-center gap-1">
<AlertTriangleIcon size={20} />
{moderationLabel?.name}
{moderationMediaLabel?.name}
</div>
<div className="group-data-[state=open]:hidden">{'show'}</div>
<div className="hidden group-data-[state=open]:flex">{'hide'}</div>
Expand Down Expand Up @@ -436,8 +445,8 @@ type PostCardProps = {
parent?: boolean;
};

export const PostCard = memo(function PostCard(props: PostCardProps) {
if (!props.post) return null;
export const PostCard = memo(function PostCard({ post, ...props }: PostCardProps) {
if (!post) return null;

return <PostCardInner {...props} />;
return <PostCardInner {...props} post={post} />;
});
2 changes: 1 addition & 1 deletion src/components/ui/badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export function Badge({ children, title }: { children: React.ReactNode; title: s
if (!children) return null;
return (
<div className="flex items-center">
<span title={title} className="bg-neutral-800 text-white p-1 text-xs rounded-md">
<span title={title} className="border p-1 text-xs rounded-md">
{children}
</span>
</div>
Expand Down

0 comments on commit 5e7f374

Please sign in to comment.