From ec0a0c4cfe363e56994b25d54ec9624b1fc04b4e Mon Sep 17 00:00:00 2001 From: Michael Hudson Nkotagu Date: Mon, 28 Oct 2024 13:32:27 +0300 Subject: [PATCH 01/15] chore: Fix crash due to RichText with missing TypographyProps --- packages/commons-ui-payload/src/RichText/RichText.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/commons-ui-payload/src/RichText/RichText.js b/packages/commons-ui-payload/src/RichText/RichText.js index 610687984..4382312df 100644 --- a/packages/commons-ui-payload/src/RichText/RichText.js +++ b/packages/commons-ui-payload/src/RichText/RichText.js @@ -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 ( From db36e098daeadb68b663560b924116f9dedcaffa Mon Sep 17 00:00:00 2001 From: Michael Hudson Nkotagu Date: Mon, 28 Oct 2024 13:32:54 +0300 Subject: [PATCH 02/15] chore: Update Typography props for PageHeader and FooterDescription --- apps/civicsignalblog/src/components/Footer/FooterDescription.js | 2 +- apps/civicsignalblog/src/components/PageHeader/PageHeader.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/civicsignalblog/src/components/Footer/FooterDescription.js b/apps/civicsignalblog/src/components/Footer/FooterDescription.js index 92f200ef0..065928ac5 100644 --- a/apps/civicsignalblog/src/components/Footer/FooterDescription.js +++ b/apps/civicsignalblog/src/components/Footer/FooterDescription.js @@ -29,7 +29,7 @@ const FooterDescription = React.forwardRef( Date: Mon, 28 Oct 2024 14:23:39 +0300 Subject: [PATCH 03/15] fix: Handle undefined values for current and default apps for first time user account creation --- apps/civicsignalblog/src/payload/access/canAccessApplication.js | 2 +- .../src/payload/components/allowedAppSelect/index.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/civicsignalblog/src/payload/access/canAccessApplication.js b/apps/civicsignalblog/src/payload/access/canAccessApplication.js index c191e1fef..7ee683907 100644 --- a/apps/civicsignalblog/src/payload/access/canAccessApplication.js +++ b/apps/civicsignalblog/src/payload/access/canAccessApplication.js @@ -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) ); } diff --git a/apps/civicsignalblog/src/payload/components/allowedAppSelect/index.tsx b/apps/civicsignalblog/src/payload/components/allowedAppSelect/index.tsx index 4c9dccbca..dce586faa 100644 --- a/apps/civicsignalblog/src/payload/components/allowedAppSelect/index.tsx +++ b/apps/civicsignalblog/src/payload/components/allowedAppSelect/index.tsx @@ -32,7 +32,7 @@ function CustomSelectComponent({ path, label }) { path={path} name={path} options={options} - value={String(value)} + value={value ? String(value) : ``} onChange={(e) => setValue(e.value)} /> From 5ce5896e326630ed01ceee31ed310a18bfa81049 Mon Sep 17 00:00:00 2001 From: Michael Hudson Nkotagu Date: Tue, 29 Oct 2024 12:01:03 +0300 Subject: [PATCH 04/15] fix: Add missing options for fetching draft page content to enable previews --- apps/civicsignalblog/src/lib/data/common/index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/civicsignalblog/src/lib/data/common/index.js b/apps/civicsignalblog/src/lib/data/common/index.js index 8c9474bc5..490f629a1 100644 --- a/apps/civicsignalblog/src/lib/data/common/index.js +++ b/apps/civicsignalblog/src/lib/data/common/index.js @@ -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); From ae48c2b51511fc29b71be327b30f2ec2a58cf47e Mon Sep 17 00:00:00 2001 From: Michael Hudson Nkotagu Date: Wed, 30 Oct 2024 16:45:50 +0300 Subject: [PATCH 05/15] fix: Add preview for posts --- apps/civicsignalblog/src/lib/data/pagify/post.js | 5 +++-- apps/civicsignalblog/src/lib/data/utils/posts.js | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/apps/civicsignalblog/src/lib/data/pagify/post.js b/apps/civicsignalblog/src/lib/data/pagify/post.js index f8329a3ea..7c6c93583 100644 --- a/apps/civicsignalblog/src/lib/data/pagify/post.js +++ b/apps/civicsignalblog/src/lib/data/pagify/post.js @@ -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; diff --git a/apps/civicsignalblog/src/lib/data/utils/posts.js b/apps/civicsignalblog/src/lib/data/utils/posts.js index 65382fd86..ad7aeea73 100644 --- a/apps/civicsignalblog/src/lib/data/utils/posts.js +++ b/apps/civicsignalblog/src/lib/data/utils/posts.js @@ -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, From 5a486351a401f95b9649d3462a4861fe00a82cdd Mon Sep 17 00:00:00 2001 From: Michael Hudson Nkotagu Date: Thu, 31 Oct 2024 11:36:22 +0300 Subject: [PATCH 06/15] chore: Update pageheader snapshot --- .../src/components/PageHeader/PageHeader.snap.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/apps/civicsignalblog/src/components/PageHeader/PageHeader.snap.js b/apps/civicsignalblog/src/components/PageHeader/PageHeader.snap.js index 36f2fabce..c324dcd58 100644 --- a/apps/civicsignalblog/src/components/PageHeader/PageHeader.snap.js +++ b/apps/civicsignalblog/src/components/PageHeader/PageHeader.snap.js @@ -15,10 +15,9 @@ exports[` renders unchanged 1`] = `
-

Let's @@ -28,7 +27,7 @@ exports[` renders unchanged 1`] = ` together -

