Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block based rendering #443

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from
Draft

Conversation

kilemensi
Copy link
Member

@kilemensi kilemensi commented Jun 5, 2023

Description

Our current implementation kinds of cheat: Looks at a page and processes all blocks that it knows will more or less be in a page. This PR flips that process: process all blocks in a given page without caring which page it is.

DO NOT MERGE: This PR is up to kick-start discussions and it's not ready to merge just yet. Pages that currently use block-based rendering include:

  • Privacy policy,
  • Knowledge > News, and
  • About.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Chore (non-breaking change that improves code quality)

Screenshots

N/A

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas

@kilemensi kilemensi added bug Something isn't working chore A task that needs to be done (neither enhancement or bug) labels Jun 5, 2023
@kilemensi kilemensi self-assigned this Jun 5, 2023
@vercel
Copy link

vercel bot commented Jun 5, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
codeforafrica ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 7, 2023 6:59am

Copy link
Contributor

@koechkevin koechkevin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kilemensi I try to access http://localhost:3000 I get an error

image

@kilemensi
Copy link
Member Author

@kilemensi I try to access http://localhost:3000 I get an error

That's why it's not ready for merging just yet @koechkevin ... Pushed a fix for it.

Copy link
Contributor

@koechkevin koechkevin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kilemensi I have tested this approach and it looks good.

@kilemensi
Copy link
Member Author

@kilemensi I have tested this approach and it looks good.

Aaaight @koechkevin but what are you thoughts? Is this approach better that what we have? Can we improve the implementation, etc?

The idea is to get everyone's input?

const res = useArticles(slug, { locale, q, sort, page, pageSize });
const res = useArticles(collection || slug, {
locale,
q,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this variable q? the other variables represent the actual representation I believe but q is not clear?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

q = query e.g. https://www.google.com/search?q=code+for+africa or https://github.com/search?q=code+for+africa&type=repositories

@@ -33,7 +33,7 @@ const LongForm = React.forwardRef(function LongForm(props, ref) {
{content.map((c) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using plurals for naming lists then while using the map method we can use the singular reference
e.g contents.map((content) => { ...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 ... except our CMS has chosen to call the page contents content so we're stuck with that for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What CMS are we using?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Payload CMS... Speaking of CMS, I'd also like to hear you views and experiences with various CMSes.

if (!docs?.length) {
return null;
}
const tags = docs.flatMap((doc) => doc.tags).filter((tag) => tag?.slug);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using typescript might help a lot with unsafe type issues here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 ... that's the next step: monorepo -> ci/cd -> typescript -> end-to-end testing. Happy to hear your suggestions as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean we are going to convert our codebase based on this steps

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes-ish.

  1. We've moved about 3 apps into this monorepo (charter.africa, codeforafrica and promisetracker). We still have a few to go (pesayetu, trolltracker, etc.)
  2. We've already implemented CI/CD for charter.africa and codeforafrica (you can see the workflows in the repo).
  3. We have included Jest (for component testing) and Playwright (for end-to-end testing) but we're not really using them that much (just snapshot testing w/ Jest).

So the idea is come up with a comprehensive plan that will allow us to move everything UI into this repo and make sure we have ci/cd -> typescript -> end-to-end testing for all the apps.

const { slug } = page;

// SWR fallback
let swrKey = `/api/v1/knowledge/${slug}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

base end points like this shall change time to time so it should be added to configuration files

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to chat about how we'll do it for all base end points in the app/repo.

@kilemensi
Copy link
Member Author

Thanks for the review @saminegash, but what are you thoughts about the approach so far?

@saminegash
Copy link
Contributor

I think I cannot say more as I am just looking into the codebases and diving in I believe.

@kilemensi
Copy link
Member Author

Your review and thoughts @kelvinkipruto

@kilemensi
Copy link
Member Author

@kelvinkipruto

@kelvinkipruto
Copy link
Contributor

@kilemensi I have gotten this to work, but it's hard to follow the code flow compared to the current page-based processing. For example, the pagify function means some block will still be processed per page?
I like how blockify works, and I think it's a better way than our current method.
One issue I have faced though is when I add a news block to any that does not have a parent page, it breaks. ( I will investigate further) but given this approach, shouldn't it be processed regardless of the page it is on?

@kilemensi
Copy link
Member Author

@kilemensi ... the pagify function means some block will still be processed per page?

pagify is for those pages that do not exist in the CMS @kelvinkipruto. For example single news item page. pagify creates the block(s) that should be displayed in this page but doesn't process/render the page. The processing/rendering still happens in blockify.

Not sure if there is anything we can do about these sort of pages but any ideas are welcomed.

I like how blockify works, and I think it's a better way than our current method.

👍🏽

One issue I have faced though is when I add a news block to any that does not have a parent page, it breaks. ( I will investigate further) but given this approach, shouldn't it be processed regardless of the page it is on?

Yes, news block should be processed regardless of which page it's on. If it doesn't work, do investigate and report. It's most likely an edge case we haven't considered.

@kilemensi
Copy link
Member Author

Taking this back to draft to focus on current PROD issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working chore A task that needs to be done (neither enhancement or bug)
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

4 participants