feat: add feature UI components with useQuery hooks
- navigation: SiteHeader component + useHeader hook - blog: ArticleCard, ArticleList, ArticleDetail + useArticleList, useArticleBySlug hooks - marketing-pages: PageHero, PageContent + usePageBySlug, useSiteSettings hooks - App pages now thin server wrappers that prefetch + hydrate; feature components own their data fetching via useSuspenseQuery
This commit is contained in:
25
packages/marketing-pages/src/ui/components/page-content.tsx
Normal file
25
packages/marketing-pages/src/ui/components/page-content.tsx
Normal file
@@ -0,0 +1,25 @@
|
||||
"use client";
|
||||
|
||||
import { usePageBySlug } from "../hooks/use-page-by-slug";
|
||||
import { PageHero } from "./page-hero";
|
||||
|
||||
export type PageContentProps = {
|
||||
slug: string;
|
||||
};
|
||||
|
||||
export function PageContent({ slug }: PageContentProps) {
|
||||
const { data: page } = usePageBySlug(slug);
|
||||
|
||||
if (!page) return null;
|
||||
|
||||
return (
|
||||
<article className="mx-auto max-w-3xl">
|
||||
<PageHero hero={page.hero} />
|
||||
<div className="prose text-foreground">
|
||||
<pre className="whitespace-pre-wrap text-sm">
|
||||
{JSON.stringify(page.layout, null, 2)}
|
||||
</pre>
|
||||
</div>
|
||||
</article>
|
||||
);
|
||||
}
|
||||
16
packages/marketing-pages/src/ui/components/page-hero.tsx
Normal file
16
packages/marketing-pages/src/ui/components/page-hero.tsx
Normal file
@@ -0,0 +1,16 @@
|
||||
import type { Hero } from "../../entities/models/page";
|
||||
|
||||
export type PageHeroProps = {
|
||||
hero: Hero;
|
||||
};
|
||||
|
||||
export function PageHero({ hero }: PageHeroProps) {
|
||||
return (
|
||||
<header className="mb-8">
|
||||
<h1 className="text-3xl font-bold text-foreground">{hero.heading}</h1>
|
||||
{hero.subheading ? (
|
||||
<p className="mt-2 text-lg text-muted-foreground">{hero.subheading}</p>
|
||||
) : null}
|
||||
</header>
|
||||
);
|
||||
}
|
||||
12
packages/marketing-pages/src/ui/hooks/use-page-by-slug.ts
Normal file
12
packages/marketing-pages/src/ui/hooks/use-page-by-slug.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
"use client";
|
||||
|
||||
import { useSuspenseQuery } from "@tanstack/react-query";
|
||||
import { useTRPC } from "@repo/core-trpc";
|
||||
import type { Page } from "../../entities/models/page";
|
||||
|
||||
export function usePageBySlug(slug: string) {
|
||||
const trpc = useTRPC();
|
||||
return useSuspenseQuery(
|
||||
trpc.marketingPages.pageBySlug.queryOptions({ slug }),
|
||||
) as { data: Page | null };
|
||||
}
|
||||
12
packages/marketing-pages/src/ui/hooks/use-site-settings.ts
Normal file
12
packages/marketing-pages/src/ui/hooks/use-site-settings.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
"use client";
|
||||
|
||||
import { useSuspenseQuery } from "@tanstack/react-query";
|
||||
import { useTRPC } from "@repo/core-trpc";
|
||||
import type { SiteSettings } from "../../entities/models/site-settings";
|
||||
|
||||
export function useSiteSettings() {
|
||||
const trpc = useTRPC();
|
||||
return useSuspenseQuery(
|
||||
trpc.marketingPages.siteSettings.queryOptions({}),
|
||||
) as { data: SiteSettings };
|
||||
}
|
||||
@@ -1 +1,5 @@
|
||||
export { pageBySlugQuery, siteSettingsQuery } from "./query";
|
||||
export { usePageBySlug } from "./hooks/use-page-by-slug";
|
||||
export { useSiteSettings } from "./hooks/use-site-settings";
|
||||
export { PageHero, type PageHeroProps } from "./components/page-hero";
|
||||
export { PageContent, type PageContentProps } from "./components/page-content";
|
||||
|
||||
Reference in New Issue
Block a user