Skip to content

Commit

Permalink
Merge pull request #983 from CodeForAfrica/fix/civicsignal_live_previews
Browse files Browse the repository at this point in the history
@/CivicSignal: Fix previews on research blog content
  • Loading branch information
m453h authored Nov 15, 2024
2 parents 22519b6 + 68747d9 commit 4e0d4b1
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 58 deletions.
10 changes: 4 additions & 6 deletions apps/civicsignalblog/src/components/ArticleGrid/ArticleGrid.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Section } from "@commons-ui/core";
import { RichTypography } from "@commons-ui/next";
import { Grid } from "@mui/material";
import { Box, Grid } from "@mui/material";
import React from "react";

import ArticleCardList from "@/civicsignalblog/components/ArticleCardList";
Expand All @@ -26,12 +26,10 @@ const ArticleGrid = React.forwardRef(function ArticleGrid(props, ref) {
return (
<Section sx={{ px: { xs: "20px", sm: 0 }, ...sx }} {...other} ref={ref}>
<Grid container sx={{ py: { xs: "28px", md: 8, lg: "105.29px" } }}>
<Grid
item
xs={12}
<Box
sx={{
order: { xs: 0, md: 1 },
display: articles?.length > 0 ? "flex" : "none",
width: "100%",
}}
>
{/* title is below featuredArticle in md and above hence needs margin-top */}
Expand Down Expand Up @@ -59,7 +57,7 @@ const ArticleGrid = React.forwardRef(function ArticleGrid(props, ref) {
mb: { xs: 2.5, md: 5 },
}}
/>
</Grid>
</Box>
{featuredArticle ? (
<Grid
item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ exports[`<ArticleGrid /> renders unchanged 1`] = `
class="MuiGrid-root MuiGrid-container css-teoma9-MuiGrid-root"
>
<div
class="MuiGrid-root MuiGrid-item MuiGrid-grid-xs-12 css-1rk8ai9-MuiGrid-root"
class="MuiBox-root css-1xugy04"
>
<div
class="MuiStack-root css-kbcct1-MuiStack-root"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ exports[`<Articles /> renders unchanged 1`] = `
class="MuiGrid-root MuiGrid-container css-teoma9-MuiGrid-root"
>
<div
class="MuiGrid-root MuiGrid-item MuiGrid-grid-xs-12 css-1cj7j73-MuiGrid-root"
class="MuiBox-root css-1xugy04"
>
<div
class="MuiTypography-root MuiTypography-h4 css-7yxv5i-MuiTypography-root"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const FooterDescription = React.forwardRef(
</Link>
<RichText
variant="footer"
typographyProps={{
TypographyProps={{
LinkProps: {
color: "text.secondary",
sx: { textDecorationColor: "text.secondary" },
Expand Down
48 changes: 25 additions & 23 deletions apps/civicsignalblog/src/components/LongFormMedia/LongFormMedia.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,34 @@ const LongFormMedia = React.forwardRef((props, ref) => {
}}
ref={ref}
>
<Figure
ImageProps={{
alt: image.alt,
sx: {
objectFit: "cover",
position: "relative !important",
},
src: image.src,
}}
sx={{
height: {
xs: "200px",
md: "500px",
},
width: "100%",
}}
>
<figcaption
style={{
{image && (
<Figure
ImageProps={{
alt: image.alt,
sx: {
objectFit: "cover",
position: "relative !important",
},
src: image.src,
}}
sx={{
height: {
xs: "200px",
md: "500px",
},
width: "100%",
margin: "0 auto",
}}
>
{image.alt}
</figcaption>
</Figure>
<figcaption
style={{
width: "100%",
margin: "0 auto",
}}
>
{image.alt}
</figcaption>
</Figure>
)}
</Box>
);
});
Expand Down
4 changes: 0 additions & 4 deletions apps/civicsignalblog/src/components/NavBar/NavBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,4 @@ NavBar.propTypes = {
),
};

NavBar.defaultProps = {
menus: undefined,
};

export default NavBar;
8 changes: 0 additions & 8 deletions apps/civicsignalblog/src/components/Page/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,4 @@ Page.propTypes = {
title: PropTypes.string,
};

Page.defaultProps = {
children: undefined,
navbar: undefined,
blocks: undefined,
footer: undefined,
title: undefined,
};

export default Page;
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const PageHeader = React.forwardRef(function PageHeader(props, ref) {
{title}
</RichTypography>
<RichText
typographyProps={{
TypographyProps={{
fontWeight: "normal",
variant: "h2",
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ exports[`<PageHeader /> renders unchanged 1`] = `
</h2>
<div
class="MuiBox-root css-0"
typographyprops="[object Object]"
>
<p
class="MuiTypography-root MuiTypography-body1 css-oo170e-MuiTypography-root"
<h2
class="MuiTypography-root MuiTypography-h2 css-hd3436-MuiTypography-root"
>
Let's
<strong>
Expand All @@ -28,7 +27,7 @@ exports[`<PageHeader /> renders unchanged 1`] = `
<strong>
together
</strong>
</p>
</h2>
</div>
</div>
</div>
Expand Down
6 changes: 4 additions & 2 deletions apps/civicsignalblog/src/lib/data/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,13 @@ function getDefaultErrorPageProps(slug = "404") {
}

export async function getPageProps(api, context) {
const { params } = context;
const { params, draftMode = false } = context;
const options = { draft: draftMode };

const slug = getPageSlug(context);
let {
docs: [page],
} = await api.findPage(slug);
} = await api.findPage(slug, options);
if (!page) {
if (["404", "500"].includes(slug)) {
return getDefaultErrorPageProps(slug);
Expand Down
5 changes: 3 additions & 2 deletions apps/civicsignalblog/src/lib/data/pagify/post.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { getPost } from "@/civicsignalblog/lib/data/utils/posts";

async function post(api, context) {
const { params } = context;
const { params, draftMode = false } = context;
const options = { draft: draftMode };
const page = params.slugs[1];
const slug = params.slugs[2];
return getPost(api, slug, page);
return getPost(api, slug, page, options);
}

export default post;
3 changes: 2 additions & 1 deletion apps/civicsignalblog/src/lib/data/utils/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ export async function getPosts(api, params, primaryTag) {
};
}

export async function getPost(api, slug, primaryTag) {
export async function getPost(api, slug, primaryTag, options) {
const { docs } = await api.getCollection("posts", {
...options,
where: {
slug: {
equals: slug,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default async function canAccessApplication(req, searchString) {
if (user) {
const app = headers["CS-App"] || user.currentApp || user.defaultApp;
return (
app.toLowerCase() === searchString.toLowerCase() &&
app?.toLowerCase() === searchString.toLowerCase() &&
user.allowedApps.includes(app)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import applications from "#civicsignalblog/payload/lib/data/common/applications"

function CustomSelectComponent({ path, label }) {
const { user } = useAuth();
const { value, setValue } = useField({ path });
const { value, setValue } = useField<string>({ path });
const [options, setOptions] = useState([]);

useEffect(() => {
Expand All @@ -32,7 +32,7 @@ function CustomSelectComponent({ path, label }) {
path={path}
name={path}
options={options}
value={String(value)}
value={value}
onChange={(e) => setValue(e.value)}
/>
</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/commons-ui-payload/src/RichText/RichText.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const serialize = (children, props) =>
if (!node) {
return null;
}
const TypographyProps = { ...DEFAULT_PROPS, ...props.TypographyProps };
const TypographyProps = { ...DEFAULT_PROPS, ...props?.TypographyProps };
switch (node.type) {
case "h1":
return (
Expand Down

0 comments on commit 4e0d4b1

Please sign in to comment.