Skip to content

Commit

Permalink
Adjust conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
pookmish committed Dec 8, 2023
1 parent 0b9d5f6 commit c6b3dda
Show file tree
Hide file tree
Showing 13 changed files with 15 additions and 12 deletions.
3 changes: 2 additions & 1 deletion app/(public)/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import {DrupalMenuLinkContent} from "next-drupal";
import {GetStaticPathsResult, Metadata} from "next";
import {getNodeMetadata} from "./metadata";
import LibraryHeader from "@/components/node/sul-library/library-header";
import {StanfordNode} from "@/lib/drupal/drupal";
import {StanfordNode, StanfordParagraph} from "@/lib/drupal/drupal";
import InternalHeaderBanner from "@/components/patterns/internal-header-banner";
import {Suspense} from "react";
import SecondaryMenu from "@/components/menu/secondary-menu";
import {getMenu} from "@/lib/drupal/get-menu";
import {DrupalJsonApiParams} from "drupal-jsonapi-params";
import {isDraftMode} from "@/lib/drupal/is-draft-mode";
import UnpublishedBanner from "@/components/patterns/unpublished-banner";
import fetchComponents from "@/lib/fetch-components";

type Params = {
slug: string | string[]
Expand Down
2 changes: 1 addition & 1 deletion app/api/revalidate/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ export const GET = async (request: NextRequest) => {
return NextResponse.json({message: 'Missing slug'}, {status: 400});
}
revalidatePath(slug)
return NextResponse.json({revalidated: true});
return NextResponse.json({revalidated: true, path: slug});
}
2 changes: 2 additions & 0 deletions app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export const metadata = {
}
}

export const revalidate = 86400;

