Skip to content

Commit

Permalink
Merge pull request #738 from CodeForAfrica/feature/finish-footer
Browse files Browse the repository at this point in the history
@/roboshield Current footer to Payload
  • Loading branch information
koechkevin authored Jun 26, 2024
2 parents 4d6ca35 + 9f91667 commit 0c793d3
Show file tree
Hide file tree
Showing 10 changed files with 484 additions and 801 deletions.
2 changes: 2 additions & 0 deletions apps/roboshield/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"react-dom": "^18.3.1",
"react-rotating-text": "^1.4.1",
"robots-txt-parse": "^2.0.1",
"slate": "^0.103.0",
"sqlite": "^5.1.1",
"sqlite3": "^5.1.7",
"tsc-alias": "^1.8.10",
Expand All @@ -68,6 +69,7 @@
"jest": "^29.7.0",
"jest-config-commons-ui": "workspace:*",
"prettier": "3.1.1",
"ts-node": "^10.9.2",
"typescript": "^5.4.5"
}
}
59 changes: 38 additions & 21 deletions apps/roboshield/src/components/Footer/Footer.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Section } from "@commons-ui/core";
import { Figure, Link, RichTypography } from "@commons-ui/next";
import { Box, Grid, Stack } from "@mui/material";
import { styled } from "@mui/material/styles";
import { Theme, styled } from "@mui/material/styles";

import NewsletterSubscription from "@/roboshield/components/NewsletterSubscription";
import StayInTouch from "@/roboshield/components/StayInTouch";
import RichText from "@/roboshield/components/RichText";
import FooterDescription from "./FooterDescription";
import { Partner } from "@/roboshield/lib/data/payload.types";

