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

Update dependencies fix page #106

Merged
merged 9 commits into from
Jan 27, 2025
4 changes: 2 additions & 2 deletions nextjs-app/app/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Head from "next/head";
import PageBuilderPage from "@/app/components/PageBuilder";
import { sanityFetch } from "@/sanity/lib/live";
import { getPageQuery, pagesSlugs } from "@/sanity/lib/queries";
import { Page as PageType } from "@/sanity.types";
import { GetPageQueryResult } from "@/sanity.types";
import { PageOnboarding } from "@/app/components/Onboarding";

type Props = {
Expand Down Expand Up @@ -77,7 +77,7 @@ export default async function Page(props: Props) {
</div>
</div>
</div>
<PageBuilderPage page={page as PageType} />
<PageBuilderPage page={page as GetPageQueryResult} />
</div>
);
}
2 changes: 1 addition & 1 deletion nextjs-app/app/components/InfoSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function CTA({ block }: InfoProps) {
{block.subheading}
</span>
)}
<div className="prose prose-a:text-red-500 mt-4">
<div className="mt-4">
{block?.content?.length && (
<PortableText
className=""
Expand Down
27 changes: 20 additions & 7 deletions nextjs-app/app/components/PageBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { useOptimistic } from "next-sanity/hooks";
import Link from "next/link";

import BlockRenderer from "@/app/components/BlockRenderer";
import { Page } from "@/sanity.types";
import { GetPageQueryResult } from "@/sanity.types";
import { dataAttr } from "@/sanity/lib/utils";
import { studioUrl } from "@/sanity/lib/api";

type PageBuilderPageProps = {
page: Page;
page: GetPageQueryResult;
};

type PageBuilderSection = {
Expand All @@ -28,7 +28,13 @@ type PageData = {
* The PageBuilder component is used to render the blocks from the `pageBuilder` field in the Page type in your Sanity Studio.
*/

function renderSections(pageBuilderSections: PageBuilderSection[], page: Page) {
function renderSections(
pageBuilderSections: PageBuilderSection[],
page: GetPageQueryResult
) {
if (!page) {
return null;
}
return (
<div
data-sanity={dataAttr({
Expand All @@ -50,7 +56,10 @@ function renderSections(pageBuilderSections: PageBuilderSection[], page: Page) {
);
}

function renderEmptyState(page: Page) {
function renderEmptyState(page: GetPageQueryResult) {
if (!page) {
return null;
}
return (
<div className="container">
<h1 className="text-4xl font-extrabold text-gray-900 tracking-tight sm:text-5xl">
Expand All @@ -77,12 +86,12 @@ export default function PageBuilder({ page }: PageBuilderPageProps) {
const pageBuilderSections = useOptimistic<
PageBuilderSection[] | undefined,
SanityDocument<PageData>
>(page?.pageBuilder, (currentSections, action) => {
>(page?.pageBuilder || [], (currentSections, action) => {
// The action contains updated document data from Sanity
// when someone makes an edit in the Studio

// If the edit was to a different document, ignore it
if (action.id !== page._id) {
if (action.id !== page?._id) {
return currentSections;
}

Expand All @@ -91,14 +100,18 @@ export default function PageBuilder({ page }: PageBuilderPageProps) {
// Reconcile References. https://www.sanity.io/docs/enabling-drag-and-drop#ffe728eea8c1
return action.document.pageBuilder.map(
(section) =>
currentSections?.find((s) => s._key === section?._key) || section,
currentSections?.find((s) => s._key === section?._key) || section
);
}

// Otherwise keep the current sections
return currentSections;
});

if (!page) {
return renderEmptyState(page);
}

return pageBuilderSections && pageBuilderSections.length > 0
? renderSections(pageBuilderSections, page)
: renderEmptyState(page);
Expand Down
6 changes: 5 additions & 1 deletion nextjs-app/app/components/PortableText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ export default function CustomPortableText({
};

return (
<div className={["prose", className].filter(Boolean).join(" ")}>
<div
className={["prose prose-a:text-red-500", className]
.filter(Boolean)
.join(" ")}
>
<PortableText components={components} value={value} />
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion nextjs-app/app/posts/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export async function generateStaticParams() {
*/
export async function generateMetadata(
props: Props,
parent: ResolvingMetadata,
parent: ResolvingMetadata
): Promise<Metadata> {
const params = await props.params;
const { data: post } = await sanityFetch({
Expand Down
22 changes: 11 additions & 11 deletions nextjs-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@
"@sanity/image-url": "^1.1.0",
"@sanity/uuid": "^3.0.2",
"@tailwindcss/typography": "^0.5.15",
"@types/node": "^20.14.13",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@vercel/speed-insights": "^1.1.0",
"autoprefixer": "^10.4.20",
"date-fns": "^3.6.0",
"next": "^15.0.4",
"next-sanity": "^9.8.18",
"postcss": "^8.4.49",
"next": "^15.1.6",
"next-sanity": "^9.8.42",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"sanity": "^3.65.0",
"sanity": "^3.71.2",
"sonner": "^1.7.0",
"styled-components": "^6.1.13",
"tailwindcss": "^3.4.15",
"typescript": "5.6.3"
"styled-components": "^6.1.13"
},
"devDependencies": {
"typescript": "5.6.3",
"eslint": "^8.57.0",
"eslint-config-next": "^15.0.3"
"@types/react-dom": "^18.3.1",
"@types/node": "^20.14.13",
"@types/react": "^18.3.12",
"eslint-config-next": "^15.0.3",
"postcss": "^8.4.49",
"tailwindcss": "^3.4.15"
}
}
Loading
Loading