Skip to content

Commit e3e6e80

Browse files
committed
Refactor code structure for improved readability and maintainability
1 parent 65e0069 commit e3e6e80

File tree

23 files changed

+57
-33
lines changed

23 files changed

+57
-33
lines changed

.gitignore

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ workspace/
55
**/build/
66
**/public/build
77
**/playwright-report
8-
data.db
8+
99
/playground
1010
**/tsconfig.tsbuildinfo
1111
.react-router
@@ -14,6 +14,5 @@ data.db
1414
# we're going to keep them around.
1515
# .env
1616
test-results
17-
**/generated/**
18-
data.db*
17+
**/generated/**
1918
.env

.vscode/settings.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
"typescript.preferences.autoImportFileExcludePatterns": [
33
"@remix-run/server-runtime",
44
"@remix-run/router",
5-
"react-router-dom",
6-
"react-router"
5+
"react-router-dom"
76
],
87
"workbench.editorAssociations": {
98
"*.db": "sqlite-viewer.view"

exercises/02.metadata/01.problem.styling/app/root.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ import { EpicShop } from './epicshop'
1313
export const links: Route.LinksFunction = () => [
1414
// 🐨 Add the stylesheet imported from app.css!
1515
// 🐨 Add fonts and preconnect to google!
16-
// 💰 { rel: 'preconnect', href: 'https://fonts.googleapis.com' },
17-
// 💰 { rel: 'preconnect', href: 'https://fonts.gstatic.com', crossOrigin: 'anonymous' },
16+
// 💰 Use this to preconnect to google fonts
17+
// { rel: 'preconnect', href: 'https://fonts.googleapis.com' },
18+
// 💰 Use this to preconnect to google fonts
19+
// { rel: 'preconnect', href: 'https://fonts.gstatic.com', crossOrigin: 'anonymous' },
1820
// 💰 this is the link to the fonts we want to use:
1921
// https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap
2022
]

exercises/02.metadata/02.problem.titles-react/README.mdx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,15 @@ which would produce the following HTML:
4141

4242
Now that you understand how the hoisting mechanism works, let's see how we can use
4343
this to our advantage by adding titles to our pages using React.
44-
45-
Every route in the project has instructions on what you need to do, go Koala hunting
46-
and try to add titles to all the pages!
44+
4745

4846
📜 https://react.dev/blog/2024/12/05/react-19#support-for-metadata-tags
4947

5048
## Exercise Goals
5149

5250
In this exercise, we're going to add titles to our pages using React 19 JSX metadata tags.
5351

54-
1. Go through every route, Kody will be there to guide you in what you need to do.
52+
1. Go through product routes, Kody will be there to guide you in what you need to do.
5553
2. Add titles to relevant pages using React 19 JSX metadata tags.
5654
3. Make sure to test your titles by visiting the pages and checking the document title in the
5755
browser tab and also in the document head using the browser dev tools.

exercises/02.metadata/03.problem.titles-with-meta/README.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ In this exercise, we're going to use the `meta` export to add titles to our page
3636
## Exercise Goals
3737

3838
1. Go to the `root.tsx` file and find Kody there, he will help you add the first SEO title in the root.
39-
2. Once you have that in place visit each route and add the `meta` export to add titles to each page.
39+
2. Once you have that in place visit the landing page route, and then the product routes and add the `meta` export to add titles to each page.
4040
3. Make sure to include the root meta in the title to have `Epic Shop - <Page Specific Title>`.
4141
4. Kelly has helped us with utilities for metadata parsing and reading! You can find them in
4242
`app/utils/metadata.ts`. Feel free to check their implementation first!

exercises/02.metadata/03.problem.titles-with-meta/app/root.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export const links: Route.LinksFunction = () => [
2828
export const meta: Route.MetaFunction = () => {
2929
// 🐨 Add the title to this page
3030
// 💰 The title should be "Epic Shop"
31+
// 💰 Even if you add it the child route (_landing._index/route.tsx) takes precedence so you need to change it there as well to see this reflected on the page
3132
return []
3233
}
3334

exercises/02.metadata/03.problem.titles-with-meta/app/routes/_landing._index/route.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// 💰 You will need these utilities! Feel free to check their implementation first!
12
import {
23
getMetaFromMatches,
34
getMetaTitle,
@@ -9,7 +10,6 @@ import { FeaturedProductsSection } from './featured-products.section'
910
import { FeaturesSection } from './features-section'
1011
import { HeroSection } from './hero-section'
1112
import { NewsletterSection } from './newsletter-section'
12-
// 💰 You will need these utilities! Feel free to check their implementation first!
1313

1414
// 🐨 We want to include the root meta in the title to have Epic Shop | Terms of Use
1515
export const meta: Route.MetaFunction = ({ matches }) => {

exercises/02.metadata/03.problem.titles-with-meta/app/routes/_landing.products._index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { Filter, Grid, List, Star, Heart } from 'lucide-react'
22
import { useState, useMemo } from 'react'
33
import { Link } from 'react-router'
4+
// 💰 You will need these utilities! Feel free to check their implementation first!
45
import {
56
getMetaFromMatches,
67
getMetaTitle,
78
constructPrefixedTitle,
89
} from '#app/utils/metadata.js'
910
import { products, categories, brands } from '../../data/products'
10-
// 💰 You will need these utilities! Feel free to check their implementation first!
1111
import { type Route } from './+types/_landing.products._index'
1212

1313
// 🐨 We want to include the root meta in the title to have Epic Shop | All Products

exercises/03.data-fetching/01.problem.fetching-with-loaders/README.mdx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,13 @@ a different concept of data fetching with loaders:
4747

4848
1. **Basic Data Fetching**: In the first route, we will implement a simple loader that fetches
4949
all products from the database and displays them on the page. This will help you understand
50-
the basics of setting up a loader and using the fetched data in your components.
50+
the basics of setting up a loader and using the fetched data in your components. (`_landing._index.route.tsx`)
5151
2. **Using URL Parameters**: The second route will introduce URL parameters. We will create a loader
5252
that fetches a product based on the ID provided in the URL. This will teach you how to read
53-
URL parameters in loaders and use them to fetch specific data.
53+
URL parameters in loaders and use them to fetch specific data. (`_landing.products.$productId.route.tsx`)
5454
3. **Optimizing Data Fetching**: In the final route, we will focus on optimizing our data fetching.
5555
We will use a simple trick of parallelizing multiple data fetches to improve performance. This will help you
56-
understand how to make your loaders more efficient.
56+
understand how to make your loaders more efficient. (`_landing.products._index/route.tsx`)
57+
58+
We also want to replace the hardcoded data we had before with real data from the database in `categories-section.tsx`
59+
and `featured-products-section.tsx` components.

exercises/03.data-fetching/01.problem.fetching-with-loaders/app/routes/_landing.products._index/route.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,10 @@ export default function ProductsPage({ loaderData }: Route.ComponentProps) {
151151
// 💰 You can just use category.id and category.name here!
152152
<button
153153
key={category}
154+
// 💰 Use category.name
154155
onClick={() => setSelectedCategory(category)}
155156
className={`block w-full rounded-lg px-3 py-2 text-left transition-colors duration-200 ${
157+
// 💰 Match with category.name
156158
selectedCategory === category
157159
? 'bg-amber-100 text-amber-800 dark:bg-amber-900/30 dark:text-amber-200'
158160
: 'text-gray-700 hover:bg-gray-100 dark:text-gray-300 dark:hover:bg-gray-700'
@@ -174,8 +176,10 @@ export default function ProductsPage({ loaderData }: Route.ComponentProps) {
174176
// 💰 You can just use brand.id and brand.name here!
175177
<button
176178
key={brand}
179+
// 💰 Use brand.name
177180
onClick={() => setBrand(brand)}
178181
className={`block w-full rounded-lg px-3 py-2 text-left transition-colors duration-200 ${
182+
// 💰 Use brand.name
179183
selectedBrand === brand
180184
? 'bg-amber-100 text-amber-800 dark:bg-amber-900/30 dark:text-amber-200'
181185
: 'text-gray-700 hover:bg-gray-100 dark:text-gray-300 dark:hover:bg-gray-700'

0 commit comments

Comments
 (0)