-
Notifications
You must be signed in to change notification settings - Fork 84
built a newsletter section #128
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
Open
Shivam107
wants to merge
2
commits into
apsinghdev:main
Choose a base branch
from
Shivam107:fix/newsletter
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { z } from "zod"; | ||
| import { router, publicProcedure } from "../trpc.js"; | ||
| import { newsletterService } from "../services/newsletter.service.js"; | ||
|
|
||
| export const newsletterRouter = router({ | ||
| list: publicProcedure | ||
| .input(z.object({ search: z.string().optional() }).optional()) | ||
Shivam107 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .query(async ({ input }) => newsletterService.list(input?.search)), | ||
|
|
||
| bySlug: publicProcedure | ||
| .input(z.object({ slug: z.string() })) | ||
| .query(async ({ input }) => newsletterService.bySlug(input.slug)), | ||
Shivam107 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import { Prisma } from "@prisma/client"; | ||
| import dbClient from "../prisma.js"; | ||
|
|
||
| const { prisma } = dbClient; | ||
|
|
||
| export const newsletterService = { | ||
| list: async (search?: string) => { | ||
| const where: Prisma.NewsletterIssueWhereInput | undefined = search | ||
| ? { | ||
| OR: [ | ||
| { title: { contains: search, mode: "insensitive" } }, | ||
| { summary: { contains: search, mode: "insensitive" } }, | ||
| { tags: { hasSome: search.split(" ").filter(Boolean) } }, | ||
| ], | ||
| } | ||
| : undefined; | ||
|
|
||
| return prisma.newsletterIssue.findMany({ | ||
| ...(where && { where }), | ||
| orderBy: { publishedAt: "desc" }, | ||
| select: { | ||
| id: true, | ||
| slug: true, | ||
| title: true, | ||
| summary: true, | ||
| publishedAt: true, | ||
| readTime: true, | ||
| heroMediaUrl: true, | ||
| heroMediaType: true, | ||
| tags: true, | ||
| }, | ||
| }); | ||
| }, | ||
|
|
||
| bySlug: async (slug: string) => { | ||
| return prisma.newsletterIssue.findUnique({ | ||
| where: { slug }, | ||
| include: { | ||
| sections: { | ||
| orderBy: { order: "asc" }, | ||
| }, | ||
| }, | ||
| }); | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
apps/web/src/app/(main)/dashboard/newsletters/[slug]/NewsletterDetailClient.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| "use client"; | ||
|
|
||
| import { Suspense, lazy } from "react"; | ||
| import Link from "next/link"; | ||
| import { useNewsletterDetail } from "@/app/api/newsletter"; | ||
| import { NewsletterIssue } from "@/data/newsletters"; | ||
| import { NewsletterHero } from "@/components/newsletter/NewsletterHero"; | ||
| import { NewsletterSectionRenderer } from "@/components/newsletter/NewsletterSectionRenderer"; | ||
| import { EngagementBar } from "../engagementBar"; | ||
|
|
||
| const LazyNewsletterSectionRenderer = lazy(() => | ||
| import("@/components/newsletter/NewsletterSectionRenderer").then((mod) => ({ | ||
| default: mod.NewsletterSectionRenderer, | ||
| })) | ||
| ); | ||
|
|
||
| type NewsletterDetailClientProps = { | ||
| slug: string; | ||
| fallback: NewsletterIssue; | ||
| }; | ||
|
|
||
| function SectionsSkeleton() { | ||
| return ( | ||
| <div className="space-y-8"> | ||
| {[1, 2, 3].map((i) => ( | ||
| <div key={i} className="space-y-3 animate-pulse"> | ||
| <div className="h-8 w-48 rounded-lg bg-ox-black-2" /> | ||
| <div className="space-y-2"> | ||
| <div className="h-4 w-full rounded bg-ox-black-2" /> | ||
| <div className="h-4 w-5/6 rounded bg-ox-black-2" /> | ||
| </div> | ||
| </div> | ||
| ))} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| function NavigationButtons() { | ||
| return ( | ||
| <div className="flex gap-3 flex-wrap"> | ||
| <Link | ||
| href="/dashboard/newsletters" | ||
| className="rounded-full border border-ox-purple px-6 py-2 text-xs font-semibold uppercase tracking-wide text-ox-purple transition hover:bg-ox-purple hover:text-ox-white" | ||
| > | ||
| Home | ||
| </Link> | ||
| <Link | ||
| href="/pricing" | ||
| className="rounded-full border border-ox-purple px-6 py-2 text-xs font-semibold uppercase tracking-wide text-ox-purple transition hover:bg-ox-purple hover:text-ox-white" | ||
| > | ||
| Pricing | ||
| </Link> | ||
| <a | ||
| href="https://discord.gg/opensox" | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| className="rounded-full border border-ox-purple px-6 py-2 text-xs font-semibold uppercase tracking-wide text-ox-purple transition hover:bg-ox-purple hover:text-ox-white" | ||
| > | ||
| Community | ||
| </a> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| export function NewsletterDetailClient({ slug, fallback }: NewsletterDetailClientProps) { | ||
| const { data, isLoading } = useNewsletterDetail(slug); | ||
| const issue = data ?? fallback; | ||
|
|
||
| if (!issue) return null; | ||
|
|
||
| return ( | ||
| <div className="flex flex-col gap-6 p-4 xl:p-6"> | ||
| {/* @ts-ignore */} | ||
| <NewsletterHero issue={issue} shareButton={<EngagementBar slug={slug} />} /> | ||
| <NavigationButtons /> | ||
| <Suspense fallback={<SectionsSkeleton />}> | ||
| {/* @ts-ignore */} | ||
| <LazyNewsletterSectionRenderer sections={issue.sections} /> | ||
| </Suspense> | ||
Shivam107 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| </div> | ||
| ); | ||
| } | ||
19 changes: 19 additions & 0 deletions
19
apps/web/src/app/(main)/dashboard/newsletters/[slug]/page.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { notFound } from "next/navigation"; | ||
| import { newsletterIssues } from "@/data/newsletters"; | ||
| import { NewsletterDetailClient } from "./NewsletterDetailClient"; | ||
|
|
||
| interface PageProps { | ||
| params: Promise<{ slug: string }>; | ||
| } | ||
|
|
||
|
|
||
| export default async function NewsletterDetail({ params }: PageProps) { | ||
| const { slug } = await params; | ||
| const fallback = newsletterIssues.find((issue) => issue.slug === slug); | ||
|
|
||
| if (!fallback) { | ||
| notFound(); | ||
| } | ||
|
|
||
| return <NewsletterDetailClient slug={slug} fallback={fallback} />; | ||
| } |
49 changes: 49 additions & 0 deletions
49
apps/web/src/app/(main)/dashboard/newsletters/engagementBar.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| "use client"; | ||
|
|
||
| import { useCallback, useState } from "react"; | ||
|
|
||
| interface EngagementBarProps { | ||
| slug: string; | ||
| } | ||
|
|
||
| export type { EngagementBarProps }; | ||
|
|
||
| export function EngagementBar({ slug }: EngagementBarProps) { | ||
| const link = `/dashboard/newsletters/${slug}`; | ||
| const [copied, setCopied] = useState(false); | ||
|
|
||
| const handleShare = useCallback(async () => { | ||
| if (typeof window === "undefined") return; | ||
| const absoluteUrl = `${window.location.origin}${link}`; | ||
|
|
||
| // Try native share API first | ||
| if (navigator.share) { | ||
| try { | ||
| await navigator.share({ | ||
| url: absoluteUrl, | ||
| }); | ||
| return; | ||
| } catch (error) { | ||
| console.error("Share failed:", error); | ||
| } | ||
| } | ||
|
|
||
| // Fallback to copy to clipboard | ||
| try { | ||
| await navigator.clipboard.writeText(absoluteUrl); | ||
| setCopied(true); | ||
| setTimeout(() => setCopied(false), 2000); | ||
| } catch (error) { | ||
| console.error("Unable to copy link", error); | ||
| } | ||
| }, [link]); | ||
|
|
||
| return ( | ||
| <button | ||
| onClick={handleShare} | ||
| className="rounded-full border border-ox-purple px-4 py-2 text-xs font-semibold uppercase tracking-wide text-ox-purple transition hover:bg-ox-purple hover:text-ox-white" | ||
| > | ||
| {copied ? "Copied!" : "Share"} | ||
| </button> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| "use client"; | ||
|
|
||
| import { useMemo, useState, Suspense, lazy } from "react"; | ||
| import { useNewsletterList } from "@/app/api/newsletter"; | ||
| import { newsletterIssues as mockIssues, type NewsletterIssue } from "@/data/newsletters"; | ||
|
|
||
| const LazyNewsletterCard = lazy(() => | ||
| import("@/components/newsletter/NewsletterCard").then((mod) => ({ | ||
| default: mod.NewsletterCard, | ||
| })) | ||
| ); | ||
|
|
||
| function CardSkeleton() { | ||
| return ( | ||
| <div className="h-20 animate-pulse rounded-3xl border border-ox-gray bg-ox-black-2" /> | ||
| ); | ||
| } | ||
|
|
||
| function NewsletterCardList({ issues }: { issues: NewsletterIssue[] }) { | ||
| return ( | ||
| <> | ||
| {issues.map((issue: NewsletterIssue) => ( | ||
| <Suspense key={issue.slug} fallback={<CardSkeleton />}> | ||
| <LazyNewsletterCard issue={issue} /> | ||
| </Suspense> | ||
| ))} | ||
| </> | ||
| ); | ||
| } | ||
|
|
||
| export default function NewsletterIndex() { | ||
| const [query, setQuery] = useState(""); | ||
| const { data, isLoading } = useNewsletterList(query) as { | ||
| data: NewsletterIssue[] | undefined; | ||
| isLoading: boolean; | ||
| }; | ||
| const issues = data?.length ? data : mockIssues; | ||
|
|
||
| const filteredIssues = useMemo<NewsletterIssue[]>(() => { | ||
| const normalized = query.trim().toLowerCase(); | ||
| if (!normalized) return issues as NewsletterIssue[]; | ||
|
|
||
| return (issues as NewsletterIssue[]).filter((issue) => | ||
| `${issue.title} ${issue.summary}` | ||
| .toLowerCase() | ||
| .includes(normalized) | ||
| ); | ||
| }, [issues, query]); | ||
|
|
||
| return ( | ||
| <div className="flex flex-col gap-6 p-4 xl:p-6"> | ||
| <div className="rounded-3xl border border-ox-gray bg-ox-black-1 px-5 py-6 shadow-sm sm:px-7"> | ||
| <h1 className="text-center text-3xl font-semibold text-ox-white md:text-4xl">Newsletter</h1> | ||
| {query && ( | ||
| <div className="mt-4 flex w-full max-w-lg items-center rounded-full border border-ox-gray bg-ox-black-2 px-4 py-2"> | ||
| <input | ||
| type="search" | ||
| value={query} | ||
| onChange={(e) => setQuery(e.target.value)} | ||
| placeholder="Search newsletters" | ||
| disabled={isLoading} | ||
| className="w-full bg-transparent text-sm text-ox-white placeholder:text-ox-gray-light focus:outline-none" | ||
| /> | ||
| </div> | ||
| )} | ||
Shivam107 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| </div> | ||
| <section className="grid gap-3"> | ||
| {isLoading ? ( | ||
| <SkeletonList /> | ||
| ) : filteredIssues.length > 0 ? ( | ||
| <NewsletterCardList issues={filteredIssues} /> | ||
| ) : ( | ||
| <EmptyState query={query} /> | ||
| )} | ||
| </section> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| function SkeletonList() { | ||
| return ( | ||
| <div className="space-y-3"> | ||
| {[1, 2, 3].map((key) => ( | ||
| <div | ||
| key={key} | ||
| className="h-32 animate-pulse rounded-3xl border border-ox-gray bg-ox-black-2" | ||
| /> | ||
| ))} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| function EmptyState({ query }: { query: string }) { | ||
| return ( | ||
| <div className="rounded-3xl border border-dashed border-ox-gray bg-ox-black-1 p-10 text-center"> | ||
| <h2 className="text-lg font-semibold text-ox-white">No matches found</h2> | ||
| <p className="mt-2 text-sm text-ox-gray-light"> | ||
| We couldn’t find any newsletters for “{query}”. Try a different keyword or clear the search | ||
| filter. | ||
| </p> | ||
| </div> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
Remove unused import.
The
paymentRouterimport is no longer used in theappRouterafter being replaced withnewsletterRouter. This is dead code that should be removed.Apply this diff to remove the unused import:
-import { paymentRouter } from "./payment.js";📝 Committable suggestion
🤖 Prompt for AI Agents