Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add community digest on homepage #11

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions prisma/json-schema/json-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,10 @@
"hasSentNewsletter": {
"type": "boolean",
"default": false
},
"isFeatured": {
"type": "boolean",
"default": false
}
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "digests" ADD COLUMN "isFeatured" BOOLEAN NOT NULL DEFAULT false;
3 changes: 2 additions & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ model Digest {
digestBlocks DigestBlock[]
typefullyThreadUrl String?
hasSentNewsletter Boolean @default(false)
isFeatured Boolean @default(false)
@@unique([slug, teamId])
@@map("digests")
}
Expand Down
45 changes: 45 additions & 0 deletions src/components/home/HomeDigests.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import db from '@/lib/db';
import React from 'react';
import PublicDigestCard from '../teams/PublicDigestCard';

const HomeDigests = async () => {
const digests = await db.digest.findMany({
take: 3,
orderBy: { publishedAt: 'desc' },
where: { publishedAt: { not: null }, isFeatured: true },
select: {
id: true,
publishedAt: true,
title: true,
description: true,
slug: true,
team: { select: { slug: true } },
_count: {
select: {
digestBlocks: true,
},
},
},
});

return (
<div className="p-4 m-auto max-w-5xl pt-10 pb-20 text-gray-900 w-full h-full flex flex-col items-center">
<h2 className="pb-12 font-[800] text-2xl lg:text-3xl text-center flex flex-col ">
<span>Community digests</span>
</h2>
<div className="flex max-lg:flex-col lg:space-x-10 max-lg:space-y-12">
<div className="gap-3 grid md:grid-cols-3 xs:grid-cols-2">
{digests.map((digest) => (
<PublicDigestCard
key={digest.id}
digest={digest}
teamSlug={digest.team.slug}
/>
))}
</div>
</div>
</div>
);
};

export default HomeDigests;
5 changes: 5 additions & 0 deletions src/components/pages/Homepage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Hero from '@/components/home/Hero';
import HomeFooter from '../home/HomeFooter';
import HomeSteps from '../home/HomeSteps';
import { Session } from 'next-auth';
import HomeDigests from '../home/HomeDigests';

const Homepage = ({ user }: { user?: Session['user'] }) => {
return (
Expand All @@ -12,6 +13,10 @@ const Homepage = ({ user }: { user?: Session['user'] }) => {
<section className="flex-1 flex justify-center pb-8 bg-slate-100">
<HomeSteps />
</section>
<section className="bg-white flex flex-1 justify-center">
{/* @ts-expect-error */}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could add a TODO or issue to update React & types to solve this issue.

<HomeDigests />
</section>
<HomeFooter />
</div>
);
Expand Down
1 change: 0 additions & 1 deletion src/components/pages/TeamPublicPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ const TeamPublicPage = ({ team }: Props) => {
key={digest.slug}
digest={digest}
teamSlug={team.slug}
teamName={team.name}
/>
))
)}
Expand Down
4 changes: 1 addition & 3 deletions src/components/teams/PublicDigestCard.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { PublicTeamResult } from '@/lib/queries';
import { generateDigestOGUrl } from '@/utils/open-graph';
import { format } from 'date-fns';
import Image from 'next/image';
import Link from 'next/link';

interface Props {
digest: NonNullable<PublicTeamResult>['Digest'][number];
teamSlug: string;
teamName: string;
}

const PublicDigestCard = ({ digest, teamSlug, teamName }: Props) => {
const PublicDigestCard = ({ digest, teamSlug }: Props) => {
const { title, description, publishedAt, _count } = digest;
const url = new URL(generateDigestOGUrl(digest.slug));

Expand Down
3 changes: 3 additions & 0 deletions src/pages/admin/[[...nextadmin]].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ export const getServerSideProps: GetServerSideProps = async ({ req, res }) => {
description: {
display: true,
},
isFeatured: {
display: true,
},
createdAt: {
display: true,
},
Expand Down
Loading