acekyd / made-in-nigeria

Here is a curation of awesome tools built by Nigerians that can be used by anybody and from anywhere in the world.
https://madeinnigeria.dev
1.02k stars 403 forks source link

Improve how projects data is fetched and made available in V2 #268

Closed acekyd closed 10 months ago

acekyd commented 10 months ago

I don't use much Next but I currently fetch projects only on the Projects page however would love to do this in a way that makes the data available across state in the website.

This will enable building components that could use the data in a user's profile on the blog for example.

Open to recommendations or a PR.

Current implementation can be found in Projects

kaf-lamed-beyt commented 10 months ago

Okay... so, a profile can be tied to a project's owner?

acekyd commented 10 months ago

Yes and also hopefully make the website faster. And if someone goes to a direct link without going to the projects page, the data is also available. @kaf-lamed-beyt

kaf-lamed-beyt commented 10 months ago

Oh okay. makes sense now.

I thought of an approach — two actually — of accomplishing this. The first involves using a Zustand store to persist the project's data.

The second encompasses the use of a shareable hook — perhaps, useProjects() — which would encapsulate the getData and convertToJSON() functions. So we'd just call the hook wherever we need it in the project.

Thinking of it again now, I think it'd be better if we go with the store approach as it'd prevent us from fetching data over and over again wherever the hook is used in a component. We fetch the project data once from GitHub and populate the store with it.

Any time we want anything from the store, we go there. Let me know how this sounds @acekyd.

acekyd commented 10 months ago

Yes I like the sound of the universal store so we can reuse the data anyhow we please. @kaf-lamed-beyt

kaf-lamed-beyt commented 10 months ago

Awesome! I'll try something out during the week and let you know how it goes.

acekyd commented 10 months ago

What questions do you have about this? @kaf-lamed-beyt

kaf-lamed-beyt commented 10 months ago

Okay... say we keep all the projects in a store, yeah?

This will enable building components that could use the data in a user's profile on the blog for example.

What's the relationship between those projects and the creators? Say, on the creators route for instance

acekyd commented 10 months ago

@kaf-lamed-beyt So the main goal is this - whichever page serves as the entry point for a user - could be a blog page, could be the about page, I'd want to load the projects in the background (and one time) so that wherever they navigate to after that is smoother.

As regards the interoperability of the data with components / pages - for the creators, the routes would be their username e.g /creators/acekyd. And in that markdown, we can show projects that match their username. Or on the landing page we can randomly or manually select featured projects without having to run a http request.

Not all of these features are currently available or will be on launch, but good to think of the data fetching with that in mind.

kaf-lamed-beyt commented 10 months ago

Aha! I see. Now I understand. I'll refactor the current store approach. If anything changes I'll let you know.

acekyd commented 10 months ago

Resolved in #272