Skip to content

Commit 6d2e58e

Browse files
committed
feat(basic-starter): upgrade starters to NextDrupal classes
Issue #601
1 parent 1c3b13f commit 6d2e58e

File tree

25 files changed

+281
-163
lines changed

25 files changed

+281
-163
lines changed

examples/example-router-migration/lib/drupal.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import {
33
// NextDrupal
44
} from "next-drupal"
55

6-
const baseUrl: string = process.env.NEXT_PUBLIC_DRUPAL_BASE_URL || ""
7-
const clientId = process.env.DRUPAL_CLIENT_ID || ""
8-
const clientSecret = process.env.DRUPAL_CLIENT_SECRET || ""
6+
const baseUrl = process.env.NEXT_PUBLIC_DRUPAL_BASE_URL as string
7+
const clientId = process.env.DRUPAL_CLIENT_ID as string
8+
const clientSecret = process.env.DRUPAL_CLIENT_SECRET as string
99

1010
export const drupal = new DrupalClient(baseUrl, {
1111
auth: {

starters/basic-starter/.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
.pnp.js
77
.yarn/install-state.gz
88

9-
# build/test artifacts
10-
/.turbo
9+
# testing
1110
/coverage
1211

1312
# next.js

starters/basic-starter/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Basic Starter
22

3-
A simple starter for building your site with Next.js and Drupal.
3+
A simple starter for building your site with Next.js' Pages Router and Drupal.
44

55
## How to use
66

starters/basic-starter/components/Layout.tsx

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,13 @@
1-
import Link from "next/link"
2-
import { PreviewAlert } from "@/components/PreviewAlert"
1+
import { HeaderNav } from "@/components/navigation/HeaderNav"
2+
import { PreviewAlert } from "@/components/misc/PreviewAlert"
33
import type { ReactNode } from "react"
44

55
export function Layout({ children }: { children: ReactNode }) {
66
return (
77
<>
88
<PreviewAlert />
99
<div className="max-w-screen-md px-6 mx-auto">
10-
<header>
11-
<div className="container flex items-center justify-between py-6 mx-auto">
12-
<Link href="/" className="text-2xl font-semibold no-underline">
13-
Next.js for Drupal
14-
</Link>
15-
<Link
16-
href="https://next-drupal.org/docs"
17-
target="_blank"
18-
rel="external"
19-
className="hover:text-blue-600"
20-
>
21-
Read the docs
22-
</Link>
23-
</div>
24-
</header>
10+
<HeaderNav />
2511
<main className="container py-10 mx-auto">{children}</main>
2612
</div>
2713
</>

starters/basic-starter/components/drupal/ArticleTeaser.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Image from "next/image"
2-
import Link from "next/link"
2+
import { Link } from "@/components/navigation/Link"
33
import { absoluteUrl, formatDate } from "@/lib/utils"
44
import type { DrupalNode } from "next-drupal"
55

starters/basic-starter/components/PreviewAlert.tsx renamed to starters/basic-starter/components/misc/PreviewAlert.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,18 @@ export function PreviewAlert() {
1414
return null
1515
}
1616

17+
function buttonHandler() {
18+
void fetch("/api/exit-preview")
19+
setShowPreviewAlert(false)
20+
}
21+
1722
return (
1823
<div className="sticky top-0 left-0 z-50 w-full px-2 py-1 text-center text-white bg-black">
1924
<p className="mb-0">
2025
This page is a preview.{" "}
2126
<button
2227
className="inline-block ml-3 rounded border px-1.5 hover:bg-white hover:text-black active:bg-gray-200 active:text-gray-500"
23-
onClick={() => router.push("/api/exit-preview")}
28+
onClick={buttonHandler}
2429
>
2530
Exit preview mode
2631
</button>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Link } from "@/components/navigation/Link"
2+
3+
export function HeaderNav() {
4+
return (
5+
<header>
6+
<div className="container flex items-center justify-between py-6 mx-auto">
7+
<Link href="/" className="text-2xl font-semibold no-underline">
8+
Next.js for Drupal
9+
</Link>
10+
<Link
11+
href="https://next-drupal.org/docs"
12+
target="_blank"
13+
rel="external"
14+
className="hover:text-blue-600"
15+
>
16+
Read the docs
17+
</Link>
18+
</div>
19+
</header>
20+
)
21+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { forwardRef } from "react"
2+
import NextLink from "next/link"
3+
import type { AnchorHTMLAttributes, ReactNode } from "react"
4+
import type { LinkProps as NextLinkProps } from "next/link"
5+
6+
type LinkProps = NextLinkProps &
7+
Omit<AnchorHTMLAttributes<HTMLAnchorElement>, keyof NextLinkProps> & {
8+
children?: ReactNode
9+
}
10+
11+
export const Link = forwardRef<HTMLAnchorElement, LinkProps>(
12+
function LinkWithRef(
13+
{
14+
// Turn next/link prefetching off by default.
15+
// @see https://github.com/vercel/next.js/discussions/24009
16+
prefetch = false,
17+
...rest
18+
},
19+
ref
20+
) {
21+
return <NextLink prefetch={prefetch} {...rest} ref={ref} />
22+
}
23+
)
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
import { DrupalClient } from "next-drupal"
1+
import { NextDrupalPages } from "next-drupal"
22

3-
const baseUrl: string = process.env.NEXT_PUBLIC_DRUPAL_BASE_URL || ""
4-
const clientId = process.env.DRUPAL_CLIENT_ID || ""
5-
const clientSecret = process.env.DRUPAL_CLIENT_SECRET || ""
3+
const baseUrl = process.env.NEXT_PUBLIC_DRUPAL_BASE_URL as string
4+
const clientId = process.env.DRUPAL_CLIENT_ID as string
5+
const clientSecret = process.env.DRUPAL_CLIENT_SECRET as string
66

7-
export const drupal = new DrupalClient(baseUrl, {
7+
export const drupal = new NextDrupalPages(baseUrl, {
88
auth: {
99
clientId,
1010
clientSecret,
1111
},
12+
useDefaultEndpoints: true,
13+
// debug: true,
1214
})

starters/basic-starter/tsconfig.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,15 @@
1414
"isolatedModules": true,
1515
"jsx": "preserve",
1616
"incremental": true,
17+
"plugins": [
18+
{
19+
"name": "next"
20+
}
21+
],
1722
"paths": {
1823
"@/*": ["./*"]
1924
}
2025
},
21-
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
26+
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
2227
"exclude": ["node_modules"]
2328
}

0 commit comments

Comments
 (0)