Skip to content

Commit

Permalink
DIGG-207: Adding single type to handle multi language StartPage
Browse files Browse the repository at this point in the history
  • Loading branch information
MikaMunterud committed Nov 8, 2024
1 parent 68ab075 commit fb24bc3
Show file tree
Hide file tree
Showing 15 changed files with 1,402 additions and 160 deletions.
12 changes: 8 additions & 4 deletions components/content/GridList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ import { PublicationTeaser } from "@/components/content/Publication/PublicationT
import { ButtonLink } from "@/components/global/Button";
import { Heading } from "@/components/global/Typography/Heading";
import {
GoodExampleDataFragment,
NewsItemDataFragment,
GoodExampleBlockItemFragment,
NewsBlockItemFragment,
ToolDataFragment,
} from "@/graphql/__generated__/operations";
import { Toolteaser } from "../Tool";

interface ListProps {
items: (ToolDataFragment | NewsItemDataFragment | GoodExampleDataFragment)[];
items: (
| ToolDataFragment
| GoodExampleBlockItemFragment
| NewsBlockItemFragment
)[];
heading?: string;
showMoreLink?: {
slug: string;
Expand Down Expand Up @@ -63,7 +67,7 @@ export const GridList: FC<ListProps> = ({
{(() => {
switch (item.__typename) {
case "dataportal_Digg_Tool":
return <Toolteaser tools={item} />;
return <Toolteaser tools={item as ToolDataFragment} />;
default:
return <PublicationTeaser publication={item} />;
}
Expand Down
16 changes: 13 additions & 3 deletions components/content/LandingPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import Link from "next/link";
import dynamic from "next/dynamic";
import {
ContainerDataFragment,
GoodExampleBlockItemFragment,
GoodExampleDataFragment,
NewsBlockItemFragment,
NewsItemDataFragment,
} from "@/graphql/__generated__/operations";
import { GridList } from "@/components/content/GridList";
Expand All @@ -16,7 +18,12 @@ import { Preamble } from "@/components/global/Typography/Preamble";
import { ContentBox } from "@/components/content/ContentBox";
import { dataCategories } from "@/utilities/dataCategories";
import { ButtonLink } from "@/components/global/Button";
import { isExternalLink, linkBase } from "@/utilities";
import {
isExternalLink,
linkBase,
toGoodExamplePreview,
toNewsPreview,
} from "@/utilities";
import ArrowRightIcon from "@/assets/icons/arrowRight.svg";
import ExternalLinkIcon from "@/assets/icons/external-link.svg";
import useTranslation from "next-translate/useTranslation";
Expand Down Expand Up @@ -73,6 +80,9 @@ export const LandingPage: FC<LandingPageProps> = (props) => {
blocks[0];
const content = topPromos ? blocks.slice(1) : blocks;

const newsPreviews = news?.map(toNewsPreview);
const examplePreviews = example?.map(toGoodExamplePreview);

useEffect(() => {
const crumbs = [{ name: "start", link: { ...linkBase, link: "/" } }];
if (parent && parent.heading && parent.slug) {
Expand Down Expand Up @@ -110,7 +120,7 @@ export const LandingPage: FC<LandingPageProps> = (props) => {
{news && (
<GridList
className="!my-xl md:!my-2xl"
items={news}
items={newsPreviews as NewsBlockItemFragment[]}
showMoreLink={{
title: t("pages|news$view-all"),
slug: t("routes|news$path"),
Expand All @@ -121,7 +131,7 @@ export const LandingPage: FC<LandingPageProps> = (props) => {
{example && (
<GridList
className="!my-xl md:!my-2xl"
items={example}
items={examplePreviews as GoodExampleBlockItemFragment[]}
showMoreLink={{
title: t("pages|good-examples$view-all"),
slug: t("routes|good-examples$path"),
Expand Down
14 changes: 9 additions & 5 deletions components/content/ListPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { Pagination } from "@/components/global/Pagination";
import { useRouter, NextRouter } from "next/router";
import { SettingsContext } from "@/providers/SettingsProvider";
import {
GoodExampleDataFragment,
NewsItemDataFragment,
GoodExampleBlockItemFragment,
NewsBlockItemFragment,
ToolDataFragment,
} from "@/graphql/__generated__/operations";
import { Heading } from "@/components/global/Typography/Heading";
Expand All @@ -17,8 +17,8 @@ import { Button } from "@/components/global/Button";
interface ListPageProps {
listItems: (
| ToolDataFragment
| NewsItemDataFragment
| GoodExampleDataFragment
| NewsBlockItemFragment
| GoodExampleBlockItemFragment
)[];
heading: string;
type: string;
Expand All @@ -39,7 +39,11 @@ export const ListPage: FC<ListPageProps> = ({ listItems, heading }) => {
const endIndex = startIndex + listItemsPerPage;
const [filterList, setFilterList] =
useState<
(ToolDataFragment | NewsItemDataFragment | GoodExampleDataFragment)[]
(
| ToolDataFragment
| NewsBlockItemFragment
| GoodExampleBlockItemFragment
)[]
>(listItems);
const [keywordList, setKeywordList] = useState<Keyword[]>([]);
const [activeFilter, setActiveFilter] = useState<Keyword>({
Expand Down
11 changes: 5 additions & 6 deletions components/content/Publication/PublicationTeaser/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,25 @@ import { FC, useEffect, useState } from "react";
import { CustomImage } from "@/components/global/CustomImage";
import ArrowIcon from "@/assets/icons/arrowRight.svg";
import {
GoodExampleDataFragment,
NewsItemDataFragment,
GoodExampleBlockItemFragment,
NewsBlockItemFragment,
} from "@/graphql/__generated__/operations";
import { Heading } from "@/components/global/Typography/Heading";
import Link from "next/link";
import { formatDate } from "@/utilities/dateHelper";

interface PublicationTeaserProps {
publication: GoodExampleDataFragment | NewsItemDataFragment;
publication: GoodExampleBlockItemFragment | NewsBlockItemFragment;
}

export const PublicationTeaser: FC<PublicationTeaserProps> = ({
publication,
}) => {
const { publishedAt, heading, slug, image, __typename } = publication;
const { heading, publishedAt, slug, image, __typename } = publication;
const { lang } = useTranslation();
const [date, setDate] = useState("");

const type =
__typename === "dataportal_Digg_News_Item"
__typename === "dataportal_Digg_NewsItem_Preview"
? { url: `/nyheter${slug}`, name: "Nyhet" }
: { url: `/goda-exempel${slug}`, name: "Goda Exempel" };

Expand Down
146 changes: 146 additions & 0 deletions components/content/StartPage/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import { usePathname } from "next/navigation";
import { FC } from "react";
import Link from "next/link";
import dynamic from "next/dynamic";
import { StartPageDataFragment } from "@/graphql/__generated__/operations";
import { BlockList } from "@/components/content/blocks/BlockList";
import { Heading } from "@/components/global/Typography/Heading";
import { Container } from "@/components/layout/Container";
import { Preamble } from "@/components/global/Typography/Preamble";
import { ContentBox } from "@/components/content/ContentBox";
import { dataCategories } from "@/utilities/dataCategories";
import { ButtonLink } from "@/components/global/Button";
import { isExternalLink } from "@/utilities";
import ArrowRightIcon from "@/assets/icons/arrowRight.svg";
import ExternalLinkIcon from "@/assets/icons/external-link.svg";
import useTranslation from "next-translate/useTranslation";

export interface StartPageProps extends StartPageDataFragment {}

const DynamicStatisticGraph = dynamic(
() => import("@/components/content/Statistic/StatisticGraph"),
{
ssr: false,
},
);

const DynamicStatisticNumbers = dynamic(
() => import("@/components/content/Statistic/StatisticNumbers"),
{
ssr: false,
},
);

const DynamicStatistic = dynamic(
() => import("@/components/content/Statistic"),
{
ssr: false,
},
);

const contentBoxLinks = [
{ label: "Bidra till Sveriges dataportal", href: "/om-oss" },
{ label: "Hitta datasamverkan", href: "/datasamverkan" },
{
label: "Delta i communityt",
href: "https://community.dataportal.se/",
},
];

export const StartPage: FC<StartPageProps> = (props) => {
const { heading, preamble, image, blocks } = props;
const pathname = usePathname();
const { t, lang } = useTranslation();

return (
<Container>
<div id="startPage" className="space-y-md lg:space-y-xl">
{!image && heading && (
<Heading level={1} size="lg" className="mb-lg md:mb-xl">
{heading}
</Heading>
)}

{pathname === `/${t("routes|search-api$path")}` ||
(!image && preamble) ? (
<Preamble className="max-w-md">{preamble}</Preamble>
) : null}

<div className={"mb-xl"}>
{blocks && <BlockList blocks={blocks} landingPage={true} />}
</div>

{lang === "sv" && (
<>
<ContentBox
heading="Var med och delta"
description="På Sveriges dataportal kan du som delar eller använder data, eller på andra sätt vill att data ska bli en strategisk resurs för bred samhällsnytta, delta på olika sätt. Här kan du ha dialoger med andra, bidra med innehåll eller kanske hitta en framtida samverkanspart."
>
<div className="flex flex-wrap justify-center gap-md lg:gap-xl">
{contentBoxLinks.map((link, idx: number) => (
<ButtonLink
key={idx}
href={link.href}
label={link.label}
icon={
isExternalLink(link.href)
? ExternalLinkIcon
: ArrowRightIcon
}
iconPosition="right"
/>
))}
</div>
</ContentBox>
</>
)}

<ContentBox heading={t("pages|startpage$datasets_by_category")}>
<ul className="flex flex-wrap justify-center gap-md lg:gap-lg">
{dataCategories?.map((category, idx: number) => (
<li key={idx}>
<ButtonLink
className="text-center"
aria-label={t("pages|startpage$search_datasets_format", {
category: t(`resources|${category.href}`),
})}
href={`/${t("routes|datasets$path")}?f=${encodeURIComponent(
`http://www.w3.org/ns/dcat#theme||${
category.href
}||FALSE||uri||${t(
"resources|http://www.w3.org/ns/dcat#theme",
)}||${t("resources|" + category.href)}`,
)}`}
label={t(`resources|${category.href}`)}
/>
</li>
))}
</ul>
</ContentBox>

<section id="statistics" className="my-xl">
<div className="mb-2xl flex flex-col justify-between gap-sm md:flex-row md:items-end">
<Heading level={2} size={"lg"}>
{t("pages|statistic$statistic-numbers")}
</Heading>
<Link
href={`/${t("routes|statistics$path")}`}
locale={lang}
className="statistic-link"
>
{t("pages|statistic$statistic-link")}
</Link>
</div>

<div className="mb-2xl flex flex-wrap justify-between">
<DynamicStatisticGraph />
<DynamicStatisticNumbers />
</div>
<div className="flex flex-col items-start gap-xl md:grid md:grid-cols-2">
<DynamicStatistic />
</div>
</section>
</div>
</Container>
);
};
Loading

0 comments on commit fb24bc3

Please sign in to comment.