diff --git a/components/InTheNews/InTheNews.tsx b/components/InTheNews/InTheNews.tsx
index fc6f91b82..6fd4c04fe 100644
--- a/components/InTheNews/InTheNews.tsx
+++ b/components/InTheNews/InTheNews.tsx
@@ -1,4 +1,4 @@
-import { useState } from "react"
+import { useState, Fragment } from "react"
import { Col, Row, Container, Badge, Spinner } from "../bootstrap"
import Tab from "react-bootstrap/Tab"
import Nav from "react-bootstrap/Nav"
@@ -9,10 +9,11 @@ import { NewsCard } from "./NewsCard"
import { NewsType, NewsItem, useNews } from "components/db/news"
type NewsFeedProps = {
- type: NewsType
+ type: NewsType | null
newsItems: NewsItem[]
}
+const newsTypePlurals: (keyof TabCounts)[] = ["media", "awards", "books"]
type TabCounts = {
media: number
awards: number
@@ -23,7 +24,7 @@ const NewsFeed = ({ type, newsItems }: NewsFeedProps) => {
return (
{newsItems
- .filter(item => item.type === type)
+ .filter(item => item.type === type || type === null)
.map((item, index) => (
))}
@@ -50,21 +51,25 @@ export const InTheNews = () => {
{t("title")}
-
- {isMobile ? (
-
- ) : (
-
- )}
-
-
- {loading ? (
-
-
- Loading...
-
-
- ) : (
+ {loading ? (
+
+
+ Loading...
+
+
+ ) : newsItems &&
+ counts &&
+ newsItems.length > 10 &&
+ [counts.media, counts.awards, counts.books].filter(Boolean).length >
+ 1 ? (
+
+ {isMobile ? (
+
+ ) : (
+
+ )}
+
+
@@ -82,89 +87,58 @@ export const InTheNews = () => {
- )}
+
+
+
+ ) : (
+
+
+
+
+
-
+ )}
)
}
-const TabGroup = ({ counts }: { counts: TabCounts | null }) => {
+const TabGroup = ({ counts }: { counts: TabCounts }) => {
const { t } = useTranslation("inTheNews")
return (
-
-
-
-
-
-
-
-
-
+ {newsTypePlurals
+ .filter(val => counts[val])
+ .map(val => (
+
+
+
+ ))}
)
}
-const TabDropdown = ({ counts }: { counts: TabCounts | null }) => {
+const TabDropdown = ({ counts }: { counts: TabCounts }) => {
const { t } = useTranslation("inTheNews")
- const [selectedTab, setSelectedTab] = useState
("Media")
+ const [selectedTab, setSelectedTab] = useState(t("media.title"))
const handleTabClick = (tabTitle: string) => {
setSelectedTab(tabTitle)
@@ -178,29 +152,20 @@ const TabDropdown = ({ counts }: { counts: TabCounts | null }) => {
{selectedTab}
- handleTabClick("Media")}
- >
- {t("media.title")}
-
-
- handleTabClick("Awards")}
- >
- {t("awards.title")}
-
-
- handleTabClick("Books")}
- >
- {t("books.title")}
-
+ {newsTypePlurals
+ .filter(val => counts[val])
+ .map((val, i) => (
+
+ {i !== 0 && }
+ handleTabClick(t(`${val}.title`))}
+ >
+ {t(`${val}.title`)}
+
+
+ ))}