const RootLayout = ({children, modal}: { children: ReactNode, modal: ReactNode }) => {
const draftMode = isDraftMode();
return (
Expand Down
2 changes: 1 addition & 1 deletion src/components/node/stanford-event-series/page-display.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import fetchComponents from "@/lib/fetch-components";

const StanfordEventSeries = async ({node, ...props}: { node: EventSeries }) => {
node.su_event_series_components = await fetchComponents<StanfordParagraph>(node.su_event_series_components ?? []);
node.su_event_series_components = node.su_event_series_components.filter(item => item?.id?.length > 0);
node.su_event_series_components = node.su_event_series_components.filter(item => !!item?.id);
return (
<article {...props}>
<Conditional showWhen={node.su_event_series_subheadline}>
Expand Down
2 changes: 1 addition & 1 deletion src/components/node/stanford-event/page-display.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const StanfordEvent = async ({node, ...props}: { node: Event }) => {
if (node.su_event_source?.url) redirect(node.su_event_source.url)

node.su_event_components = await fetchComponents<StanfordParagraph>(node.su_event_components ?? []);
node.su_event_components = node.su_event_components.filter(item => item?.id?.length > 0);
node.su_event_components = node.su_event_components.filter(item => !!item?.id);

const inPast = new Date(node.su_event_date_time?.end_value) < new Date();
const start = new Date(node.su_event_date_time?.value);
Expand Down
2 changes: 1 addition & 1 deletion src/components/node/stanford-news/list-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const StanfordNewsListItem = ({node, h3Heading, ...props}: PropsWithoutRef<Props
const imageUrl = node.su_news_featured_media?.field_media_image?.image_style_uri?.breakpoint_2xl_1x || node.su_news_banner?.field_media_image?.image_style_uri?.breakpoint_2xl_1x
const placeholder = node.su_news_featured_media?.field_media_image?.uri.base64 || node.su_news_banner?.field_media_image?.uri.base64;

const topics = node.su_news_topics?.filter(topic => topic.name?.length > 0) ?? [];
const topics = node.su_news_topics?.filter(topic => !!topic.name) ?? [];
return (
<article {...props}>
<div className="text-18 mb-14">
Expand Down
2 changes: 1 addition & 1 deletion src/components/node/stanford-news/page-display.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {redirect} from "next/navigation";

const StanfordNews = async ({node, ...props}: { node: News }) => {
node.su_news_components = await fetchComponents<StanfordParagraph>(node.su_news_components ?? [])
node.su_news_components = node.su_news_components.filter(item => item?.id?.length > 0);
node.su_news_components = node.su_news_components.filter(item => !item?.id);

// Redirect the user to the external source.
if (node.su_news_source?.url && node.su_news_source?.url?.length > 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/node/stanford-page/page-display.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {isDraftMode} from "@/lib/drupal/is-draft-mode";
const StanfordPage = async ({node}: { node: BasicPage }) => {
const draftMode = isDraftMode();
node.su_page_components = await fetchComponents<StanfordParagraph>(node.su_page_components ?? [], {draftMode});
node.su_page_components = node.su_page_components.filter(item => item?.id?.length > 0);
node.su_page_components = node.su_page_components.filter(item => !!item?.id);

const fullWidth = node.layout_selection?.resourceIdObjMeta?.drupal_internal__target_id === 'stanford_basic_page_full';
return (
Expand Down
2 changes: 1 addition & 1 deletion src/components/node/stanford-person/page-display.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import EmailLink from "@/components/patterns/elements/email-link";

const StanfordPerson = async ({node, ...props}: { node: Person }) => {
node.su_person_components = await fetchComponents<StanfordParagraph>(node.su_person_components ?? []);
node.su_person_components = node.su_person_components.filter(item => item?.id?.length > 0);
node.su_person_components = node.su_person_components.filter(item => !!item?.id);
node.lib_guides = node.sul_person__libguide_id ? await fetchLibGuides({accountId: node.sul_person__libguide_id}) : [];

const imageUrl = node.su_person_photo?.field_media_image?.image_style_uri?.medium_square;
Expand Down
2 changes: 1 addition & 1 deletion src/components/node/stanford-publication/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Conditional from "@/components/utils/conditional";
import Link from "@/components/patterns/elements/drupal-link";

const StanfordPublicationCard = ({node, ...props}: { node: Publication }) => {
const topics = node.su_publication_topics?.filter(topic => topic.name?.length > 0) ?? [];
const topics = node.su_publication_topics?.filter(topic => !!topic.name) ?? [];
return (
<article {...props}>
<Card
Expand Down
2 changes: 1 addition & 1 deletion src/components/node/stanford-publication/page-display.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import fetchComponents from "@/lib/fetch-components";
const StanfordPublication = async ({node, ...props}: { node: Publication }) => {

node.su_publication_components = await fetchComponents<StanfordParagraph>(node.su_publication_components ?? []);
node.su_publication_components = node.su_publication_components.filter(item => item?.id?.length > 0);
node.su_publication_components = node.su_publication_components.filter(item => !!item?.id);

const getMonthName = (monthNumber: number) => {
const date = new Date();
Expand Down
2 changes: 1 addition & 1 deletion src/components/node/sul-library/page-display.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import formatHtml from "@/lib/format-html";

const SulLibrary = async ({node, ...props}: { node: Library }) => {
node.su_library__paragraphs = await fetchComponents<StanfordParagraph>(node.su_library__paragraphs ?? []);
node.su_library__paragraphs = node.su_library__paragraphs.filter(item => item?.id?.length > 0);
node.su_library__paragraphs = node.su_library__paragraphs.filter(item => !!item?.id);
const fullWidth = node.layout_selection?.resourceIdObjMeta?.drupal_internal__target_id === 'sul_library_full_width'

return (
Expand Down
2 changes: 1 addition & 1 deletion src/components/paragraph/stanford-entity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface EntityProps extends PropsWithoutRef<any> {

const StanfordEntity = async ({headerId, headline, description, link, styles, entities = [], fullWidth = true, ...props}: EntityProps) => {
const items = await fetchComponents<StanfordNode>(entities ?? []);
const entityItems = items.filter(item => item)
const entityItems = items.filter(item => !!item.id)

const wrapperClasses = styles?.background === 'black' ? 'text-white py-40' : '';

Expand Down

0 comments on commit c6b3dda

Please sign in to comment.