GithubHelp home page GithubHelp logo

codecrafters-io / frontend Goto Github PK

View Code? Open in Web Editor NEW
24.0 4.0 4.0 76.4 MB

Rebuild complex systems from scratch

Home Page: https://app.codecrafters.io/catalog

License: Other

JavaScript 43.90% HTML 0.86% Handlebars 25.44% CSS 0.31% Makefile 0.09% SCSS 0.02% TypeScript 29.36% Shell 0.02%
ember programming-challenges

frontend's Introduction

codecrafters-frontend

The front-end app that powers app.codecrafters.io.

Prerequisites

You will need the following things installed on your computer:

You can run tests locally without a backend server, but to use the app you'll also need an instance of codecrafters-io/core running. You can either run this against staging, or against a local instance of core. Visit the core repo for setup instructions.

Setup / Installation

  • git clone <repository-url> this repository
  • cd frontend
  • npm install
  • Copy .env.example to .env and fill in the values

Running / Development

Running against staging

  • Run BACKEND_URL="https://backend-staging.codecrafters.io" npm run start
  • View your app at http://localhost:4200

Running with or without FastBoot

  • FastBoot is enabled when running ember build --environment=production
    • Pre-rendering is done only for routes configured under prember section in ember-cli-build.js
  • FastBoot is enabled for all routes when running ember server
    • To disable it, run FASTBOOT_DISABLED=true ember server
    • Alternatively, append ?fastboot=false query parameter to each request URL
  • Add FASTBOOT_DISABLED=true to your local .env file to disable FastBoot completely
    • You can override it by passing FASTBOOT_DISABLED="" in the command line
  • NPM tasks start and start:ember run with FastBoot disabled
  • NPM tasks start:fastboot and start:ember:fastboot run with FastBoot enabled

Running tests

  • Run make serve, ensure your server is running
  • View your tests at http://localhost:4200/tests/index/html?moduleId=abcd.
  • Select the module(s) you want to run from the dropdown at the top right of the page & click "Apply" to run tests.
  • To run all tests, remove the ?moduleId=abcd query parameter from the URL.

Linting

  • npm run lint
  • npm run lint:fix

Analyzing bundle size

  • Run ANALYZE_BUNDLE=true ember server --environment=production

Building

  • npm exec ember build (development)
  • npm run build (production)

Deploying

  • This app is automatically deployed to app.codecrafters.io when a commit is merged into master.
  • Each branch is also deployed to a preview URL via Vercel.

frontend's People

Contributors

chadwhitacre avatar codecrafters-bot avatar deepsourcebot avatar dependabot[bot] avatar ember-tomster avatar friendlymatthew avatar gitbutler-client avatar lib-martinito avatar libmartinito avatar louisnguyencreative avatar m-nikhil avatar rohitpaulk avatar ryan-gang avatar sarupbanskota avatar sweep-ai[bot] avatar vasylmarchuk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

frontend's Issues

Setup cloudflare pages deployment

We ran into a pretty scary bug on Vercel (still yet to know if it's us or them), and we'd like to be prepared for this in the future. Let's see if we can make our deployment work on cloudflare pages - including the pre-rendering, redirects, middleware etc.

@VasylMarchuk I've invited you to our cloudflare pages account. Feel free to purchase a domain if you need it for testing.

Use CodeMirror for rendering code/diffs

Currently, our code rendering system is built in-house using Shiki for code highlighting. Some features we've added on top of this are:

  • Support for rendering diffs (green/red background for lines, +/- icons etc.)
  • Support for expanding/collapsing unchanged diff sections
  • Support for rendering comments (comment icons, expand/collapse comments etc.)

This is getting hard for us to extend, mostly because there isn't a solid foundation that is oriented around code editing. Let's transition away from this and use CodeMirror instead.

Rationale

We're already running into some limitations with the current system.

Current work

One example of a current limitation is the way we handle comments.

Our comment buttons are currently anchored to the right of a line, so in most cases they're hidden by default. Even if you scroll to them, the disappear when you scroll back to read the comment:

Screen.Recording.2024-01-29.at.17.44.47.mov

We want to them to be anchored to the right-most end of the editor container (not the line), like with Repl.it:

Screen.Recording.2024-01-29.at.17.43.05.mov

This is non-trivial to implement from scratch, since they need to be absolutely positioned wrt. the editor container in such a way that they're aware of a line's current Y-index. With CodeMirror, this'll be easier to do by using a system similar to their "gutter" feature (that renders icons on the left side, not right). You'll see that repl-it is using some kind of gutters plugin too.

Future work

A lot of the features we want to build in the future will be easier to build if we're using CodeMirror.

  • Select text and click on "explain this"
  • CodeIntelligence like GitHub, where you hover over a method and it shows you references, go-to defn. etc.
  • Displaying line numbers along with diffs

We might also add an in-browser editor at some point (thought it's unlikely that'll happen soon).

Scope

For starters, let's not add any new features but transition our existing features to use CodeMirror. I'm ordering these based on least used -> most used (we should ship PRs for the least used first, so we can iron out any issues early on before shipping)

1. Rendering buildpack code: URL

This only renders code, no diffs. No expand/collapse functionality, no comments functionality.

Screenshot 2024-01-29 at 17 55 53

2. Rendering Submission Diffs for admins: URL

This renders diffs, but without comments etc. Needs to support expanding/collapsing unchanged lines, but doesn't need to support comments.

Screenshot 2024-01-29 at 17 56 28

3. Rendering first stage solution diffs: URL

Similar to the above.

Screenshot 2024-01-29 at 17 57 36

4. Community Solution Diffs: URL

This is the most complicated one: needs diffs + comments + collapse/expand unchanged sections.

Dark Mode - foundations

We've got a couple of pages / areas within pages that are currently in dark mode.

Examples:

Our styling relies on Tailwind's Dark mode feature.

We want to add dark mode throughout the app, but will do so incrementally since there'll be multiple components that need to be edited to make things look good.

As part of this task, let's add the "foundation" for this.

  • We need dark mode state to be stored in local storage. The options are "light", "dark" and "system". The default will be "light".
  • For staff, we need a way to toggle this in the UI. Let's add another link to account dropdown here, below the Test Sentry link.
  • When this is toggled, we need the "dark" class to be applied / removed from the application layout.
  • Cleanup the is-dark-mode modifier - currently it's pretty hacky, uses intersectionobserver and what not
  • Cleanup the colorScheme service, it currently uses hardcoded rules based on routes
  • Bonus: figure out if there's a way to prevent white flashes on reload due to fastboot (I expect this'll happen?)

