Skip to content

Commit

Permalink
Fixed main menu 3rd+ levels
Browse files Browse the repository at this point in the history
  • Loading branch information
pookmish committed Nov 27, 2023
1 parent 3443299 commit 7b5d4a3
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 49 deletions.
2 changes: 1 addition & 1 deletion app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const revalidate = 86400;
const Home = async () => {
const draftMode = isDraftMode()
const node = await getResourceByPath<BasicPageNodeType>('/', {draftMode});
if(!node) notFound();
if (!node) notFound();

return (
<>
Expand Down
2 changes: 1 addition & 1 deletion src/components/elements/headers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const headingLinkClasses = "[&_a]:text-digital-red [&_a]:hocus:text-black [&_a]:

export const H1 = ({children, ...props}: PropsWithChildren<Props>) => {
return (
<h1 {...props}>
<h1 className={twMerge(props.className, "text-m4")} {...props}>
{children}
</h1>
)
Expand Down
4 changes: 2 additions & 2 deletions src/components/menu/main-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const MenuItem = ({id, url, title, activeTrail, items, level = 0}: MenuItemProps
const [submenuOpen, setSubmenuOpen] = useState<boolean>(false)
const browserUrl = useNavigationEvent()
useEffect(() => setSubmenuOpen(false), [browserUrl]);
const itemProps = useOutsideClick(() => setSubmenuOpen(false));

const handleEscape = useCallback((event: KeyboardEvent) => {
if (event.key === "Escape" && submenuOpen) {
Expand Down Expand Up @@ -131,7 +132,6 @@ const MenuItem = ({id, url, title, activeTrail, items, level = 0}: MenuItemProps
];

const itemStyles: string = level === 0 ? topItem.join(' ') : childItem.join(' ');
const itemProps = useOutsideClick(() => setSubmenuOpen(false));

return (
<li
Expand Down Expand Up @@ -170,7 +170,7 @@ const MenuItem = ({id, url, title, activeTrail, items, level = 0}: MenuItemProps

{items &&
<ul
className={(submenuOpen ? "block" : "hidden") + " list-unstyled w-full min-w-[300px] lg:bg-white lg:shadow-2xl px-0 " + (level === 0 ? "lg:absolute lg:top-full lg:left-0 " : "") + zIndexes[level]}>
className={(submenuOpen ? "block" : "hidden") + " list-unstyled w-full min-w-[300px] lg:bg-white lg:shadow-2xl px-0 lg:absolute " + (level === 0 ? "lg:top-full lg:left-0 " : "lg:top-0 lg:left-full ") + zIndexes[level]}>
{items.map(item =>
<MenuItem
key={item.id}
Expand Down
36 changes: 26 additions & 10 deletions src/components/nodes/pages/stanford-policy/stanford-policy-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import StringWithLines from "@components/elements/string-with-lines";
import {JSX, PropsWithoutRef} from "react";
import {H1, H2, H3} from "@components/elements/headers";

const StanfordPolicyPage = async ({node, ...props}: PropsWithoutRef<{ node: PolicyNodeType }>): Promise<JSX.Element> => {
const relatedPolicies: PolicyNodeType[] = await getResources(node.su_policy_related ?? [])
const StanfordPolicyPage = async ({node, ...props}: PropsWithoutRef<{
node: PolicyNodeType
}>): Promise<JSX.Element> => {
const relatedPolicies = (await getResources<PolicyNodeType>(node.su_policy_related ?? [])).filter(related => related.id !== node.id)
const changeLog = node.su_policy_changelog?.filter(change => change.su_policy_public) ?? []

return (
Expand All @@ -19,7 +21,11 @@ const StanfordPolicyPage = async ({node, ...props}: PropsWithoutRef<{ node: Poli
{node.su_policy_effective &&
<div>
<strong>Effective Date: </strong>
{new Date(node.su_policy_effective).toLocaleDateString('en-us', {month: "long", day: "numeric", year: "numeric"})}
{new Date(node.su_policy_effective).toLocaleDateString('en-us', {
month: "long",
day: "numeric",
year: "numeric"
})}
</div>
}

Expand All @@ -32,19 +38,27 @@ const StanfordPolicyPage = async ({node, ...props}: PropsWithoutRef<{ node: Poli
{node.su_policy_updated &&
<div>
<strong>Last Updated: </strong>
{new Date(node.su_policy_updated).toLocaleDateString('en-us', {month: "long", day: "numeric", year: "numeric"})}
{new Date(node.su_policy_updated).toLocaleDateString('en-us', {
month: "long",
day: "numeric",
year: "numeric"
})}
</div>
}

{changeLog &&
{changeLog.length > 0 &&

<div className="bg-black-10 p-20 border border-black-40 mb-10">
<H2 className="text-m1">Change log:</H2>

{changeLog.map((change: PolicyChangeLogType) =>
<div key={change.id}>
<H3 className="flex gap-2 text-m0">
<div>{new Date(change.su_policy_date).toLocaleDateString('en-us', {month: "long", day: "numeric", year: "numeric"})}</div>
<div>{new Date(change.su_policy_date).toLocaleDateString('en-us', {
month: "long",
day: "numeric",
year: "numeric"
})}</div>
<div className="w-[2px] bg-black shrink-0"/>
<div>{change.su_policy_title}</div>
</H3>
Expand All @@ -63,14 +77,16 @@ const StanfordPolicyPage = async ({node, ...props}: PropsWithoutRef<{ node: Poli
}


{(relatedPolicies.length > 0) &&
{relatedPolicies.length > 0 &&
<div>
<H2 className="text-centered">Related Policies</H2>
<div className="flex flex-col lg:flex-row flex-wrap">
<ul className="list-unstyled grid lg:grid-cols-3">
{relatedPolicies.map((policy: PolicyNodeType) =>
<StanfordPolicyCard node={policy} key={policy.id}/>
<li key={policy.id}>
<StanfordPolicyCard node={policy}/>
</li>
)}
</div>
</ul>
</div>
}
</div>
Expand Down
45 changes: 22 additions & 23 deletions src/lib/drupal/get-resource.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@


import {AccessToken, JsonApiResource, JsonApiWithLocaleOptions} from "next-drupal";
import {AccessToken, JsonApiResource, JsonApiOptions} from "next-drupal";
import {stringify} from "qs"
import {buildUrl, buildHeaders, getJsonApiPathForResourceType, getPathFromContext} from "./utils";
import {deserialize} from "@lib/drupal/deserialize";
import {JsonApiParams} from "next-drupal";
import {PageProps, StanfordConfigPage} from "@lib/types";

export async function getResources<T>(items: { type: string, id: string }[], draftMode: boolean = false): Promise<T[]> {
export const getResources = async <T extends JsonApiResource, >(
items: { type: string, id: string }[],
draftMode: boolean = false
): Promise<T[]> => {
const requests: PromiseLike<any>[] = [];
items.map(item => requests.push(getResource(item.type, item.id, {draftMode})));
items.filter(({type, id}) => `${type}-${id}` !== 'unknown-missing')
.map(item => requests.push(getResource<T>(item.type, item.id, {draftMode})));

// @ts-ignore
return Promise.all(requests.map((p, i) => p.catch((e) => {
if (`${items[i].type}-${items[i].id}` !== 'unknown-missing') {
console.error(`Failed Fetching (probably unpublished) component ${items[i].type}-${items[i].id}`, e);
}
console.error(`Failed Fetching (probably unpublished) component ${items[i].type}-${items[i].id}`, e);
return null
})));
}

export async function getResourceFromContext<T extends JsonApiResource>(
export const getResourceFromContext = async <T extends JsonApiResource, >(
type: string,
context: PageProps,
options?: {
Expand All @@ -31,7 +31,7 @@ export async function getResourceFromContext<T extends JsonApiResource>(
isVersionable?: boolean
draftMode?: boolean
}
): Promise<T | undefined> {
): Promise<T | undefined> => {
options = {
deserialize: true,
draftMode: false,
Expand All @@ -55,15 +55,15 @@ export async function getResourceFromContext<T extends JsonApiResource>(
return resource
}

export async function getResourceByPath<T extends JsonApiResource>(
export const getResourceByPath = async <T extends JsonApiResource, >(
path: string,
options?: {
accessToken?: AccessToken
deserialize?: boolean
isVersionable?: boolean
draftMode?: boolean
} & JsonApiWithLocaleOptions,
): Promise<T | undefined> {
} & JsonApiOptions,
): Promise<T | undefined> => {
options = {
deserialize: true,
isVersionable: false,
Expand Down Expand Up @@ -119,15 +119,14 @@ export async function getResourceByPath<T extends JsonApiResource>(
return options.deserialize ? deserialize(data) : data
}

export async function getResourceCollection<T = JsonApiResource[]>(
export const getResourceCollection = async <T extends JsonApiResource, >(
type: string,
options?: {
deserialize?: boolean
accessToken?: AccessToken
draftMode?: boolean
} & JsonApiWithLocaleOptions,

): Promise<T> {
} & JsonApiOptions,
): Promise<T> => {
options = {
deserialize: true,
draftMode: false,
Expand Down Expand Up @@ -157,16 +156,15 @@ export async function getResourceCollection<T = JsonApiResource[]>(
return options.deserialize ? deserialize(json) : json
}

export async function getResource<T extends JsonApiResource>(
export const getResource = async <T extends JsonApiResource, >(
type: string,
uuid: string,
options?: {
accessToken?: AccessToken
deserialize?: boolean
draftMode?: boolean
} & JsonApiWithLocaleOptions,

): Promise<T> {
} & JsonApiOptions,
): Promise<T> => {
options = {
deserialize: true,
params: {},
Expand Down Expand Up @@ -196,12 +194,13 @@ export async function getResource<T extends JsonApiResource>(
return options.deserialize ? deserialize(json) : json
}

export async function getConfigPageResource<T extends StanfordConfigPage>(
export const getConfigPageResource = async <T extends StanfordConfigPage>(
name: string,
options?: {
deserialize?: boolean
accessToken?: AccessToken
} & JsonApiWithLocaleOptions): Promise<T | undefined> {
} & JsonApiOptions
): Promise<T | undefined> => {
let response;
try {
response = await getResourceCollection<JsonApiResource>(`config_pages--${name}`, options);
Expand Down
24 changes: 12 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3140,9 +3140,9 @@
form-data "^4.0.0"

"@types/node@*", "@types/node@^20.1.3":
version "20.9.5"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.9.5.tgz#bb441014bcb91c63742b0e1fe25b902f5d581faa"
integrity sha512-Uq2xbNq0chGg+/WQEU0LJTSs/1nKxz6u1iemLcGomkSnKokbW1fbLqc3HOqCf2JP7KjlL4QkS7oZZTrOQHQYgQ==
version "20.10.0"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.10.0.tgz#16ddf9c0a72b832ec4fcce35b8249cf149214617"
integrity sha512-D0WfRmU9TQ8I9PFx9Yc+EBHw+vSpIub4IDvQivcp26PtPrdMGAq5SDcpXEo/epqa/DXotVpekHiLNTg3iaKXBQ==
dependencies:
undici-types "~5.26.4"

Expand Down Expand Up @@ -4291,9 +4291,9 @@ camelcase@^5.3.1:
integrity sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==

caniuse-lite@^1.0.30001406, caniuse-lite@^1.0.30001538, caniuse-lite@^1.0.30001541:
version "1.0.30001564"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001564.tgz#eaa8bbc58c0cbccdcb7b41186df39dd2ba591889"
integrity sha512-DqAOf+rhof+6GVx1y+xzbFPeOumfQnhYzVnZD6LAXijR77yPtm9mfOcqOnT3mpnJiZVT+kwLAFnRlZcIz+c6bg==
version "1.0.30001565"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001565.tgz#a528b253c8a2d95d2b415e11d8b9942acc100c4f"
integrity sha512-xrE//a3O7TP0vaJ8ikzkD2c2NgcVUvsEe2IvFTntV4Yd1Z9FVzh+gW+enX96L0psrbaFMcVcH2l90xNuGDWc8w==

case-sensitive-paths-webpack-plugin@^2.4.0:
version "2.4.0"
Expand Down Expand Up @@ -4380,9 +4380,9 @@ cli-cursor@^3.1.0:
restore-cursor "^3.1.0"

cli-spinners@^2.5.0:
version "2.9.1"
resolved "https://registry.yarnpkg.com/cli-spinners/-/cli-spinners-2.9.1.tgz#9c0b9dad69a6d47cbb4333c14319b060ed395a35"
integrity sha512-jHgecW0pxkonBJdrKsqxgRX9AcG+u/5k0Q7WPDfi8AogLAdwxEkyYYNWwZ5GvVFoFx2uiY1eNcSK00fh+1+FyQ==
version "2.9.2"
resolved "https://registry.yarnpkg.com/cli-spinners/-/cli-spinners-2.9.2.tgz#1773a8f4b9c4d6ac31563df53b3fc1d79462fe41"
integrity sha512-ywqV+5MmyL4E7ybXgKys4DugZbX0FC6LnwrhjuykIjnK9k8OQacQ7axGKnjDXWNhns0xot3bZI5h55H8yo9cJg==

cli-table3@^0.6.1:
version "0.6.3"
Expand Down Expand Up @@ -5137,9 +5137,9 @@ ejs@^3.1.8:
jake "^10.8.5"

electron-to-chromium@^1.4.535:
version "1.4.593"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.593.tgz#f71b157f7382f3d3a164f73ff2da772d4b3fd984"
integrity sha512-c7+Hhj87zWmdpmjDONbvNKNo24tvmD4mjal1+qqTYTrlF0/sNpAcDlU0Ki84ftA/5yj3BF2QhSGEC0Rky6larg==
version "1.4.594"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.594.tgz#f69f207fba80735a44a988df42f3f439115d0515"
integrity sha512-xT1HVAu5xFn7bDfkjGQi9dNpMqGchUkebwf1GL7cZN32NSwwlHRPMSDJ1KN6HkS0bWUtndbSQZqvpQftKG2uFQ==

elliptic@^6.5.3, elliptic@^6.5.4:
version "6.5.4"
Expand Down

1 comment on commit 7b5d4a3

@vercel
Copy link

@vercel vercel bot commented on 7b5d4a3 Nov 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.