Skip to content

Commit

Permalink
Merge pull request #78 from JaberHPranto/feature/social-share
Browse files Browse the repository at this point in the history
update vote count in description and fix broken image issue
  • Loading branch information
omranjamal authored Sep 7, 2024
2 parents b2bc737 + 13e33d8 commit 534ac8a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
5 changes: 5 additions & 0 deletions apps/jonogon-web-next/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ export const metadata: Metadata = {
url: 'https://jonogon.org',
siteName: 'jonogon.org',
type: 'website',
images: [
{
url: '/opengraph-image.jpeg',
},
],
},
};

Expand Down
2 changes: 1 addition & 1 deletion apps/jonogon-web-next/src/app/petitions/[id]/_page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ export default function Petition() {
{petition?.data.status !== 'rejected' &&
petition?.data.status !== 'draft' && (
<div
className="flex items-center gap-1.5 mt-1 text-primary/80 rounded-2xl border px-4 py-2 hover:border-red-500 hover:text-red-500 transition-colors"
className="flex items-center gap-1.5 mt-3 text-primary/80 rounded-2xl border px-4 py-2 hover:border-red-500 hover:text-red-500 transition-colors"
role="button"
onClick={() => openShareModal()}>
<Share2 className="size-3" />
Expand Down
21 changes: 16 additions & 5 deletions apps/jonogon-web-next/src/app/petitions/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ export const runtime = 'edge';

export async function generateMetadata({params}: {params: {id: string}}) {
const response = await trpcVanilla.petitions.get.query({id: params.id});
const {id, title, description, attachments} = response.data;
const {
id,
title,
description,
attachments,
petition_upvote_count,
petition_downvote_count,
} = response.data;

const users = await trpcVanilla.users.getTotalNumberOfUsers.query();
const totalNumberOfUsers = users.data.count ? Number(users.data.count) : 0;
const totalVoteCount = petition_upvote_count + petition_downvote_count;

const originalTitle = title ?? '';
const originalDescription = description ?? '';
Expand All @@ -19,7 +25,7 @@ export async function generateMetadata({params}: {params: {id: string}}) {
: `${originalTitle} - Jonogon`;

const metaTitle = title ?? '';
const metaDescription = generateDescription(totalNumberOfUsers);
const metaDescription = generateDescription(totalVoteCount);

return {
title: siteTitle,
Expand Down Expand Up @@ -51,7 +57,12 @@ export async function generateMetadata({params}: {params: {id: string}}) {
description: metaDescription,
images:
attachments.length > 0
? [`https://jonogon.org${attachments[0].thumbnail}`]
? [
`${attachments[0].thumbnail}`.replace(
'$CORE_HOSTNAME',
'localhost',
),
]
: [],
},
};
Expand Down

0 comments on commit 534ac8a

Please sign in to comment.