Skip to content

Commit

Permalink
deduplicate, convert messy ifs to switch
Browse files Browse the repository at this point in the history
  • Loading branch information
WillCorrigan committed Oct 2, 2024
1 parent 7879b26 commit 47aa95b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
5 changes: 3 additions & 2 deletions packages/frontpage/app/(app)/_components/post-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export async function PostCard({
}: PostProps) {
const handle = await getVerifiedHandle(author);
const postHref = `/post/${handle}/${rkey}`;
const user = await getUser();

return (
// TODO: Make article route to postHref via onClick on card except innser links or buttons
Expand Down Expand Up @@ -115,7 +116,7 @@ export async function PostCard({
</div>
</div>

{(await getUser()) ? (
{user ? (
<div className="ml-auto">
<EllipsisDropdown>
<ReportButton
Expand All @@ -125,7 +126,7 @@ export async function PostCard({
author,
})}
/>
{(await getUser())?.did === author ? (
{user?.did === author ? (
<DeleteButton
deleteAction={DeletePostAction.bind(null, rkey)}
/>
Expand Down
23 changes: 13 additions & 10 deletions packages/frontpage/app/(app)/moderation/_components/report-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,19 @@ const createLink = async (
author?: DID | null,
rkey?: string | null,
) => {
if (collection === PostCollection) {
return `/post/${author}/${rkey}/`;
} else if (collection === CommentCollection) {
const { postRkey, postAuthor } = (await getPostFromComment({
rkey: rkey!,
did: author!,
}))!;
return `/post/${postAuthor}/${postRkey}/${author}/${rkey}/`;
} else {
return `/profile/${author}/`;
switch (collection) {
case PostCollection:
return `/post/${author}/${rkey}/`;

case CommentCollection:
const { postRkey, postAuthor } = (await getPostFromComment({
rkey: rkey!,
did: author!,
}))!;
return `/post/${postAuthor}/${postRkey}/${author}/${rkey}/`;

default:
return `/profile/${author}/`;
}
};

Expand Down

0 comments on commit 47aa95b

Please sign in to comment.