Skip to content

Commit

Permalink
Update cookies function and dependency libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
pookmish committed Feb 4, 2025
1 parent 116f1b8 commit 2143f04
Show file tree
Hide file tree
Showing 25 changed files with 4,526 additions and 18,665 deletions.
574 changes: 287 additions & 287 deletions .yarn/releases/yarn-4.5.3.cjs → .yarn/releases/yarn-4.6.0.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.5.3.cjs
yarnPath: .yarn/releases/yarn-4.6.0.cjs
2 changes: 1 addition & 1 deletion app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const revalidate = false
export const dynamic = "force-static"

const Home = async () => {
const {entity} = await getEntityFromPath<NodeStanfordPage>("/", isPreviewMode())
const {entity} = await getEntityFromPath<NodeStanfordPage>("/")

if (!entity) notFound()

Expand Down
7 changes: 3 additions & 4 deletions app/preview/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ import {isPreviewMode} from "@lib/drupal/is-preview-mode"

const PreviewPage = async (props: PageProps) => {
const params = await props.params
if (!isPreviewMode()) notFound()
if (!(await isPreviewMode())) notFound()
const {entity} = await getEntityFromPath<NodeUnion>(getPathFromContext(params.slug), true)

if (!entity) notFound()

return (
<>
<UnpublishedBanner status={entity.status} message="Unpublished Page" />
<UnpublishedBanner status={entity.status} message="Unpublished Page">
<NodePage node={entity} />
</>
</UnpublishedBanner>
)
}

Expand Down
9 changes: 4 additions & 5 deletions app/preview/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ import {isPreviewMode} from "@lib/drupal/is-preview-mode"
import Editori11y from "@components/tools/editorially"
import UnpublishedBanner from "@components/elements/unpublished-banner"

const Layout = ({children}: {children: React.ReactNode}) => {
const inPreview = isPreviewMode()
const Layout = async ({children}: {children: React.ReactNode}) => {
const inPreview = await isPreviewMode()
return (
<>
{inPreview && (
<>
<UnpublishedBanner status={false} message="Preview Mode">
<Editori11y />
<UnpublishedBanner status={false} message="Preview Mode" />
</>
</UnpublishedBanner>
)}
{children}
</>
Expand Down
2 changes: 1 addition & 1 deletion app/preview/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {isPreviewMode} from "@lib/drupal/is-preview-mode"
import Page from "../page"

const PreviewPage = async () => {
if (!isPreviewMode()) notFound()
if (!(await isPreviewMode())) notFound()
return <Page />
}

Expand Down
52 changes: 26 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,31 @@
"dependencies": {
"@formkit/auto-animate": "^0.8.2",
"@heroicons/react": "^2.2.0",
"@mui/base": "5.0.0-beta.68",
"@next/third-parties": "15.1.4",
"@mui/base": "5.0.0-beta.69",
"@next/third-parties": "15.1.6",
"@tailwindcss/container-queries": "^0.1.1",
"@types/node": "^22.10.7",
"@types/react": "^19.0.7",
"@types/node": "^22.13.1",
"@types/react": "^19.0.8",
"@types/react-dom": "19.0.3",
"algoliasearch": "5.19.0",
"algoliasearch": "5.20.0",
"autoprefixer": "^10.4.20",
"clsx": "^2.1.1",
"decanter": "^7.3.0",
"decanter": "^7.3.1",
"drupal-jsonapi-params": "^2.3.2",
"graphql": "^16.10.0",
"graphql-request": "^7.1.2",
"graphql-tag": "^2.12.6",
"html-entities": "^2.5.2",
"html-react-parser": "^5.2.2",
"next": "^15.2.0-canary.12",
"next": "^15.1.6",
"plaiceholder": "^3.0.0",
"postcss": "^8.5.1",
"qs": "^6.14.0",
"react": "19.0.0",
"react-dom": "19.0.0",
"react-focus-lock": "^2.13.5",
"react-instantsearch": "^7.15.0",
"react-instantsearch-nextjs": "^0.4.1",
"react-instantsearch": "^7.15.3",
"react-instantsearch-nextjs": "^0.4.4",
"react-slick": "^0.30.3",
"react-tiny-oembed": "^1.1.0",
"sharp": "^0.33.5",
Expand All @@ -51,36 +51,36 @@
},
"devDependencies": {
"@graphql-codegen/add": "^5.0.3",
"@graphql-codegen/cli": "^5.0.3",
"@graphql-codegen/cli": "^5.0.4",
"@graphql-codegen/import-types-preset": "^3.0.0",
"@graphql-codegen/typescript-graphql-request": "^6.2.0",
"@graphql-codegen/typescript-operations": "^4.4.0",
"@next/bundle-analyzer": "15.1.4",
"@storybook/addon-essentials": "^8.5.0",
"@storybook/addon-interactions": "^8.5.0",
"@storybook/addon-links": "^8.5.0",
"@graphql-codegen/typescript-operations": "^4.4.1",
"@next/bundle-analyzer": "15.1.6",
"@storybook/addon-essentials": "^8.5.3",
"@storybook/addon-interactions": "^8.5.3",
"@storybook/addon-links": "^8.5.3",
"@storybook/addon-styling": "^1.3.7",
"@storybook/blocks": "^8.5.0",
"@storybook/nextjs": "^8.5.0",
"@storybook/react": "^8.5.0",
"@storybook/blocks": "^8.5.3",
"@storybook/nextjs": "^8.5.3",
"@storybook/react": "^8.5.3",
"@storybook/testing-library": "^0.2.2",
"@types/react-slick": "^0.23.13",
"concurrently": "^9.1.2",
"encoding": "^0.1.13",
"eslint": "9.18.0",
"eslint-config-next": "15.1.4",
"eslint": "9.19.0",
"eslint-config-next": "15.1.6",
"eslint-config-prettier": "^10.0.1",
"eslint-plugin-prettier": "^5.2.2",
"eslint-plugin-prettier": "^5.2.3",
"eslint-plugin-storybook": "^0.11.2",
"prettier": "^3.4.2",
"prettier-plugin-tailwindcss": "^0.6.10",
"react-docgen": "^7.1.0",
"storybook": "^8.5.0",
"prettier-plugin-tailwindcss": "^0.6.11",
"react-docgen": "^7.1.1",
"storybook": "^8.5.3",
"storybook-addon-module-mock": "^1.3.4",
"tsconfig-paths-webpack-plugin": "^4.2.0",
"typescript-eslint": "8.20.0"
"typescript-eslint": "8.23.0"
},
"packageManager": "yarn@4.5.3",
"packageManager": "yarn@4.6.0",
"resolutions": {
"@types/react": "npm:[email protected]",
"@types/react-dom": "npm:[email protected]"
Expand Down
3 changes: 1 addition & 2 deletions src/components/elements/user-analytics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import {getConfigPageField} from "@lib/gql/gql-queries"
import {StanfordBasicSiteSetting} from "@lib/gql/__generated__/drupal.d"
import Script from "next/script"
import {GoogleAnalytics} from "@next/third-parties/google"
import {isPreviewMode} from "@lib/drupal/is-preview-mode"

const UserAnalytics = async () => {
if (isPreviewMode()) return
if (process.env.NODE_ENV === "development") return

const googleAnalytics = await getConfigPageField<
StanfordBasicSiteSetting,
Expand Down
5 changes: 2 additions & 3 deletions src/components/nodes/cards/node-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import StanfordPageCard from "@components/nodes/cards/stanford-page/stanford-pag
import StanfordPersonCard from "@components/nodes/cards/stanford-person/stanford-person-card"
import StanfordPolicyCard from "@components/nodes/cards/stanford-policy/stanford-policy-card"
import StanfordPublicationCard from "@components/nodes/cards/stanford-publication/stanford-publication-card"
import {isPreviewMode} from "@lib/drupal/is-preview-mode"
import {NodeUnion} from "@lib/gql/__generated__/drupal.d"
import SupBookCard from "@components/nodes/cards/sup-book/sup-book-card"

Expand All @@ -22,9 +21,9 @@ type Props = {
}

const NodeCard = ({node, headingLevel}: Props) => {
const previewMode = isPreviewMode()

const itemProps: {[key: string]: string} = {}
if (previewMode) {
if (process.env.NODE_ENV === "development") {
itemProps["data-type"] = node.__typename || "unknown"
itemProps["data-id"] = node.id
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/nodes/list-item/node-list-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ type Props = {
}

const NodeListItem = ({node, headingLevel}: Props) => {
const previewMode = isPreviewMode()

const itemProps: {[key: string]: string} = {}
if (previewMode) {
if (process.env.NODE_ENV === "development") {
itemProps["data-type"] = node.__typename || "unknown"
itemProps["data-id"] = node.id
}
Expand Down
3 changes: 1 addition & 2 deletions src/components/nodes/pages/node-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ import SupBookPage from "@components/nodes/pages/sup-book/sup-book-page"
import SupBookAncillaryPage from "@components/nodes/pages/sup-book-ancilary/sup-book-ancillary-page"

const NodePage = ({node}: {node: NodeUnion}) => {
const previewMode = isPreviewMode()
const itemProps: {[key: string]: string} = {}

if (previewMode) {
if (process.env.NODE_ENV === "development") {
itemProps["data-type"] = node.__typename || "unknown"
itemProps["data-id"] = node.id
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type Props = HtmlHTMLAttributes<HTMLDivElement> & {
}

const StanfordCoursePage = ({node, ...props}: Props) => {
if (node.suCourseLink?.url && !isPreviewMode()) redirect(node.suCourseLink?.url)
if (node.suCourseLink?.url) redirect(node.suCourseLink?.url)
return (
<article className="centered my-32" {...props}>
<NodePageMetadata key={node.id} metatags={node.metatag} pageTitle={node.title} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Props = HtmlHTMLAttributes<HTMLDivElement> & {
}

const StanfordEventPage = ({node, ...props}: Props) => {
if (node.suEventSource?.url && !isPreviewMode()) redirect(node.suEventSource.url)
if (node.suEventSource?.url) redirect(node.suEventSource.url)

const startTime = new Date(node.suEventDateTime.value * 1000)
const endTime = new Date(node.suEventDateTime.end_value * 1000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Props = HtmlHTMLAttributes<HTMLDivElement> & {
}

const StanfordNewsPage = ({node, ...props}: Props) => {
if (node.suNewsSource?.url && !isPreviewMode()) redirect(node.suNewsSource.url)
if (node.suNewsSource?.url) redirect(node.suNewsSource.url)

const publishDate = node.suNewsPublishingDate
? new Date(node.suNewsPublishingDate.time).toLocaleDateString("en-us", {
Expand Down
6 changes: 2 additions & 4 deletions src/components/paragraphs/paragraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import SpacerParagraph from "@components/paragraphs/stanford-spacer/spacer-parag
import WysiwygParagraph from "@components/paragraphs/stanford-wysiwyg/wysiwyg-paragraph"
import BannerParagraph from "@components/paragraphs/stanford-banner/banner-paragraph"
import ListParagraph from "@components/paragraphs/stanford-lists/list-paragraph"
import {isPreviewMode} from "@lib/drupal/is-preview-mode"
import {ParagraphUnion} from "@lib/gql/__generated__/drupal.d"
import {Suspense} from "react"
import FileListParagraph from "@components/paragraphs/sup-file-list/file-list-paragraph"
Expand All @@ -32,10 +31,9 @@ const Paragraph = async ({paragraph}: Props) => {
)
}
const ParagraphComponent = async ({paragraph}: Props) => {
const previewMode = isPreviewMode()

const itemProps: Record<string, string> = {}
if (previewMode) {

if (process.env.NODE_ENV === "development") {
itemProps["data-type"] = paragraph.__typename || "unknown"
itemProps["data-id"] = paragraph.id
}
Expand Down
7 changes: 1 addition & 6 deletions src/components/paragraphs/rows/one-column.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import Paragraph from "@components/paragraphs/paragraph"
import {ParagraphUnion} from "@lib/gql/__generated__/drupal.d"
import {isPreviewMode} from "@lib/drupal/is-preview-mode"

const OneColumn = ({items}: {items: ParagraphUnion[]}) => {
const draftProps: Record<string, string> = {}
if (isPreviewMode()) {
draftProps["data-columns"] = "1"
}
return (
<div className="space-y-16" {...draftProps}>
<div className="space-y-16" data-columns="1">
{items.map(item => (
<Paragraph paragraph={item} key={item.id} />
))}
Expand Down
8 changes: 1 addition & 7 deletions src/components/paragraphs/rows/three-column.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import OneColumn from "@components/paragraphs/rows/one-column"
import {ParagraphUnion} from "@lib/gql/__generated__/drupal.d"
import {getParagraphBehaviors} from "@components/paragraphs/get-paragraph-behaviors"
import {isPreviewMode} from "@lib/drupal/is-preview-mode"

const ThreeColumn = ({items}: {items: ParagraphUnion[]}) => {
const leftItems = items.filter(item => getParagraphBehaviors(item).layout_paragraphs?.region === "left")
Expand All @@ -10,13 +9,8 @@ const ThreeColumn = ({items}: {items: ParagraphUnion[]}) => {
)
const rightItems = items.filter(item => getParagraphBehaviors(item).layout_paragraphs?.region === "right")

const draftProps: Record<string, string> = {}
if (isPreviewMode()) {
draftProps["data-columns"] = "3"
}

return (
<div className="gutters grid gap-10 @4xl:grid-cols-2 @6xl:gap-20 @9xl:grid-cols-3" {...draftProps}>
<div className="gutters grid gap-10 @4xl:grid-cols-2 @6xl:gap-20 @9xl:grid-cols-3" data-columns="3">
<OneColumn items={leftItems} />
<OneColumn items={mainItems} />
<OneColumn items={rightItems} />
Expand Down
8 changes: 1 addition & 7 deletions src/components/paragraphs/rows/two-column.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import OneColumn from "@components/paragraphs/rows/one-column"
import {ParagraphUnion} from "@lib/gql/__generated__/drupal.d"
import {getParagraphBehaviors} from "@components/paragraphs/get-paragraph-behaviors"
import {isPreviewMode} from "@lib/drupal/is-preview-mode"
import {twMerge} from "tailwind-merge"

export type TwoColumnConfig = Record<string, string>
Expand All @@ -20,13 +19,8 @@ const TwoColumn = ({items, config}: Props) => {
gridCols = "@6xl/rows:grid-cols-2-1"
}

const draftProps: Record<string, string> = {}
if (isPreviewMode()) {
draftProps["data-columns"] = "2"
}

return (
<div className={twMerge("gutters grid gap-10 @6xl/rows:gap-20", gridCols)} {...draftProps}>
<div className={twMerge("gutters grid gap-10 @6xl/rows:gap-20", gridCols)} data-columns="2">
<OneColumn items={leftItems} />
<OneColumn items={rightItems} />
</div>
Expand Down
6 changes: 3 additions & 3 deletions src/lib/drupal/is-preview-mode.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {cookies, type UnsafeUnwrappedCookies} from "next/headers"
import {cookies} from "next/headers"

/*
* Draft mode works when in normal builds. Use environment variable during development.
*/
export const isPreviewMode = (): boolean => {
export const isPreviewMode = async (): Promise<boolean> => {
return (
process.env.NODE_ENV === "development" ||
(cookies() as unknown as UnsafeUnwrappedCookies)?.get("preview")?.value === process.env.DRUPAL_PREVIEW_SECRET
(await cookies())?.get("preview")?.value === process.env.DRUPAL_PREVIEW_SECRET
)
}
Loading

0 comments on commit 2143f04

Please sign in to comment.