Skip to content

Commit 565e864

Browse files
committed
pretty good spot
1 parent 069c72e commit 565e864

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2196
-192
lines changed

exercises/01.start/01.problem.vite-plugin/app/movies-data.ts

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use server'
2-
31
// Mock data for demonstration
42
let movies = [
53
{
@@ -87,30 +85,3 @@ export async function getMovie(id: number) {
8785
}
8886
return movie
8987
}
90-
91-
export async function toggleFavorite(prevState: any, formData: FormData) {
92-
const movieId = Number(formData.get('id'))
93-
const isFavorite = formData.get('isFavorite') === 'true'
94-
const failureChance = Number(formData.get('failureChance')) || 0
95-
96-
// Simulate failure based on the failure chance
97-
if (failureChance > 0 && Math.random() * 100 < failureChance) {
98-
return {
99-
success: false,
100-
error: `Toggle operation failed! (${failureChance}% failure chance)`,
101-
movieId,
102-
}
103-
}
104-
105-
// Update the movie's favorite status
106-
const movie = movies.find((m) => m.id === movieId)
107-
if (movie) {
108-
movie.isFavorite = isFavorite
109-
}
110-
111-
return {
112-
success: true,
113-
error: null,
114-
movieId,
115-
}
116-
}

exercises/01.start/01.problem.vite-plugin/app/routes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ import { type RouteConfig, index, route } from '@react-router/dev/routes'
22

33
export default [
44
index('routes/index.tsx'),
5-
route('/:movieId', 'routes/$movieId.tsx'),
5+
route('/:movieId', 'routes/movie-details.tsx'),
66
] satisfies RouteConfig

exercises/01.start/01.problem.vite-plugin/app/routes/index.tsx

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,27 @@ import { getMovies } from '#app/movies-data.ts'
33
import { type Route } from './+types/index'
44

55
export async function loader() {
6-
return {
7-
movies: await getMovies(),
8-
}
6+
const movies = await getMovies()
7+
return { movies }
98
}
109

1110
export default function MoviesPage({ loaderData }: Route.ComponentProps) {
11+
const { movies } = loaderData
1212
return (
1313
<main className="bg-background movies-page min-h-screen">
14+
<title>React Router RSC Movies</title>
15+
<meta
16+
name="description"
17+
content="Demo of React Server Components in React Router"
18+
/>
1419
<div className="mx-auto max-w-6xl px-6 py-16">
1520
<div className="mx-auto max-w-4xl">
1621
<h1 className="rr-heading mb-8 text-3xl font-bold">
1722
Movie Collection
1823
</h1>
1924

2025
<div className="grid grid-cols-1 gap-6 md:grid-cols-2 lg:grid-cols-3">
21-
{loaderData.movies.map((movie) => (
26+
{movies.map((movie) => (
2227
<Link
2328
key={movie.id}
2429
to={href('/:movieId', { movieId: String(movie.id) })}
@@ -52,13 +57,3 @@ export default function MoviesPage({ loaderData }: Route.ComponentProps) {
5257
</main>
5358
)
5459
}
55-
56-
export function meta() {
57-
return [
58-
{ title: 'Basic React Router v7' },
59-
{
60-
name: 'description',
61-
content: 'Basic React Router v7 with loaders and client-side navigation',
62-
},
63-
]
64-
}

exercises/01.start/01.problem.vite-plugin/app/routes/$movieId.tsx renamed to exercises/01.start/01.problem.vite-plugin/app/routes/movie-details.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,19 @@
11
import { href, Link } from 'react-router'
22
import { getMovie } from '#app/movies-data.ts'
3-
import { type Route } from './+types/$movieId'
3+
import { type Route } from './+types/movie-details'
44

55
export async function loader({ params }: Route.LoaderArgs) {
66
const movie = await getMovie(Number(params.movieId))
77
return { movie }
88
}
99

10-
export function meta({ loaderData }: Route.MetaArgs) {
11-
return [
12-
{ title: `${loaderData.movie.title} - Demo 1` },
13-
{
14-
name: 'description',
15-
content: loaderData.movie.description,
16-
},
17-
]
18-
}
19-
2010
export default function MovieDetailsPage({ loaderData }: Route.ComponentProps) {
2111
const { movie } = loaderData
2212

2313
return (
2414
<main className="bg-background movie-details-page min-h-screen">
15+
<title>{movie.title}</title>
16+
<meta name="description" content={movie.description} />
2517
<div className="mx-auto max-w-4xl px-6 py-16">
2618
<div className="mb-8">
2719
<nav className="rr-text mb-6 text-sm">

exercises/01.start/01.solution.vite-plugin/app/movies-data.ts

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use server'
2-
31
// Mock data for demonstration
42
let movies = [
53
{
@@ -87,30 +85,3 @@ export async function getMovie(id: number) {
8785
}
8886
return movie
8987
}
90-
91-
export async function toggleFavorite(prevState: any, formData: FormData) {
92-
const movieId = Number(formData.get('id'))
93-
const isFavorite = formData.get('isFavorite') === 'true'
94-
const failureChance = Number(formData.get('failureChance')) || 0
95-
96-
// Simulate failure based on the failure chance
97-
if (failureChance > 0 && Math.random() * 100 < failureChance) {
98-
return {
99-
success: false,
100-
error: `Toggle operation failed! (${failureChance}% failure chance)`,
101-
movieId,
102-
}
103-
}
104-
105-
// Update the movie's favorite status
106-
const movie = movies.find((m) => m.id === movieId)
107-
if (movie) {
108-
movie.isFavorite = isFavorite
109-
}
110-
111-
return {
112-
success: true,
113-
error: null,
114-
movieId,
115-
}
116-
}

exercises/01.start/01.solution.vite-plugin/app/routes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ import { type RouteConfig, index, route } from '@react-router/dev/routes'
22

33
export default [
44
index('routes/index.tsx'),
5-
route('/:movieId', 'routes/$movieId.tsx'),
5+
route('/:movieId', 'routes/movie-details.tsx'),
66
] satisfies RouteConfig

exercises/01.start/01.solution.vite-plugin/app/routes/index.tsx

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,27 @@ import { getMovies } from '#app/movies-data.ts'
33
import { type Route } from './+types/index'
44

55
export async function loader() {
6-
return {
7-
movies: await getMovies(),
8-
}
6+
const movies = await getMovies()
7+
return { movies }
98
}
109

1110
export default function MoviesPage({ loaderData }: Route.ComponentProps) {
11+
const { movies } = loaderData
1212
return (
1313
<main className="bg-background movies-page min-h-screen">
14+
<title>React Router RSC Movies</title>
15+
<meta
16+
name="description"
17+
content="Demo of React Server Components in React Router"
18+
/>
1419
<div className="mx-auto max-w-6xl px-6 py-16">
1520
<div className="mx-auto max-w-4xl">
1621
<h1 className="rr-heading mb-8 text-3xl font-bold">
1722
Movie Collection
1823
</h1>
1924

2025
<div className="grid grid-cols-1 gap-6 md:grid-cols-2 lg:grid-cols-3">
21-
{loaderData.movies.map((movie) => (
26+
{movies.map((movie) => (
2227
<Link
2328
key={movie.id}
2429
to={href('/:movieId', { movieId: String(movie.id) })}
@@ -52,13 +57,3 @@ export default function MoviesPage({ loaderData }: Route.ComponentProps) {
5257
</main>
5358
)
5459
}
55-
56-
export function meta() {
57-
return [
58-
{ title: 'Basic React Router v7' },
59-
{
60-
name: 'description',
61-
content: 'Basic React Router v7 with loaders and client-side navigation',
62-
},
63-
]
64-
}

exercises/01.start/01.solution.vite-plugin/app/routes/$movieId.tsx renamed to exercises/01.start/01.solution.vite-plugin/app/routes/movie-details.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,19 @@
11
import { href, Link } from 'react-router'
22
import { getMovie } from '#app/movies-data.ts'
3-
import { type Route } from './+types/$movieId'
3+
import { type Route } from './+types/movie-details'
44

55
export async function loader({ params }: Route.LoaderArgs) {
66
const movie = await getMovie(Number(params.movieId))
77
return { movie }
88
}
99

10-
export function meta({ loaderData }: Route.MetaArgs) {
11-
return [
12-
{ title: `${loaderData.movie.title} - Demo 1` },
13-
{
14-
name: 'description',
15-
content: loaderData.movie.description,
16-
},
17-
]
18-
}
19-
2010
export default function MovieDetailsPage({ loaderData }: Route.ComponentProps) {
2111
const { movie } = loaderData
2212

2313
return (
2414
<main className="bg-background movie-details-page min-h-screen">
15+
<title>{movie.title}</title>
16+
<meta name="description" content={movie.description} />
2517
<div className="mx-auto max-w-4xl px-6 py-16">
2618
<div className="mb-8">
2719
<nav className="rr-text mb-6 text-sm">

exercises/01.start/02.solution.loader-rsc/app/movies-data.ts

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use server'
2-
31
// Mock data for demonstration
42
let movies = [
53
{
@@ -87,30 +85,3 @@ export async function getMovie(id: number) {
8785
}
8886
return movie
8987
}
90-
91-
export async function toggleFavorite(prevState: any, formData: FormData) {
92-
const movieId = Number(formData.get('id'))
93-
const isFavorite = formData.get('isFavorite') === 'true'
94-
const failureChance = Number(formData.get('failureChance')) || 0
95-
96-
// Simulate failure based on the failure chance
97-
if (failureChance > 0 && Math.random() * 100 < failureChance) {
98-
return {
99-
success: false,
100-
error: `Toggle operation failed! (${failureChance}% failure chance)`,
101-
movieId,
102-
}
103-
}
104-
105-
// Update the movie's favorite status
106-
const movie = movies.find((m) => m.id === movieId)
107-
if (movie) {
108-
movie.isFavorite = isFavorite
109-
}
110-
111-
return {
112-
success: true,
113-
error: null,
114-
movieId,
115-
}
116-
}

exercises/01.start/02.solution.loader-rsc/app/routes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ import { type RouteConfig, index, route } from '@react-router/dev/routes'
22

33
export default [
44
index('routes/index.tsx'),
5-
route('/:movieId', 'routes/$movieId.tsx'),
5+
route('/:movieId', 'routes/movie-details.tsx'),
66
] satisfies RouteConfig

0 commit comments

Comments
 (0)