Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Pull news articles from `dub.co` API

Tim Wilsone5f1d5efba71
diff --git a/apps/web/app/app.dub.co/(dashboard)/layout.tsx b/apps/web/app/app.dub.co/(dashboard)/layout.tsx
index b5361a442d..07b01ec73b 100644
--- a/apps/web/app/app.dub.co/(dashboard)/layout.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/layout.tsx
@@ -1,5 +1,6 @@
import { MainNav } from "@/ui/layout/main-nav";
import { HelpButtonRSC } from "@/ui/layout/sidebar/help-button-rsc";
+import { NewsRSC } from "@/ui/layout/sidebar/news-rsc";
import Toolbar from "@/ui/layout/toolbar/toolbar";
import { constructMetadata } from "@dub/utils";
import { ReactNode } from "react";
@@ -12,7 +13,9 @@ export default async function Layout({ children }: { children: ReactNode }) {
return (
<Providers>
<div className="min-h-screen w-full bg-white">
- <MainNav toolContent={<HelpButtonRSC />}>{children}</MainNav>
+ <MainNav toolContent={<HelpButtonRSC />} newsContent={<NewsRSC />}>
+ {children}
+ </MainNav>
</div>
{/* <ChangelogPopup /> */}
<Toolbar show={["onboarding"]} />
diff --git a/apps/web/ui/layout/main-nav.tsx b/apps/web/ui/layout/main-nav.tsx
index 132fa12ea1..5f52310f5b 100644
--- a/apps/web/ui/layout/main-nav.tsx
+++ b/apps/web/ui/layout/main-nav.tsx
@@ -27,7 +27,8 @@ export const SideNavContext = createContext<SideNavContext>({
export function MainNav({
children,
toolContent,
-}: PropsWithChildren<{ toolContent?: ReactNode }>) {
+ newsContent,
+}: PropsWithChildren<{ toolContent?: ReactNode; newsContent?: ReactNode }>) {
const pathname = usePathname();
const { isMobile } = useMediaQuery();
@@ -78,7 +79,7 @@ export function MainNav({
)}
/>
</div>
- <SidebarNav toolContent={toolContent} />
+ <SidebarNav toolContent={toolContent} newsContent={newsContent} />
</div>
</div>
<div className="bg-neutral-100 md:pt-1.5">
diff --git a/apps/web/ui/layout/sidebar/news-rsc.tsx b/apps/web/ui/layout/sidebar/news-rsc.tsx
new file mode 100644
index 0000000000..93fbf07f97
--- /dev/null
+++ b/apps/web/ui/layout/sidebar/news-rsc.tsx
@@ -0,0 +1,29 @@
+import { News, NewsArticle } from "./news";
+
+export async function NewsRSC() {
+ const { latestNewsArticles } = await fetch(
+ // "https://dub.co/api/content?type=news",
+ "https://dub-site-git-news-api-dubinc.vercel.app/api/content?type=news", // TODO: Update to dub.co
+ {
+ next: {
+ revalidate: 60 * 60 * 24, // cache for 24 hours
+ },
+ },
+ ).then((res) => res.json());
+
+ return (
+ <News
+ articles={(
+ (Array.isArray(latestNewsArticles) ? latestNewsArticles : []) as Omit<
+ NewsArticle,
+ "href"
+ >[]
+ )
+ .slice(0, 6) // Limit to 6 latest articles
+ .map((article) => ({
+ ...article,
+ href: `https://dub.co/${article.type === "ChangelogPost" ? "changelog" : "blog"}/${article.slug}`,
+ }))}
+ />
+ );
+}
diff --git a/apps/web/ui/layout/sidebar/news.tsx b/apps/web/ui/layout/sidebar/news.tsx
index dab0b86e52..b7e19f3c5a 100644
--- a/apps/web/ui/layout/sidebar/news.tsx
+++ b/apps/web/ui/layout/sidebar/news.tsx
@@ -1,21 +1,33 @@
+"use client";
+
import { cn } from "@dub/utils";
+import Image from "next/image";
import Link from "next/link";
import { CSSProperties, useRef, useState } from "react";
+export interface NewsArticle {
+ slug: string;
+ type: string;
+ title: string;
+ summary: string;
+ image: string;
+ href: string;
+}
+
const OFFSET_FACTOR = 4;
const SCALE_FACTOR = 0.03;
const OPACITY_FACTOR = 0.1;
-export function News() {
- const [cards, setCards] = useState([1, 2, 3, 4, 5, 6]);
+export function News({ articles }: { articles: NewsArticle[] }) {
+ const [cards, setCards] = useState(articles);
const cardCount = cards.length;
return cards.length ? (
<div className="overflow-hidden px-3 pb-3 pt-8">
<div className="group relative size-full">
- {cards.map((id, idx) => (
+ {cards.map(({ slug, type, title, summary, image, href }, idx) => (
<div
- key={id}
+ key={`${slug}-${type}`}
className={cn(
"absolute left-0 top-0 scale-[var(--scale)] transition-[opacity,transform] duration-200",
cardCount - idx > 3
@@ -36,12 +48,16 @@ export function News() {
>
<NewsCard
key={idx}
- title="Title Title"
- description="Description of the article that clicking this card will take you to"
+ title={title}
+ description={summary}
+ image={image}
+ href={href}
hideContent={cardCount - idx > 2}
active={idx === cardCount - 1}
onDismiss={() => {
- setCards((cards) => cards.filter((c) => c !== id));
+ setCards((cards) =>
+ cards.filter((c) => c.slug !== slug || c.type !== type),
+ );
}}
/>
</div>
@@ -60,14 +76,18 @@ export function News() {
function NewsCard({
title,
description,
+ image,
onDismiss,
hideContent,
+ href,
active,
}: {
title: string;
description: string;
+ image?: string;
onDismiss?: () => void;
hideContent?: boolean;
+ href?: string;
active?: boolean;
}) {
const ref = useRef<HTMLDivElement>(null);
@@ -145,7 +165,16 @@ function NewsCard({
</span>
<p className="line-clamp-2 text-neutral-500">{description}</p>
</div>
- <div className="mt-3 aspect-[16/9] w-full shrink-0 rounded bg-neutral-200" />
+ <div className="relative mt-3 aspect-[16/9] w-full shrink-0 overflow-hidden rounded border border-neutral-200 bg-neutral-100">
+ {image && (
+ <Image
+ src={image}
+ alt=""
+ fill
+ className="rounded object-cover object-center"
+ />
+ )}
+ </div>
<div
className={cn(
"h-0 overflow-hidden opacity-0 transition-[height,opacity] duration-200",
@@ -154,7 +183,8 @@ function NewsCard({
>
<div className="flex items-center justify-between pt-3 text-xs">
<Link
- href="#"
+ href={href || "https://dub.co"}
+ target="_blank"
className="font-medium text-neutral-700 transition-colors duration-75 hover:text-neutral-900"
>
Read more
diff --git a/apps/web/ui/layout/sidebar/sidebar-nav.tsx b/apps/web/ui/layout/sidebar/sidebar-nav.tsx
index 6bc46cd8e0..f78b4a19a8 100644
--- a/apps/web/ui/layout/sidebar/sidebar-nav.tsx
+++ b/apps/web/ui/layout/sidebar/sidebar-nav.tsx
@@ -13,14 +13,19 @@ import {
} from "react";
import UserSurveyButton from "../user-survey";
import { ITEMS, type NavItem as NavItemType } from "./items";
-import { News } from "./news";
import { Usage } from "./usage";
import UserDropdown from "./user-dropdown";
import { WorkspaceDropdown } from "./workspace-dropdown";
const AREAS = ["userSettings", "workspaceSettings", "default"] as const;
-export function SidebarNav({ toolContent }: { toolContent?: ReactNode }) {
+export function SidebarNav({
+ toolContent,
+ newsContent,
+}: {
+ toolContent?: ReactNode;
+ newsContent?: ReactNode;
+}) {
const { slug } = useParams() as { slug?: string };
const { flags } = useWorkspace();
const pathname = usePathname();
@@ -94,7 +99,7 @@ export function SidebarNav({ toolContent }: { toolContent?: ReactNode }) {
))}
</div>
<div className="-mx-3 mt-6 flex grow flex-col justify-end">
- {area === "default" && <News />}
+ {area === "default" && newsContent}
</div>
</Area>
))}