Basic Recipe page routing.

This commit is contained in:
Jesse Brault 2024-07-31 10:17:42 -05:00
parent 6cd87ab3c8
commit 5f87caa887
7 changed files with 63 additions and 9 deletions

View File

@ -33,7 +33,8 @@ const getRecipeInfos = async (
ownerUsername, ownerUsername,
isPublic, isPublic,
starCount, starCount,
mainImage: rawMainImage mainImage: rawMainImage,
slug
}) => ({ }) => ({
id, id,
updated: new Date(rawUpdated), updated: new Date(rawUpdated),
@ -54,7 +55,8 @@ const getRecipeInfos = async (
caption: rawMainImage.caption, caption: rawMainImage.caption,
owner: rawMainImage.owner, owner: rawMainImage.owner,
isPublic: rawMainImage.isPublic isPublic: rawMainImage.isPublic
} },
slug
}) })
) )
} }

View File

@ -9,6 +9,7 @@ export interface RawRecipeInfoView {
isPublic: boolean isPublic: boolean
starCount: number starCount: number
mainImage: RawImageView mainImage: RawImageView
slug: string
} }
interface RecipeInfoView { interface RecipeInfoView {
@ -20,6 +21,7 @@ interface RecipeInfoView {
isPublic: boolean isPublic: boolean
starCount: number starCount: number
mainImage: ImageView mainImage: ImageView
slug: string
} }
export default RecipeInfoView export default RecipeInfoView

View File

@ -1,9 +1,11 @@
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import classes from './recipe-card.module.css' import classes from './recipe-card.module.css'
import { Link } from '@tanstack/react-router'
export interface RecipeCardProps { export interface RecipeCardProps {
title: string title: string
ownerUsername: string ownerUsername: string
slug: string
mainImageUrl: string mainImageUrl: string
mainImageAlt?: string mainImageAlt?: string
starCount: number starCount: number
@ -13,6 +15,7 @@ export interface RecipeCardProps {
const RecipeCard = ({ const RecipeCard = ({
title, title,
ownerUsername, ownerUsername,
slug,
mainImageUrl, mainImageUrl,
mainImageAlt, mainImageAlt,
starCount, starCount,
@ -20,12 +23,20 @@ const RecipeCard = ({
}: RecipeCardProps) => { }: RecipeCardProps) => {
return ( return (
<article className={classes.recipeCard}> <article className={classes.recipeCard}>
<Link
to="/recipes/$username/$slug"
params={{
username: ownerUsername,
slug
}}
>
<img <img
className={classes.recipeImage} className={classes.recipeImage}
src={mainImageUrl} src={mainImageUrl}
alt={mainImageAlt} alt={mainImageAlt}
title={mainImageAlt} title={mainImageAlt}
/> />
</Link>
<div className={classes.infoContainer}> <div className={classes.infoContainer}>
<h1 className={classes.title}>{title}</h1> <h1 className={classes.title}>{title}</h1>
<span> <span>

View File

@ -0,0 +1,14 @@
import { Route } from '../../routes/recipes_/$username.$slug'
export interface RecipeProps {}
const Recipe = ({}: RecipeProps) => {
const { username, slug } = Route.useParams()
return (
<>
Hello, {username}/{slug}
</>
)
}
export default Recipe

View File

@ -34,6 +34,7 @@ const Recipes = () => {
key={view.id} key={view.id}
title={view.title} title={view.title}
ownerUsername={view.ownerUsername} ownerUsername={view.ownerUsername}
slug={view.slug}
mainImageUrl={view.mainImage.url} mainImageUrl={view.mainImage.url}
mainImageAlt={ mainImageAlt={
view.mainImage.alt ? view.mainImage.alt : undefined view.mainImage.alt ? view.mainImage.alt : undefined

View File

@ -15,6 +15,7 @@ import { Route as RecipesImport } from './routes/recipes'
import { Route as LoginImport } from './routes/login' import { Route as LoginImport } from './routes/login'
import { Route as AuthImport } from './routes/_auth' import { Route as AuthImport } from './routes/_auth'
import { Route as AuthIndexImport } from './routes/_auth/index' import { Route as AuthIndexImport } from './routes/_auth/index'
import { Route as RecipesUsernameSlugImport } from './routes/recipes_/$username.$slug'
// Create/Update Routes // Create/Update Routes
@ -38,6 +39,11 @@ const AuthIndexRoute = AuthIndexImport.update({
getParentRoute: () => AuthRoute, getParentRoute: () => AuthRoute,
} as any) } as any)
const RecipesUsernameSlugRoute = RecipesUsernameSlugImport.update({
path: '/recipes/$username/$slug',
getParentRoute: () => rootRoute,
} as any)
// Populate the FileRoutesByPath interface // Populate the FileRoutesByPath interface
declare module '@tanstack/react-router' { declare module '@tanstack/react-router' {
@ -70,6 +76,13 @@ declare module '@tanstack/react-router' {
preLoaderRoute: typeof AuthIndexImport preLoaderRoute: typeof AuthIndexImport
parentRoute: typeof AuthImport parentRoute: typeof AuthImport
} }
'/recipes/$username/$slug': {
id: '/recipes/$username/$slug'
path: '/recipes/$username/$slug'
fullPath: '/recipes/$username/$slug'
preLoaderRoute: typeof RecipesUsernameSlugImport
parentRoute: typeof rootRoute
}
} }
} }
@ -79,6 +92,7 @@ export const routeTree = rootRoute.addChildren({
AuthRoute: AuthRoute.addChildren({ AuthIndexRoute }), AuthRoute: AuthRoute.addChildren({ AuthIndexRoute }),
LoginRoute, LoginRoute,
RecipesRoute, RecipesRoute,
RecipesUsernameSlugRoute,
}) })
/* prettier-ignore-end */ /* prettier-ignore-end */
@ -91,7 +105,8 @@ export const routeTree = rootRoute.addChildren({
"children": [ "children": [
"/_auth", "/_auth",
"/login", "/login",
"/recipes" "/recipes",
"/recipes/$username/$slug"
] ]
}, },
"/_auth": { "/_auth": {
@ -109,6 +124,9 @@ export const routeTree = rootRoute.addChildren({
"/_auth/": { "/_auth/": {
"filePath": "_auth/index.tsx", "filePath": "_auth/index.tsx",
"parent": "/_auth" "parent": "/_auth"
},
"/recipes/$username/$slug": {
"filePath": "recipes_/$username.$slug.tsx"
} }
} }
} }

View File

@ -0,0 +1,6 @@
import { createFileRoute } from '@tanstack/react-router'
import Recipe from '../../pages/recipe/Recipe'
export const Route = createFileRoute('/recipes/$username/$slug')({
component: Recipe
})