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.

getContentAPI

Steven Tey0a3b835d5214
diff --git a/apps/web/lib/fetchers.ts b/apps/web/lib/fetchers.ts
index f6f9f4dd3e..d46b7b9501 100644
--- a/apps/web/lib/fetchers.ts
+++ b/apps/web/lib/fetchers.ts
@@ -2,6 +2,14 @@ import { prisma } from "@/lib/prisma";
import { cache } from "react";
import { getSession } from "./auth";
+export const getContentAPI = cache(async () => {
+ return await fetch("https://dub.co/api/content", {
+ next: {
+ revalidate: 60 * 60 * 24, // cache for 24 hours
+ },
+ }).then((res) => res.json());
+});
+
export const getDefaultWorkspace = cache(async () => {
const session = await getSession();
if (!session) {
diff --git a/apps/web/ui/layout/sidebar/help-button-rsc.tsx b/apps/web/ui/layout/sidebar/help-button-rsc.tsx
index 315497d919..4ddcfb197e 100644
--- a/apps/web/ui/layout/sidebar/help-button-rsc.tsx
+++ b/apps/web/ui/layout/sidebar/help-button-rsc.tsx
@@ -1,14 +1,8 @@
+import { getContentAPI } from "@/lib/fetchers";
import { HelpButton } from "./help-button";
export async function HelpButtonRSC() {
- const { popularHelpArticles, allHelpArticles } = await fetch(
- "https://dub.co/api/content",
- {
- next: {
- revalidate: 60 * 60 * 24, // cache for 24 hours
- },
- },
- ).then((res) => res.json());
+ const { popularHelpArticles, allHelpArticles } = await getContentAPI();
return (
<HelpButton
diff --git a/apps/web/ui/layout/sidebar/news-rsc.tsx b/apps/web/ui/layout/sidebar/news-rsc.tsx
index 93fbf07f97..796746f9a3 100644
--- a/apps/web/ui/layout/sidebar/news-rsc.tsx
+++ b/apps/web/ui/layout/sidebar/news-rsc.tsx
@@ -1,29 +1,16 @@
+import { getContentAPI } from "@/lib/fetchers";
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());
+ const { latestNewsArticles } = await getContentAPI();
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}`,
- }))}
+ articles={
+ (Array.isArray(latestNewsArticles)
+ ? latestNewsArticles
+ : []) as NewsArticle[]
+ }
/>
);
}
diff --git a/apps/web/ui/layout/sidebar/news.tsx b/apps/web/ui/layout/sidebar/news.tsx
index 81cda3499b..993e18aa7d 100644
--- a/apps/web/ui/layout/sidebar/news.tsx
+++ b/apps/web/ui/layout/sidebar/news.tsx
@@ -11,7 +11,6 @@ export interface NewsArticle {
title: string;
summary: string;
image: string;
- href: string;
}
const OFFSET_FACTOR = 4;
@@ -25,9 +24,9 @@ export function News({ articles }: { articles: NewsArticle[] }) {
return cards.length ? (
<div className="group overflow-hidden px-3 pb-3 pt-8">
<div className="relative size-full">
- {cards.map(({ slug, type, title, summary, image, href }, idx) => (
+ {cards.map(({ slug, type, title, summary, image }, idx) => (
<div
- key={`${slug}-${type}`}
+ key={slug}
className={cn(
"absolute left-0 top-0 scale-[var(--scale)] transition-[opacity,transform] duration-200",
cardCount - idx > 3
@@ -51,7 +50,7 @@ export function News({ articles }: { articles: NewsArticle[] }) {
title={title}
description={summary}
image={image}
- href={href}
+ href={slug}
hideContent={cardCount - idx > 2}
active={idx === cardCount - 1}
onDismiss={() => {