Week 8
Last week, we built a cart on our own computers. This week, we're working on a practice copy of the real Blueprint website, and the cart turns into a merch page.
So far, everything we've built lived in a Vite and React project on your own computer. The Blueprint site is built differently, so the first part of the meeting is about what changed and why. After that, I'll split us into teams and hand out tickets.
What we're building
A Store page on the practice copy of the Stevens Blueprint website. It shows merch, lets you pick a size, and adds things to a cart. It starts with made-up products, so it works with no setup. Later tickets connect it to our Fourthwall store, so it shows real products and prices and sends the cart to checkout.
Fourthwall is the service that runs the store. It holds the products and takes the payment. Our page only shows the products and builds the cart. It never shows a card form.
The shop is called Test. Right now it has four products: the Material Study Tote, the Riverside Studio Hoodie, the Dot Matrix Tee and the Hudson Standard Tee. I'll add more, so don't write code that expects four.
Changes here do not go to the live site at sitblueprint.com. The practice copy is a private repo: blueprint-learn/techteam-merch-page.
Set up
Do this before the meeting if you can. The first time takes a while because things download.
| Step | What to do |
|---|---|
| 1 | Get into the repo. It's private, so open the invite email from GitHub and accept it first, or the clone fails. Then run git clone https://github.com/blueprint-learn/techteam-merch-page.git and cd techteam-merch-page. |
| 2 | Install Deno. The site runs on Deno 2. On a Mac run brew install deno. On Windows run irm https://deno.land/install.ps1 | iex in PowerShell. Run deno --version. It should say 2.something. |
| 3 | Install Node from nodejs.org. Run node -v to check. We only use it for Prettier, the code formatter. |
| 4 | In the repo folder, run deno task serve, then open http://localhost:3000. If you see the Blueprint site, it works. Leave it running while you work. The terminal will show yellow warnings (about deprecated packages, charset, defaultProps). They come from the real site's code and don't mean anything is broken. The line that matters ends with Server started at: http://localhost:3000/. Press Ctrl+C when you're done. |
| 5 | In a second terminal in the same folder, run npm ci. You only do this once. |
The Store page is at http://localhost:3000/store/. If it's not there, run git switch main && git pull.
If something breaks, ask the person next to you first. Then ask me.
The token. Only tickets 1c, 2c, 3, 4 and 5 (issues #29 to #33) need the Fourthwall token. I'll give it to you when they open. Copy .env.example to .env.local, fill in the three values, and restart deno task serve. Without a token, the page still builds and shows the made-up products. Never commit .env.local, and never paste the token in an issue, a PR or a chat.
What is different about the real site?
The Blueprint website is still HTML, CSS, JavaScript, and React, so you already know most of what's in it. What's different is the tooling around it.
| Weeks 1 to 7 | The Blueprint website | |
|---|---|---|
| What runs the tools | Node.js | Deno (version 2) |
| What builds the page | Vite | Lume |
| Installing packages | npm install |
Nothing, Deno downloads what it needs the first time you start it |
| Start it | npm run dev |
deno task serve |
| Address | Vite prints one (usually http://localhost:5173) | http://localhost:3000, and it opens the browser for you |
| Settings | package.json, vite.config.js |
deno.json and _config.ts |
| Pages | One App.jsx |
Every .md file in src/ is a page |
| Where the words go | Inside the JSX | At the top of the .md file |
| Styling | Plain CSS in App.css |
Tailwind classes in the JSX |
| Where React runs | In the browser, every time something changes | Once, when the site is built |
useState and onClick |
Work | Do nothing |
| Finished version | npm run build |
deno task build |
We'll go through the big ones.
What is Deno?
Deno is another JavaScript runtime, just like Node.js. It runs JavaScript (and TypeScript) on your computer, outside the browser. The Blueprint website runs on Deno, so that's what starts when you type deno task serve.
You still need Node.js. The site uses npm for one thing, a formatting tool called Prettier.
What is Lume?
Lume is a static site generator. It takes the files in src/ and turns them into a website made of plain HTML and CSS files. Open deno.json and look at tasks:
"build": "deno task lume",
"serve": "deno task lume -s"
deno task serve builds the site and starts a local server. deno task build builds it into the output/ folder, which is the finished site. These are the same idea as the scripts in package.json from Weeks 1 to 7.
The live site is hosted as plain files, so there's no server running our code when someone visits. Whatever Lume builds is all the visitor gets.
How do pages work?
In Weeks 1 to 7, App.jsx was the whole page. Here, the page /about comes from the file src/about.md. At the top of that file, you'll see this:
---
title: About | Blueprint
layout: _layouts/About.jsx
hero:
title: About Us
description: >
We are the Stevens Institute of Technology chapter of Blueprint ...
---
This part is called front matter. It's data: a title, which layout to use, and the words for the page. The layout line points to src/_includes/_layouts/About.jsx, which is a React component. Lume hands it the front matter as props, so hero.title in the JSX is the "About Us" you see above. It's the same idea as a card getting a title prop in Week 4, except these props come from the top of a file.
The site's docs ask us to keep the words in the .md files and use the JSX just for how it looks, so we'll do that too.
Where does React run?
This is the biggest difference.
In Weeks 1 to 7, React ran in your browser. When setCart ran, React redrew the page. On this site, React runs on your computer, once, while Lume builds the site. It turns your JSX into HTML and stops. The browser never gets React.
That's great for things like "make one card for each product". But useState can't remember anything, because the page is already finished before anyone clicks. And onClick does nothing. Lume leaves the handler out of the HTML completely, and it doesn't tell you. We tried a button with onClick={() => alert("hi")}, and it came out as a plain <button>.
So we can't copy last week's cart over. What carries over is the thinking: components, props, .map() with a key, .find(), spread, and .filter(). The part that has to happen when someone clicks, we'll write as a small plain JavaScript file using addEventListener, like Week 2. It's more work, and that's pretty much why React exists.
Here's a way to keep the two halves straight:
| Runs when the site is built | Runs in the browser |
|---|---|
The .md front matter, layouts, and components (.jsx) |
Files in src/assets/js/, loaded with a <script> tag |
Makes one card per product with .map() |
Reacts to a click and changes the cart |
What is Tailwind?
Instead of writing CSS in a separate file, this site puts small classes right on the elements. className="text-2xl font-bold text-primary" means big, bold, and the Blueprint blue. primary and secondary are colors set in _config.ts. You don't need to memorize any of them. The Tailwind docs have a search box.
How does a change get onto the real site?
On the real repo, merging to main starts a GitHub Action that builds the site and puts it on the live site. Because of that, the club has an approval process. A change that looks different needs a review from the Website Team and the Design Team before it merges.
That's why we're working in a practice copy today. You can't break sitblueprint.com from here. If the Store page turns out well, getting it onto the real site would go through that process.
How a ticket works
Every change is one ticket (a GitHub issue), one branch and one pull request (PR).
- Open the Issues tab and pick a ticket whose "Depends on" tickets are merged. Skip any with the
needs-fourthwall-tokenlabel until I say the token exists. Assign the ticket to yourself. Keep one open ticket at a time. - Make a branch from
mainand call itissue-<issue number>-<short-name>, likeissue-24-format-money. Rungit switch main, thengit pull, thengit switch -c issue-24-format-money. - Do what the ticket says. Every acceptance line has to be true when you finish.
- Run
npm run format:write, then commit and push your branch. The prettier check on your PR fails if you skip it. - Open a PR and write
Closes #<issue number>in it, so the ticket closes when it merges. Copy the acceptance lines from the issue into the PR and tick the ones you tried. - Add me (
@Nishit-Sharma) as the reviewer. I'm the only reviewer. I try it and check each acceptance line, then I approve it or ask for changes. - Once I approve, I merge it. Then run
git switch main && git pullbefore your next ticket.
A few rules:
- Never commit the Fourthwall token or any password.
- Don't change
deno.lock,package-lock.jsonor_config.tsunless the ticket says to. - Don't open PRs against
stevensblueprint/blueprint_websitefrom here. - Stuck for more than 10 minutes? Ask me.
The tickets
Each ticket is a GitHub issue with a scope of work, acceptance criteria and a "Depends on" list. Read the issue for the details. The sizes are my guesses, and I haven't timed them. "Pair" means two people. Tickets are numbered in the order they unlock. A letter means the tickets in that step don't depend on each other, so 1a, 1b and 1c can all go at the same time. The issue titles on GitHub start with the same number. There is no #28.
| Number | Issue | Ticket | Size | Depends on | Needs the token |
|---|---|---|---|---|---|
| 1a | #24 | Build the size picker | M | Nothing | No |
| 1b | #26 | Move the cart into a component and add the estimated subtotal | M | Nothing | No |
| 1c | #29 | Fetch live products with listProducts() |
M (pair) | Nothing | Yes |
| 2a | #25 | Finish the product card: price, missing picture, long names, empty page | M | 1a | No |
| 2b | #27 | Add quantity buttons, a limit of 10 and cart messages | M | 1b | No |
| 2c | #31 | Add the cart requests to fourthwall.js |
M (pair) | 1c | Yes |
| 3 | #30 | Show live products on the page, with the fixtures as the fallback | L (pair) | 1c, 2a | Yes |
| 4 | #32 | Make the cart on the page use the real Fourthwall cart | L (pair) | 2b, 2c, 3 | Yes |
| 5 | #33 | Send the cart to Fourthwall checkout | M | 4 | Yes |
The ones that depend on nothing and don't need the token are 1a and 1b (issues #24 and #26). The token tickets wait until I say the token exists.
Teams
I'll post the teams and tickets here.
When something goes wrong
| What you see | What to check |
|---|---|
| The clone fails or says the repo isn't found | The repo is private. Accept the GitHub invite email first, then clone again. |
deno: command not found |
Close and reopen VS Code, then run deno --version. If it's still missing, redo the Deno step in Set up. |
The first deno task serve seems stuck |
It's downloading. Give it a few minutes. |
/store/ is a 404 |
Run git switch main && git pull, and use the address with the slash at the end. |
| The terminal shows a red error | Read the first red line. A missing ) or } in a .jsx file is the usual cause. |
onClick or useState does nothing |
They can't work here, because React runs once at build time. Use data- labels and addEventListener in a file in src/assets/js/ instead. |
| The prettier check fails on your PR | Run npm run format:write, commit, and push again. |
| The cart is empty after refreshing | That's expected until the real Fourthwall cart tickets are done. |
Resources
These are for later.