export interface FooterProps {
connect: {
Expand All @@ -20,8 +22,11 @@ export interface FooterProps {
sx: any;
title: string;
};
partners: any[];
project: string;
initiative: {
partners: Partner[];
title: string;
description: string;
};
}

const FooterRoot = styled(Box)(
Expand All @@ -42,9 +47,8 @@ export default function Footer({
connect,
description,
logo,
partners,
project,
newsletter,
initiative,
}: FooterProps) {
return (
<FooterRoot component="footer">
Expand Down Expand Up @@ -91,17 +95,21 @@ export default function Footer({
variant="h5SemiBold"
sx={{ color: "text.secondary", mb: "0" }}
>
In Partnership with:
{initiative?.title}
</RichTypography>
<RichText />
<Stack alignItems="center" direction="row" spacing={0.5}>
{partners.map((partner: any) => (
{initiative?.partners?.map((partner: any) => (
<Link
key={partner.name}
href={partner.url}
target="_blank"
>
<Figure
ImageProps={partner.logo}
ImageProps={{
src: partner?.logo?.src,
alt: partner?.logo?.alt,
}}
sx={{
display: "flex",
filter: "grayscale(100%)",
Expand All @@ -116,20 +124,29 @@ export default function Footer({
))}
</Stack>
</Stack>
<RichTypography
LinkProps={{
color: "text.secondary",
sx: { textDecorationColor: "text.secondary" },
<RichText
variant="footer"
typographyProps={{
sx: {
mt: {
md: 6.5,
},
},
LinkProps: {
color: "text.secondary",
sx: { textDecorationColor: "text.secondary" },
},
}}
mt={{
md: 6.5,
}}
sx={{
color: "text.secondary",
}}
>
{project}
</RichTypography>
sx={(theme: Theme) => ({
a: {
color: theme.palette.text.secondary,
textDecorationColor: theme.palette.text.secondary,
},
mt: "52px",
typography: "footer",
})}
elements={initiative?.description}
/>
</Grid>
</Grid>
</Grid>
Expand Down
33 changes: 20 additions & 13 deletions apps/roboshield/src/components/Footer/FooterDescription.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Figure, Link, RichTypography } from "@commons-ui/next";
import { Stack } from "@mui/material";
import { Figure, Link } from "@commons-ui/next";
import { Stack, Theme } from "@mui/material";
import React from "react";
import RichText from "@/roboshield/components/RichText";

interface FooterDescriptionProps {
description: any;
Expand Down Expand Up @@ -32,18 +33,24 @@ function FooterDescription({ description, logo, sx }: FooterDescriptionProps) {
}}
/>
</Link>
<RichTypography
LinkProps={{
color: "text.secondary",
sx: { textDecorationColor: "text.secondary" },
<RichText
variant="footer"
typographyProps={{
LinkProps: {
color: "text.secondary",
sx: { textDecorationColor: "text.secondary" },
},
}}
sx={{
color: "text.secondary",
mt: "52px !important",
}}
>
{description}
</RichTypography>
sx={(theme: Theme) => ({
a: {
color: theme.palette.text.secondary,
textDecorationColor: theme.palette.text.secondary,
},
mt: "52px",
typography: "footer",
})}
elements={description}
/>
</Stack>
);
}
Expand Down
132 changes: 132 additions & 0 deletions apps/roboshield/src/components/RichText/RichText.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/* eslint-disable react/no-array-index-key */
import { Link, RichTypography } from "@commons-ui/next";
import { Box } from "@mui/material";
import React, { Fragment, ReactNode, forwardRef } from "react";
import { Node, Text } from "slate";

const DEFAULT_PROPS = {
html: false,
};

interface NodeProps {
children?: Node[];
type?: string;
href?: string;
bold?: boolean;
code?: boolean;
italic?: boolean;
text?: ReactNode;
}

interface SerializeProps {
html?: boolean;
[key: string]: any;
}

const serialize = (
children: NodeProps[] | undefined,
props?: SerializeProps,
): ReactNode[] | null =>
children?.map((node, i) => {
if (Text.isText(node)) {
let { text } = node;
if (node.bold) {
text = <strong key={i}>{text}</strong>;
}
if (node.code) {
text = <code key={i}>{text}</code>;
}
if (node.italic) {
text = <em key={i}>{text}</em>;
}
return <Fragment key={i}>{text}</Fragment>;
}

if (!node) {
return null;
}

switch (node.type) {
case "h1":
return (
<RichTypography {...DEFAULT_PROPS} {...props} variant="h1" key={i}>
{serialize(node.children, props)}
</RichTypography>
);
case "h2":
return (
<RichTypography {...DEFAULT_PROPS} {...props} variant="h2" key={i}>
{serialize(node.children, props)}
</RichTypography>
);
case "h3":
return (
<RichTypography {...DEFAULT_PROPS} {...props} variant="h3" key={i}>
{serialize(node.children, props)}
</RichTypography>
);
case "h4":
return (
<RichTypography {...DEFAULT_PROPS} {...props} variant="h4" key={i}>
{serialize(node.children, props)}
</RichTypography>
);
case "h5":
return (
<RichTypography {...DEFAULT_PROPS} {...props} variant="h5" key={i}>
{serialize(node.children, props)}
</RichTypography>
);
case "h6":
return (
<RichTypography {...DEFAULT_PROPS} {...props} variant="h6" key={i}>
{serialize(node.children, props)}
</RichTypography>
);
case "quote":
return (
<blockquote key={i}>{serialize(node.children, props)}</blockquote>
);
case "link":
return (
<RichTypography component={Link} href={node.href} key={i} {...props}>
{serialize(node.children, props)}
</RichTypography>
);
default:
return (
<RichTypography
component={node.type}
{...DEFAULT_PROPS}
{...props}
key={i}
>
{serialize(node.children, props)}
</RichTypography>
);
}
}) || null;

interface RichTextProps {
elements: NodeProps[];
variant?: string;
typographyProps?: SerializeProps;
[key: string]: any;
}

const RichText = forwardRef<HTMLDivElement, RichTextProps>(
function RichText(props, ref) {
const { elements, variant, typographyProps, ...other } = props;

if (!elements?.length) {
return null;
}
return (
<Box {...other} ref={ref}>
{serialize(elements, typographyProps)}
</Box>
);
},
);

export default RichText;
3 changes: 3 additions & 0 deletions apps/roboshield/src/components/RichText/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import RichText from "./RichText";

export default RichText;
10 changes: 10 additions & 0 deletions apps/roboshield/src/lib/data/payload.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ export interface MediaData {
src: string | null;
}

export interface Partner {
logo: MediaData;
name: string;
url: string;
}
export interface Settings {
title: string;
description: TextNode;
Expand All @@ -74,6 +79,11 @@ export interface Settings {
title: string;
embedCode: string;
};
initiative: {
partners: Partner[];
title: string;
description: TextNode;
};
}

export interface CollectionQuery {
Expand Down
46 changes: 1 addition & 45 deletions apps/roboshield/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,49 +223,5 @@ export default function Home() {
}

export async function getServerSideProps(context: any) {
const { props } = await getPageServerSideProps(context);
return {
props: {
...props,
footer: {
logo: props?.footer?.logo,
newsletter: props?.footer?.newsletter,
description: `This site is an <a href="https://github.com/CodeForAfrica/ui/tree/main/apps/roboshield">open source code</a> built by <a href="https://codeforafrica.org">Code for Africa</a>, the continent's largest network of civic technology and data journalism labs. All content is released under a <a href="https://creativecommons.org/licenses/by/4.0/">Creative Commons 4 Attribution</a> License. Reuse it to help empower your own community.`,
connect: props?.footer?.connect,
partners: [
{
name: "DW Africa",
url: "https://www.dw.com/africa",
logo: {
alt: "DW Africa",
prefix: "media",
filename: "dw-africa.png",
sizes: "(max-width: 768px) 100vw, (max-width: 1200px) 50vw, 33vw",
url: "/images/DW.png",
src: "/images/DW.png",
},
},
{
name: "Civic Signal",
url: "https://civicsignal.africa/",
logo: {
alt: "Civic Signal",
prefix: "media",
filename: "civic-signal.png",
sizes: "(max-width: 768px) 100vw, (max-width: 1200px) 50vw, 33vw",
url: "/images/civic-signal.png",
src: "/images/civic-signal.png",
},
},
],
project: `This project was inspired by a
<a href="https://reutersinstitute.politics.ox.ac.uk/how-many-news-websites-block-ai-crawlers" rel="noreferrer noopener" target="blank">survey conducted</a>
by the Reutures Instititue in the Minority World. The Audit data used
in this project was based on
<a href="https://civicsignal.africa" rel="noreferrer noopener" target="blank">CivicSignal</a>
MediaData database.
`,
},
},
};
return getPageServerSideProps(context);
}
Loading

0 comments on commit 0c793d3

Please sign in to comment.