Skip to content

Conversation

@tuckergordon
Copy link
Owner

@tuckergordon tuckergordon commented Dec 7, 2024

Replaces the manual process of updating the standings table in the contentful post with a custom contentful entry that will be replaced with a table that fetches the standings from supabase.

Includes several changes to make this work:

  • Setup the supabase client
  • Create an API route to fetch the standings for a given week range
  • Create a contentful entry for the standings that is replaced by html
    • Ideally we could use a svelte component to replace this instead of raw html but one thing at a time

Also did some rearranging of the various models and utils to hopefully allow us to scale our file structure better, plus updated everything to use pnpm.

Adding standings to posts

So instead of having to manually type out the standings in the contentful post, now you basically add a placeholder that is a custom entry. Here's how it looks

1. Add a new embedded entry to the post

Screenshot 2024-12-07 at 12 45 26 PM

2. Select the standings mmish component

This is a little weird so let me explain. In Contentful you can create custom content types. I have created a mmish component content type that takes one parameter: the name of the component (e.g. standings, or in the future we'll use matchups and lottery too). Each one of these is "published" as an entry and then can be used.

I originally was thinking about making each of them they're own content type and then allowing optional parameters to be passed in (e.g. maybe you pass the week parameter into the standings content type), but that would require us publishing a new entry for every different parameter configuration. Maybe that could work, but since all i really care about is the name of the custom component to add, i figured it would be easier to keep it generic.
Screenshot 2024-12-07 at 12 45 47 PM

3. Then the entry should appear in your post!

Screenshot 2024-12-07 at 12 45 58 PM

On the back-end, the JS code looks for mmish components with name standings. If it sees one, it swaps it out for a standings table that is fed from the database (it uses the week number in the slug to figure out what week it is)

@vercel
Copy link

vercel bot commented Dec 7, 2024

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

Name Status Preview Comments Updated (UTC)
mmish ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 8, 2024 6:01pm
mmish-api ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 8, 2024 6:01pm

Replaces the manual process of updating the standings table in the
contentful post with a custom contentful entry that will be replaced
with a table that fetches the standings from supabase.

Includes several changes to make this work:
- Setup the supabase client
- Create an API route to fetch the standings for a given week range
- Create a contentful entry for the standings that is replaced by html
  - Ideally we could use a svelte component to replace this instead of
  raw html but one thing at a time

Also did some rearranging of the various models and utils to hopefully
allow us to scale our file structure better.

And switched to pnpm.
pnpm was having issues that npm wasn't, so reverting for now

Uninstall supabase cli

rm package-lock
Copy link
Collaborator

@joe-seibert joe-seibert left a comment

Choose a reason for hiding this comment

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

I think everything here looks fine, so marking as approved. I left a couple comments that are much more about best practices/stylistic stuff when it comes to queries, particularly revolving around team_id. If there's anything else specifically you'd like me to take a look at, let me know, but otherwise this looks good to me.

points_for: points_for.sum(),
points_against: points_against.sum(),
max_points_for: max_points_for.sum(),
teams:team_id(id, name)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similarly, you shouldn't need to do teams:team_id(id, name) here. I think it's suitable to do teams!inner(name). This will give you just the team names, which is what you should be caring about for generating the standings in the post, and the !inner just makes sure the query doesn't return a bunch of NULL results.


return {
teamId: standing.team_id,
// @ts-expect-error - teams is not typed correctly yet
Copy link
Collaborator

Choose a reason for hiding this comment

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

Still true? I am not sure I know how to help with this, maybe it's just something you're already expecting...

return data
.map((standing) => {
const wins = standing.win_h2h + standing.win_median;
const losses = totalWeeks * 2 - wins;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is...probably fine. It seems pretty foolproof, though there are other ways to get this directly from the queries if you'd like. I think either way is roundabout, though, and this minimizes the number of queries you need to make, so it's probably fine.

Copy link
Owner Author

Choose a reason for hiding this comment

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

What do you have in mind?

Remove unused teamId and shorten query
@tuckergordon tuckergordon merged commit 2e05745 into main Dec 8, 2024
4 checks passed
@tuckergordon tuckergordon deleted the standings-api branch December 8, 2024 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants