Skip to content
7 changes: 2 additions & 5 deletions apps/web/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Route, Routes } from 'react-router-dom';

import AppShell from './components/shell/AppShell/AppShell';
import RouteDestination from './components/RouteDestination/RouteDestination';

import LoginPage from './features/auth/LoginPage';
import RegisterPage from './features/auth/RegisterPage';

import ExplorePage from './features/explore/ExplorePage';
import CookbookPage from './features/cookbook/CookbookPage';
import RecipeCreatePage from './features/recipes/RecipeCreatePage';
import RecipeDetailPage from './features/recipe-detail/RecipeDetailPage';

export function App() {
return (
Expand All @@ -18,10 +18,7 @@ export function App() {

<Route path="/cookbook" element={<CookbookPage />} />
<Route path="/recipes/new" element={<RecipeCreatePage />} />
<Route
path="/recipes/:id"
element={<RouteDestination title="Recipe Detail" />}
/>
<Route path="/recipes/:id" element={<RecipeDetailPage />} />
<Route path="/login" element={<LoginPage />} />
<Route path="/register" element={<RegisterPage />} />
</Route>
Expand Down
12 changes: 10 additions & 2 deletions apps/web/src/components/recipe/RecipeCard/RecipeCard.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState, type ComponentPropsWithoutRef, type ReactNode } from 'react';
import { Link } from 'react-router-dom';
import { Link, useLocation } from 'react-router-dom';

import fallbackRecipeImage from '../../../assets/recipe-fallback.png';
import { HeartIcon } from '../../../icons/actions';
Expand Down Expand Up @@ -109,6 +109,8 @@ export default function RecipeCard({
className = '',
...articleProps
}: RecipeCardProps) {
const location = useLocation();

const [confirmUnsaveOpen, setConfirmUnsaveOpen] = useState(false);

const classes = ['recipe-card', className].filter(Boolean).join(' ');
Expand Down Expand Up @@ -194,7 +196,13 @@ export default function RecipeCard({
<div className="recipe-card__body">
<div className="recipe-card__heading-row">
<h3 className="recipe-card__title">
<Link className="recipe-card__title-link" to={recipePath}>
<Link
className="recipe-card__title-link"
to={recipePath}
state={{
from: `${location.pathname}${location.search}${location.hash}`,
}}
>
{title}
</Link>
</h3>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
@layer components {
.recipe-rating-input {
margin: 0;
padding: 0;

border: 0;
}

.recipe-rating-input__legend {
margin-block-end: var(--space-3);

color: var(--color-text-primary);

font-size: var(--font-size-sm);
font-weight: var(--font-weight-semibold);
}

.recipe-rating-input__options {
display: flex;
flex-wrap: wrap;
gap: var(--space-2);
}

.recipe-rating-input__option {
position: relative;

display: inline-flex;
align-items: center;
justify-content: center;

width: var(--target-size-min);
height: var(--target-size-min);

color: var(--color-brand-primary);
background-color: var(--color-surface);

border: var(--border-width-thin) solid var(--color-border-default);
border-radius: var(--radius-md);

cursor: pointer;

transition:
color var(--duration-fast) var(--ease-standard),
background-color var(--duration-fast) var(--ease-standard),
border-color var(--duration-fast) var(--ease-standard),
box-shadow var(--duration-fast) var(--ease-standard);
}

.recipe-rating-input__option:hover {
background-color: var(--color-surface-hover);
border-color: var(--color-brand-primary);
}

.recipe-rating-input__option:has(.recipe-rating-input__control:checked) {
background-color: var(--color-brand-accent-soft);
border-color: var(--color-brand-primary);
}

.recipe-rating-input__option:has(
.recipe-rating-input__control:focus-visible
) {
outline: var(--border-width-medium) solid var(--color-focus-ring);
outline-offset: 2px;
}

.recipe-rating-input__control {
position: absolute;

width: 1px;
height: 1px;

opacity: 0;
pointer-events: none;
}

.recipe-rating-input__star {
display: inline-flex;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { StarIcon } from '../../../icons/rating';
import { Icon } from '../../ui/Icon/Icon';

import './RecipeRatingInput.css';

export type RecipeRatingInputProps = {
value: number;
onChange: (value: number) => void;
name?: string;
label?: string;
};

const STAR_VALUES = [1, 2, 3, 4, 5] as const;

/**
* Accessible 1–5 star input used when a user rates a recipe.
*
* The native radio inputs keep normal form and keyboard semantics while the
* labels provide the visual star controls.
*/
export default function RecipeRatingInput({
value,
onChange,
name = 'recipe-rating',
label = 'Your rating',
}: RecipeRatingInputProps) {
return (
<fieldset className="recipe-rating-input">
<legend className="recipe-rating-input__legend">{label}</legend>

<div className="recipe-rating-input__options">
{STAR_VALUES.map((starValue) => (
<label key={starValue} className="recipe-rating-input__option">
<input
className="recipe-rating-input__control"
type="radio"
name={name}
value={starValue}
checked={value === starValue}
onChange={() => onChange(starValue)}
/>

<span className="recipe-rating-input__star" aria-hidden="true">
<Icon
icon={StarIcon}
iconProps={{
variant: starValue <= value ? 'full' : 'empty',
}}
size="xl"
/>
</span>

<span className="sr-only">
{starValue} {starValue === 1 ? 'star' : 'stars'}
</span>
</label>
))}
</div>
</fieldset>
);
}
38 changes: 37 additions & 1 deletion apps/web/src/components/recipe/__tests__/RecipeCard.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type ComponentProps } from 'react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { MemoryRouter } from 'react-router-dom';
import { MemoryRouter, Route, Routes, useLocation } from 'react-router-dom';
import { describe, expect, it, vi } from 'vitest';

import RecipeCard from '../RecipeCard/RecipeCard';
Expand Down Expand Up @@ -34,6 +34,16 @@ function renderRecipeCard(props: ComponentProps<typeof RecipeCard>) {
);
}

function LocationStateProbe() {
const location = useLocation();

return (
<output data-testid="recipe-location-state">
{JSON.stringify(location.state)}
</output>
);
}

describe('RecipeCard', () => {
it('exposes the recipe link and accessible rating summary', () => {
renderRecipeCard(baseProps);
Expand All @@ -51,6 +61,32 @@ describe('RecipeCard', () => {
).toBeTruthy();
});

it('keeps the exact browse URL as recipe navigation state', async () => {
const user = userEvent.setup();

render(
<MemoryRouter initialEntries={['/?q=pasta&category=dinner&page=2']}>
<Routes>
<Route path="/" element={<RecipeCard {...baseProps} />} />

<Route path="/recipes/:id" element={<LocationStateProbe />} />
</Routes>
</MemoryRouter>,
);

await user.click(
screen.getByRole('link', {
name: 'Spaghetti Carbonara',
}),
);

expect(screen.getByTestId('recipe-location-state').textContent).toBe(
JSON.stringify({
from: '/?q=pasta&category=dinner&page=2',
}),
);
});

it('renders structured cooking time and servings metadata', () => {
renderRecipeCard(baseProps);

Expand Down
Loading