Skip to content

Commit

Permalink
Workaround for sub sections with no images
Browse files Browse the repository at this point in the history
  • Loading branch information
leomet07 committed Nov 3, 2023
1 parent a3e722c commit f8235a5
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions pages/department/[department]/[sub_section].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { NextPageContext } from "next";
import styles from "../../../styles/[department].module.css";
import MixedArticleDisplay from "../../../components/MixedArticleDisplay";
import { generateMetaTags } from "../../../utils/generateMetaTags";
import ListArticleDisplay from "../../../components/ListArticleDisplay";

interface Props {
articles: ReceivedArticle[];
Expand All @@ -19,12 +20,14 @@ interface Props {
}

function SubSection(props: Props) {
const sub_section_display =
let sub_section_display =
props.sub_section.charAt(0).toUpperCase() + props.sub_section.slice(1);
sub_section_display = sub_section_display.split("-").join(" ");

const page_title = sub_section_display + " - The Stuyvesant Spectator";
const meta_url = `https://stuyspec.com/department/${DepartmentsArray[props.department_id]
}/${props.sub_section}`;
const meta_url = `https://stuyspec.com/department/${
DepartmentsArray[props.department_id]
}/${props.sub_section}`;
const meta_description = `${sub_section_display} at The Stuyvesant Spectator.`;

const fetch_addtional_articles = async (skip?: number, max?: number) => {
Expand All @@ -44,6 +47,9 @@ function SubSection(props: Props) {
return articles;
};

// Temporary workaround for when no images and mixedArticleDisplay craashes
const useList = props.articles.every((v) => !v.cover_image);

return (
<div>
<Head>
Expand All @@ -54,15 +60,19 @@ function SubSection(props: Props) {
<h1 id={styles.departmentTitle}>
<span id={styles.sub_section}>{sub_section_display}</span>
</h1>
<MixedArticleDisplay
articles={props.articles}
display_department={true}
additional_article_function={fetch_addtional_articles}
/>
{useList ? (
<ListArticleDisplay articles={props.articles} />
) : (
<MixedArticleDisplay
articles={props.articles}
display_department={true}
additional_article_function={fetch_addtional_articles}
/>
)}
</main>
</div>
);
};
}

export default SubSection;

Expand Down

0 comments on commit f8235a5

Please sign in to comment.