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

29 connect supabase #46

Merged
merged 9 commits into from
Sep 2, 2023
Merged

29 connect supabase #46

merged 9 commits into from
Sep 2, 2023

Conversation

ilyaflaks
Copy link
Collaborator

Connected Supabase with a the app

Issue: #29

  • Added Supabase config
  • Generated types for the Challenges table using Supabase CLI
  • Replaced hard coded data on the challenges page with data from a table
  • Requested the admins to add two environmental variables

@ilyaflaks ilyaflaks linked an issue Aug 8, 2023 that may be closed by this pull request
Copy link
Member

@HudsonGraeme HudsonGraeme left a comment

Choose a reason for hiding this comment

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

🤯 @ilyaflaks This is amazing - A work of code art 🔥

I have a small improvement to recommend but that's it - everything else looks pristine. Thanks so much for your hard work on this, huge step forward for the project.

learnjs.code-workspace Show resolved Hide resolved
<Heading size='md'>{name}</Heading>
<Text
color={
difficulty === 1
Copy link
Member

Choose a reason for hiding this comment

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

Small recommendation here for easier readability and reuse :) Since enums automatically assign themselves numeric values, it might be a good option here.

enum DifficultyLevel {
  EASY,
  MEDIUM,
  HARD
}

console.log(DifficultyLevel.HARD) // 2

Also, for the colors, we could leverage a map to really simplify things, although this is a bit of overkill lol

const colorForDifficulty: Map<DifficultyLevel, string> = new Map([
  [DifficultyLevel.EASY]: 'green.600',
  ...
])

// In the JSX
colorForDifficulty(difficulty)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I like the idea of using enums but I'm not sure I understand how to implement it.

  1. the numeric values are coming from the database. Should I change 1,2,3 to EASY, MEDIUM and HARD on the Supabase table and then change the type for ChallengeProps to the enum you wrote above? On Supabase side I can create a new type as ENUM and change the 'difficulty' column type from int2 to the new one.
    https://www.postgresql.org/docs/current/datatype-enum.html
  2. as far as I know, Map objects can only be accessed with a .get() method, so it might be easier to just create a regular object and access it like so: colorForDifficulty[difficulty]. In that case, the key of the object can be a string or a number. I agree that this is a cleaner line of code than a nested ternary statement.

Copy link
Member

Choose a reason for hiding this comment

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

1

Hmmm that's a good question. On one hand an enum provides a better description of the difficulty level but on the other hand we could leverage numbers in the future to make something like a loading bar style display of difficulty level. I lean towards keeping the int2 in supabase and using the enum to represent the numeric values in the frontend code. Something like this sandbox I think would work well :)

Edit DifficultyLevel

2

I agree object notation is easier, maps are good for performance but in this situation it's just unnecessary haha. I included an example of the object with enum keys up in the codesandbox :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, I understand now! Thanks for creating the codesandbox. I'll keep the table types as they are and add the enum to the front end.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added enums. I made them lower case because I think it looks better on the page. Uppercase looks good if the font is smaller. Let me know what you guys think!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Did anyone else get kicked out of the MIT xPro Slack channel? I don't even see it on the list of my channels like it ceased to exist altogether... Should we create our own Slack channel or Discord?

Copy link
Member

Choose a reason for hiding this comment

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

I was kicked too! I created a discord over in #47

Sorry I've been away for so long, back now to continue on the project!

Copy link
Member

@HudsonGraeme HudsonGraeme left a comment

Choose a reason for hiding this comment

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

🔥 Thanks very much @ilyaflaks!!

@HudsonGraeme HudsonGraeme merged commit 31dba8e into main Sep 2, 2023
1 check passed
@HudsonGraeme HudsonGraeme deleted the 29-connect-supabase branch September 2, 2023 16:24
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.

Connect Supabase
2 participants