+
From de4677da23181c88e73d4d5b5011b31674d45f9b Mon Sep 17 00:00:00 2001 From: Michael Hudson Nkotagu Date: Fri, 1 Nov 2024 10:13:49 +0300 Subject: [PATCH 07/15] chore: Remove defaultProps in Pages and Navbar compoments --- apps/civicsignalblog/src/components/NavBar/NavBar.js | 4 ---- apps/civicsignalblog/src/components/Page/Page.js | 8 -------- 2 files changed, 12 deletions(-) diff --git a/apps/civicsignalblog/src/components/NavBar/NavBar.js b/apps/civicsignalblog/src/components/NavBar/NavBar.js index 1aaec3a0a..502756b94 100644 --- a/apps/civicsignalblog/src/components/NavBar/NavBar.js +++ b/apps/civicsignalblog/src/components/NavBar/NavBar.js @@ -67,8 +67,4 @@ NavBar.propTypes = { ), }; -NavBar.defaultProps = { - menus: undefined, -}; - export default NavBar; diff --git a/apps/civicsignalblog/src/components/Page/Page.js b/apps/civicsignalblog/src/components/Page/Page.js index c8872f8b8..984f46ba1 100644 --- a/apps/civicsignalblog/src/components/Page/Page.js +++ b/apps/civicsignalblog/src/components/Page/Page.js @@ -36,12 +36,4 @@ Page.propTypes = { title: PropTypes.string, }; -Page.defaultProps = { - children: undefined, - navbar: undefined, - blocks: undefined, - footer: undefined, - title: undefined, -}; - export default Page; From b2673e7a446706bdef785d647b5c5121f1a2679f Mon Sep 17 00:00:00 2001 From: Michael Hudson Nkotagu Date: Mon, 11 Nov 2024 17:30:31 +0300 Subject: [PATCH 08/15] fix: Improve post tags and filter form UI --- .../src/components/ArticleGrid/ArticleGrid.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/civicsignalblog/src/components/ArticleGrid/ArticleGrid.js b/apps/civicsignalblog/src/components/ArticleGrid/ArticleGrid.js index 174bb8eb2..06ec72e19 100644 --- a/apps/civicsignalblog/src/components/ArticleGrid/ArticleGrid.js +++ b/apps/civicsignalblog/src/components/ArticleGrid/ArticleGrid.js @@ -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"; @@ -26,12 +26,12 @@ const ArticleGrid = React.forwardRef(function ArticleGrid(props, ref) { return (
- 0 ? "flex" : "none", + width: "100%", }} > {/* title is below featuredArticle in md and above hence needs margin-top */} @@ -59,7 +59,7 @@ const ArticleGrid = React.forwardRef(function ArticleGrid(props, ref) { mb: { xs: 2.5, md: 5 }, }} /> - + {featuredArticle ? ( Date: Tue, 12 Nov 2024 13:29:40 +0300 Subject: [PATCH 09/15] fix: Fix preview crashing due to missing image --- .../components/LongFormMedia/LongFormMedia.js | 48 ++++++++++--------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/apps/civicsignalblog/src/components/LongFormMedia/LongFormMedia.js b/apps/civicsignalblog/src/components/LongFormMedia/LongFormMedia.js index 1668d3ee9..8f4ddd335 100644 --- a/apps/civicsignalblog/src/components/LongFormMedia/LongFormMedia.js +++ b/apps/civicsignalblog/src/components/LongFormMedia/LongFormMedia.js @@ -12,32 +12,34 @@ const LongFormMedia = React.forwardRef((props, ref) => { }} ref={ref} > -
-
- {image.alt} -
-
+
+ {image.alt} +
+ + )} ); }); From 87ff9d8a397e309c99a64b98df57c41aaf65261c Mon Sep 17 00:00:00 2001 From: Michael Hudson Nkotagu Date: Wed, 13 Nov 2024 10:27:20 +0300 Subject: [PATCH 10/15] feat: Implement temporary solution for rendering Article Component on Live Previews --- .../src/pages/[...slugs].page.js | 40 +++++++++++++++++-- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/apps/civicsignalblog/src/pages/[...slugs].page.js b/apps/civicsignalblog/src/pages/[...slugs].page.js index 6af79e4e3..bd776210e 100644 --- a/apps/civicsignalblog/src/pages/[...slugs].page.js +++ b/apps/civicsignalblog/src/pages/[...slugs].page.js @@ -20,12 +20,44 @@ const componentsBySlugs = { }; function Index(initialData) { - const { data: props } = useLivePreview({ + let { data: props } = useLivePreview({ serverURL: process.env.NEXT_PUBLIC_APP_URL || "", depth: 2, initialData, }); + // Transform the preview data after receiving it, this is not the cleanest approach + props = { + ...props, + blocks: props?.blocks?.map((block) => { + if (block.blockType === "post-list") { + return { + title: block.stories?.title, + featured: block.stories?.featured + ? { + ...block.stories.featured, + image: { + src: + block.stories.featured.coverImage?.url || + block.stories.featured.meta?.image?.url, + alt: + block.stories.featured.coverImage?.alt || + block.stories.featured.meta?.image?.alt, + }, + } + : null, + posts: [], + pagination: { count: 1, page: 1 }, + primaryTag: block.primaryTag, + tags: [], + slug: block?.primaryTag, + labels: block.labels, + }; + } + return block; + }), + }; + const { blocks, fallback } = props; if (!blocks?.length) { return null; @@ -40,11 +72,13 @@ function Index(initialData) { return ( {blocks.map((block) => { - const Component = componentsBySlugs[block.slug]; + const blockType = block.slug || block.blockType; + const blockId = block.id || block.name || block.blockType; + const Component = componentsBySlugs[blockType]; if (!Component) { return null; } - return ; + return ; })} ); From 63f30c32c3de81de1b7082148465074811c85c57 Mon Sep 17 00:00:00 2001 From: Michael Hudson Nkotagu Date: Wed, 13 Nov 2024 10:41:37 +0300 Subject: [PATCH 11/15] chore: Update Article and ArticleGrid snapshots --- .../src/components/ArticleGrid/ArticleGrid.snap.js | 3 ++- apps/civicsignalblog/src/components/Articles/Articles.snap.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/civicsignalblog/src/components/ArticleGrid/ArticleGrid.snap.js b/apps/civicsignalblog/src/components/ArticleGrid/ArticleGrid.snap.js index 25b172ea1..63c719ebc 100644 --- a/apps/civicsignalblog/src/components/ArticleGrid/ArticleGrid.snap.js +++ b/apps/civicsignalblog/src/components/ArticleGrid/ArticleGrid.snap.js @@ -9,7 +9,8 @@ exports[` renders unchanged 1`] = ` class="MuiGrid-root MuiGrid-container css-teoma9-MuiGrid-root" >
renders unchanged 1`] = ` class="MuiGrid-root MuiGrid-container css-teoma9-MuiGrid-root" >
Date: Thu, 14 Nov 2024 10:55:56 +0300 Subject: [PATCH 12/15] chore: Revert to original live-preview implementation --- .../src/pages/[...slugs].page.js | 40 ++----------------- 1 file changed, 3 insertions(+), 37 deletions(-) diff --git a/apps/civicsignalblog/src/pages/[...slugs].page.js b/apps/civicsignalblog/src/pages/[...slugs].page.js index bd776210e..6af79e4e3 100644 --- a/apps/civicsignalblog/src/pages/[...slugs].page.js +++ b/apps/civicsignalblog/src/pages/[...slugs].page.js @@ -20,44 +20,12 @@ const componentsBySlugs = { }; function Index(initialData) { - let { data: props } = useLivePreview({ + const { data: props } = useLivePreview({ serverURL: process.env.NEXT_PUBLIC_APP_URL || "", depth: 2, initialData, }); - // Transform the preview data after receiving it, this is not the cleanest approach - props = { - ...props, - blocks: props?.blocks?.map((block) => { - if (block.blockType === "post-list") { - return { - title: block.stories?.title, - featured: block.stories?.featured - ? { - ...block.stories.featured, - image: { - src: - block.stories.featured.coverImage?.url || - block.stories.featured.meta?.image?.url, - alt: - block.stories.featured.coverImage?.alt || - block.stories.featured.meta?.image?.alt, - }, - } - : null, - posts: [], - pagination: { count: 1, page: 1 }, - primaryTag: block.primaryTag, - tags: [], - slug: block?.primaryTag, - labels: block.labels, - }; - } - return block; - }), - }; - const { blocks, fallback } = props; if (!blocks?.length) { return null; @@ -72,13 +40,11 @@ function Index(initialData) { return ( {blocks.map((block) => { - const blockType = block.slug || block.blockType; - const blockId = block.id || block.name || block.blockType; - const Component = componentsBySlugs[blockType]; + const Component = componentsBySlugs[block.slug]; if (!Component) { return null; } - return ; + return ; })} ); From 5853a56224c89c8900125c57bba847c98d559c02 Mon Sep 17 00:00:00 2001 From: Michael Hudson Nkotagu Date: Thu, 14 Nov 2024 13:49:23 +0300 Subject: [PATCH 13/15] chore: Remove unnecessary string conversion in allowedAppSelect value prop --- .../src/payload/components/allowedAppSelect/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/civicsignalblog/src/payload/components/allowedAppSelect/index.tsx b/apps/civicsignalblog/src/payload/components/allowedAppSelect/index.tsx index dce586faa..fad3f56dc 100644 --- a/apps/civicsignalblog/src/payload/components/allowedAppSelect/index.tsx +++ b/apps/civicsignalblog/src/payload/components/allowedAppSelect/index.tsx @@ -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({ path }); const [options, setOptions] = useState([]); useEffect(() => { @@ -32,7 +32,7 @@ function CustomSelectComponent({ path, label }) { path={path} name={path} options={options} - value={value ? String(value) : ``} + value={value} onChange={(e) => setValue(e.value)} />
From d707cea8ddbf812d7ffd18e66d015dfae5bd5874 Mon Sep 17 00:00:00 2001 From: Michael Hudson Nkotagu Date: Thu, 14 Nov 2024 13:52:12 +0300 Subject: [PATCH 14/15] chore: Remove wrong props in ArticleGrid --- apps/civicsignalblog/src/components/ArticleGrid/ArticleGrid.js | 2 -- .../src/components/ArticleGrid/ArticleGrid.snap.js | 1 - apps/civicsignalblog/src/components/Articles/Articles.snap.js | 1 - 3 files changed, 4 deletions(-) diff --git a/apps/civicsignalblog/src/components/ArticleGrid/ArticleGrid.js b/apps/civicsignalblog/src/components/ArticleGrid/ArticleGrid.js index 06ec72e19..d4240a66a 100644 --- a/apps/civicsignalblog/src/components/ArticleGrid/ArticleGrid.js +++ b/apps/civicsignalblog/src/components/ArticleGrid/ArticleGrid.js @@ -27,8 +27,6 @@ const ArticleGrid = React.forwardRef(function ArticleGrid(props, ref) {
renders unchanged 1`] = ` >
renders unchanged 1`] = ` >
Date: Thu, 14 Nov 2024 14:31:42 +0300 Subject: [PATCH 15/15] chore: Fix formatting issues --- .../src/payload/components/allowedAppSelect/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/civicsignalblog/src/payload/components/allowedAppSelect/index.tsx b/apps/civicsignalblog/src/payload/components/allowedAppSelect/index.tsx index fad3f56dc..a14502595 100644 --- a/apps/civicsignalblog/src/payload/components/allowedAppSelect/index.tsx +++ b/apps/civicsignalblog/src/payload/components/allowedAppSelect/index.tsx @@ -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({ path }); const [options, setOptions] = useState([]); useEffect(() => {