Skip to content

Commit

Permalink
Adjusted interception route for temporary work around of catch all ro…
Browse files Browse the repository at this point in the history
…utes
  • Loading branch information
pookmish committed Dec 9, 2024
1 parent 8ebb3b3 commit 7d1d6c0
Show file tree
Hide file tree
Showing 7 changed files with 247 additions and 267 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export const dynamic = "force-static"
export const maxDuration = 60

type Props = {
params: Promise<{uuid: string[]}>
params: Promise<{uuid: string}>
}

const Page = async (props: Props) => {
const params = await props.params
const [paragraphId, mediaUuid] = params.uuid
const [paragraphId, mediaUuid] = decodeURIComponent(params.uuid).split(":")

const paragraphQuery = await graphqlClient().Paragraph({uuid: paragraphId})
if (paragraphQuery.paragraph?.__typename !== "ParagraphStanfordGallery") notFound()
Expand Down Expand Up @@ -64,7 +64,7 @@ const Page = async (props: Props) => {
<li className="mr-auto">
<Link
className="text-white no-underline hocus:text-white hocus:underline"
href={`/gallery/${paragraph.id}/${paragraph.suGalleryImages?.[prevImageIndex].id}`}
href={`/gallery/${paragraph.id}:${paragraph.suGalleryImages?.[prevImageIndex].id}`}
replace={true}
scroll={false}
>
Expand All @@ -76,7 +76,7 @@ const Page = async (props: Props) => {
<li className="ml-auto">
<Link
className="text-white no-underline hocus:text-white hocus:underline"
href={`/gallery/${paragraph.id}/${paragraph.suGalleryImages?.[nextImageIndex].id}`}
href={`/gallery/${paragraph.id}:${paragraph.suGalleryImages?.[nextImageIndex].id}`}
replace={true}
scroll={false}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ export const metadata = {
}

type Props = {
params: Promise<{uuid: string[]}>
params: Promise<{uuid: string}>
}

const Page = async (props: Props) => {
const params = await props.params
const [paragraphId, mediaUuid] = params.uuid
const [paragraphId, mediaUuid] = decodeURIComponent(params.uuid).split(":")

const paragraphQuery = await graphqlClient().Paragraph({uuid: paragraphId})
if (paragraphQuery.paragraph?.__typename !== "ParagraphStanfordGallery") notFound()
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@types/node": "22.10.1",
"@types/react": "19.0.1",
"@types/react-dom": "19.0.1",
"algoliasearch": "^5.15.0",
"algoliasearch": "^5.16.0",
"autoprefixer": "^10.4.20",
"clsx": "^2.1.1",
"decanter": "^7.3.0",
Expand All @@ -38,8 +38,8 @@
"react": "19.0.0",
"react-dom": "19.0.0",
"react-focus-lock": "^2.13.2",
"react-instantsearch": "^7.13.8",
"react-instantsearch-nextjs": "^0.3.18",
"react-instantsearch": "^7.13.9",
"react-instantsearch-nextjs": "^0.3.19",
"react-slick": "^0.30.2",
"react-super-responsive-table": "^6.0.0",
"react-tiny-oembed": "^1.1.0",
Expand Down Expand Up @@ -80,7 +80,7 @@
"storybook": "^8.4.7",
"storybook-addon-module-mock": "^1.3.4",
"tsconfig-paths-webpack-plugin": "^4.2.0",
"typescript-eslint": "^8.17.0"
"typescript-eslint": "^8.18.0"
},
"packageManager": "yarn@4.5.3",
"resolutions": {
Expand Down
3 changes: 1 addition & 2 deletions src/components/elements/accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,10 @@ const Accordion = ({

return (
<section aria-labelledby={`${id}-button`} {...props}>
<Heading>
<Heading id={`${id}-button`}>
<button
{...buttonProps}
className={twMerge("flex w-full items-center text-left hocus-visible:underline", buttonProps?.className)}
id={`${id}-button`}
aria-expanded={isExpanded}
aria-controls={`${id}-panel`}
onClick={onButtonClick}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const GalleryImage = ({
<figure>
<div className="relative aspect-[4/3] w-full">
<Link
href={`/gallery/${galleryId}/${image.id}`}
href={`/gallery/${galleryId}:${image.id}`}
className="relative block h-full w-full"
rel="nofollow"
scroll={false}
Expand Down
72 changes: 32 additions & 40 deletions src/lib/gql/gql-queries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,47 +60,39 @@ export const getEntityFromPath = async <T extends NodeUnion>(
return getData()
}

export const getConfigPage = async <T extends ConfigPagesUnion>(
configPageType: ConfigPagesUnion["__typename"]
): Promise<T | undefined> => {
const getData = nextCache(
async () => {
let query: ConfigPagesQuery
try {
query = await graphqlClient().ConfigPages()
} catch (e) {
console.warn("Unable to fetch config pages: " + (e instanceof Error && e.stack))
return
}
export const getConfigPage = nextCache(
async <T extends ConfigPagesUnion>(configPageType: ConfigPagesUnion["__typename"]): Promise<T | undefined> => {
let query: ConfigPagesQuery
try {
query = await graphqlClient().ConfigPages()
} catch (e) {
console.warn("Unable to fetch config pages: " + (e instanceof Error && e.stack))
return
}

const queryKeys = Object.keys(query) as (keyof ConfigPagesQuery)[]
for (let i = 0; i < queryKeys.length; i++) {
const queryKey = queryKeys[i]
if (queryKey !== "__typename" && query[queryKey]?.nodes[0]?.__typename === configPageType) {
return query[queryKey].nodes[0] as T
}
const queryKeys = Object.keys(query) as (keyof ConfigPagesQuery)[]
for (let i = 0; i < queryKeys.length; i++) {
const queryKey = queryKeys[i]
if (queryKey !== "__typename" && query[queryKey]?.nodes[0]?.__typename === configPageType) {
return query[queryKey].nodes[0] as T
}
},
[configPageType || "config-pages"],
{tags: ["config-pages"]}
)
return getData()
}
}
},
[],
{tags: ["config-pages"]}
)

export const getConfigPageField = async <T extends ConfigPagesUnion, F>(
configPageType: ConfigPagesUnion["__typename"],
fieldName: keyof T
): Promise<F | undefined> => {
const getData = nextCache(
async () => {
const configPage = await getConfigPage<T>(configPageType)
return configPage?.[fieldName] as F
},
[fieldName.toString()],
{tags: ["config-pages"]}
)
return getData()
}
export const getConfigPageField = nextCache(
async <T extends ConfigPagesUnion, F>(
configPageType: ConfigPagesUnion["__typename"],
fieldName: keyof T
): Promise<F | undefined> => {
const configPage = await getConfigPage<T>(configPageType)
return configPage?.[fieldName] as F
},
[],
{tags: ["config-pages"]}
)

export const getMenu = async (name?: MenuAvailable, maxLevels?: number): Promise<MenuItem[]> => {
const menuName = name?.toLowerCase() || "main"
Expand Down Expand Up @@ -151,7 +143,7 @@ export const getAllNodes = nextCache(
return nodes
},
["all-nodes"],
{revalidate: 25200, tags: ["all-entities"]}
{revalidate: 604800, tags: ["all-entities"]}
)

/**
Expand Down Expand Up @@ -185,5 +177,5 @@ export const getAlgoliaCredential = nextCache(
return appId && indexName && apiKey ? [appId, indexName, apiKey] : []
},
["algolia"],
{tags: ["algolia"]}
{tags: ["algolia", "config-pages"]}
)
Loading

0 comments on commit 7d1d6c0

Please sign in to comment.