Feel free to change the whole structure as much as you like, no need to stick to what we have already - most of this was added in a hurry and not properly thought out.

Note: We need all of this to work in such a way that customers aren't affected, but staff can toggle this at any time and inspect how things look. At the same time, once a staff switches things back to "light" mode, this should be treated the same as a regular user's browser. It's okay for badges, contests etc. to always be in dark mode, we aren't going to support light mode for those endpoints anytime soon.

Investigate extra `await settled` and `await animationsSettled` calls in tests

Brief

Several tests require explicit extra await settled and/or await animationsSettled calls, even when using only settled-aware methods and after properly awaiting on them.

Details

  • 8 extra await settled calls existed before ember-data upgrade
  • 9 more were added during ember-data upgrade: #974
  • 2 more were added during embroider upgrade: #991
  • extra await settled calls are usually accompanied by await animationsSettled calls
  • a significant part of the extra calls happens to be in GitHub-related tests

Try moving to Bun

Let's try moving to Bun for package management. I tried it once long ago but there were compatibility issues.

Let's also change the CI workflow to run on GitHub actions directly instead of namespace.so (we have some weird caching setup there that seems to cause problems when deps change).

Revive user profile OG images

Earlier, we used to have OG images for user profile pages.

Example profile page: https://app.codecrafters.io/users/rohitpaulk

Example URL for an OG image: https://og.codecrafters.io/api/user_profile/8373d847-7cea-457c-94e2-7a1769d51cd6.png.

img

This worked only because previously the request hit our backend app first, it could convert the username to a user ID and insert the OG image tag into the rendered index.html.

Now that we're serving the front-end directly from Vercel, we'll need to do something different to revive this. I've changed the OG images URL to accept usernames too, so this should work now: https://og.codecrafters.io/api/user_profile/rohitpaulk.png.

Let's see what we can do to make these OG images work with the new app - maybe we could use Vercel middleware or something like that to fetch the username from the path and insert the OG image tag into the response for this route specifically?

Upgrade to Ember 5

Tasks

Enable syntax highlighting in tests

In the test environment, we have syntax highlighting disabled:

if (config.environment === 'test' || !window.fetch || !window.XMLHttpRequest) {
. This is because pretender seems to interfere with wasm requests and return invalid contents back. Can we see if there's a way to enable this and bypass pretender?

Fix ember-data warnings when using `findRecord` with a `slug` instead of `id`

Brief

When our app/routes/concept-group.ts route fetches a concept-group model using findRecord, it passes it a slug (rust-primer) instead of id — but the back-end returns a record with id: ca1df9fa-e8e4-4955-bea9-cc09f205ff9c.

this.store.findRecord('concept-group', params.concept_group_slug, { include: 'author' })

This leads to two following ember-data warnings:

Знімок екрана 2024-01-27 о 14 17 22

Details

When changed to using queryRecord as suggested, and passing the slug as a query parameter:

this.store.queryRecord('concept-group', { slug: params.concept_group_slug, include: 'author' })

The following problem occurs:

Знімок екрана 2024-01-27 о 14 21 45

More details

The difference in the API request URLs is:

https://backend-staging.codecrafters.io/api/v1/concept-groups/rust-primer?include=author
https://backend-staging.codecrafters.io/api/v1/concept-groups?include=author&slug=rust-primer

The Problem

The API returns a collection (array) instead of a primary object (one item), because slug is in query params instead of being in the route path as ID would be.

How should API differentiate between store.query and store.queryRecord requests, when the former expects an array, while the latter expects one object, but there's no way to tell from the URL which method was used?

"Update available" flow

🚧 WIP

Problem

We occasionally need to ship backend changes that are incompatible with new frontend versions.

How we handle this currently

Until now our approach has been to keep changes backward compatible for a week or so, and then remove the backward compatibility code after.

Requirements

We'd like to have a way to notify users that an update is available. We don't want to do this on every update, only on ones that where we manually make a version bump.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.