Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"dependencies": {
"react": "19.2.0",
"react-dom": "19.2.0",
"react-easy-crop": "6.2.4",
"react-router-dom": "7.9.6",
"zustand": "5.0.8"
},
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export function App() {
<Route index element={<ExplorePage />} />
<Route element={<RequireAuth />}>
<Route path="/cookbook" element={<CookbookPage />} />
</Route>
<Route element={<RequireAuth />}>
<Route path="/recipes/new" element={<RecipeCreatePage />} />
</Route>
<Route path="/recipes/:id" element={<RecipeDetailPage />} />
Expand Down
45 changes: 42 additions & 3 deletions apps/web/src/features/recipes/RecipeCreatePage.css
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@

.recipe-create-page__image-selector {
flex: 1;
aspect-ratio: 3 / 2;
justify-content: center;
}

Expand Down Expand Up @@ -178,10 +179,9 @@

.recipe-create-page__image-preview {
display: block;
aspect-ratio: 3 / 2;
width: 100%;
height: 100%;
min-height: 12rem;
max-height: 20rem;
height: auto;
object-fit: cover;
border-radius: var(--radius-md);
}
Expand Down Expand Up @@ -224,6 +224,33 @@
gap: var(--space-2);
}

.recipe-create-page__ingredient-fields {
display: grid;
grid-template-columns: minmax(0, 1.5fr) minmax(6rem, 0.6fr) minmax(
6rem,
0.7fr
);
gap: var(--space-2);
min-width: 0;
}

.recipe-create-page__cropper {
position: relative;
height: min(60vh, 24rem);
background: var(--color-surface-inverse);
}

.recipe-create-page__crop-zoom {
display: flex;
align-items: center;
gap: var(--space-3);
margin-top: var(--space-3);
}

.recipe-create-page__crop-zoom input {
flex: 1;
}

.recipe-create-page__repeatable-row--dragging {
opacity: 0.55;
}
Expand All @@ -236,6 +263,8 @@
min-height: var(--target-size-min);
color: var(--color-text-muted);
cursor: grab;
touch-action: none;
user-select: none;
}

.recipe-create-page__drag-handle:active {
Expand All @@ -257,6 +286,16 @@
color: var(--color-text-secondary);
}

@media (max-width: 52rem) {
.recipe-create-page__ingredient-fields {
grid-template-columns: minmax(0, 1fr) minmax(6rem, 0.7fr);
}

.recipe-create-page__ingredient-fields > :first-child {
grid-column: 1 / -1;
}
}

@media (max-width: 40rem) {
.recipe-create-page {
padding-block: var(--space-6) var(--space-8);
Expand Down
84 changes: 79 additions & 5 deletions apps/web/src/features/recipes/RecipeCreatePage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ describe('RecipeCreatePage', () => {
screen.getByText('Enter a cooking time of at least 1 minute.'),
).toBeInTheDocument();
expect(screen.getByText('Choose a recipe category.')).toBeInTheDocument();
expect(screen.getByText('Add an ingredient.')).toBeInTheDocument();
expect(
screen.getByText('Complete the ingredient name, amount, and unit.'),
).toBeInTheDocument();
expect(screen.getByText('Add an instruction.')).toBeInTheDocument();
expect(screen.getByLabelText(/Recipe title/)).toHaveAttribute(
'aria-invalid',
Expand Down Expand Up @@ -63,6 +65,62 @@ describe('RecipeCreatePage', () => {
expect(screen.queryByLabelText('Step 2')).not.toBeInTheDocument();
});

it('supports structured ingredients and button-based reordering', async () => {
const user = userEvent.setup();

render(<RecipeCreatePage />);

await user.type(screen.getByLabelText('Ingredient 1'), 'Flour');
await user.type(screen.getByLabelText('Ingredient 1 amount'), '200');
await user.selectOptions(screen.getByLabelText('Ingredient 1 unit'), 'g');
await user.click(screen.getByRole('button', { name: 'Add ingredient' }));
await user.type(screen.getByLabelText('Ingredient 2'), 'Sugar');
const firstIngredientRow = screen
.getByLabelText('Ingredient 1')
.closest('.recipe-create-page__repeatable-row');
const secondIngredientRow = screen
.getByLabelText('Ingredient 2')
.closest('.recipe-create-page__repeatable-row');

fireEvent.pointerDown(
firstIngredientRow!.querySelector('.recipe-create-page__drag-handle')!,
{ pointerId: 1, pointerType: 'touch', button: 0 },
);
fireEvent.pointerMove(secondIngredientRow!, {
pointerId: 1,
pointerType: 'touch',
});
fireEvent.pointerUp(window, { pointerId: 1, pointerType: 'touch' });

expect(screen.getByLabelText('Ingredient 1')).toHaveValue('Sugar');
expect(screen.getByLabelText('Ingredient 2')).toHaveValue('Flour');
expect(screen.getByLabelText('Ingredient 2 amount')).toHaveValue(200);
expect(screen.getByLabelText('Ingredient 2 unit')).toHaveValue('g');

await user.click(screen.getByRole('button', { name: 'Add step' }));
await user.type(screen.getByLabelText('Step 1'), 'Mix');
await user.type(screen.getByLabelText('Step 2'), 'Bake');
const firstInstructionRow = screen
.getByLabelText('Step 1')
.closest('.recipe-create-page__repeatable-row');
const secondInstructionRow = screen
.getByLabelText('Step 2')
.closest('.recipe-create-page__repeatable-row');

fireEvent.pointerDown(
firstInstructionRow!.querySelector('.recipe-create-page__drag-handle')!,
{ pointerId: 2, pointerType: 'touch', button: 0 },
);
fireEvent.pointerMove(secondInstructionRow!, {
pointerId: 2,
pointerType: 'touch',
});
fireEvent.pointerUp(window, { pointerId: 2, pointerType: 'touch' });

expect(screen.getByLabelText('Step 1')).toHaveValue('Bake');
expect(screen.getByLabelText('Step 2')).toHaveValue('Mix');
});

it('reorders ingredients and instructions by drag and drop', async () => {
const user = userEvent.setup();

Expand All @@ -79,8 +137,15 @@ describe('RecipeCreatePage', () => {
.getByLabelText('Ingredient 2')
.closest('.recipe-create-page__repeatable-row');

fireEvent.dragStart(firstIngredientRow!);
fireEvent.drop(secondIngredientRow!, { dataTransfer: {} });
fireEvent.pointerDown(
firstIngredientRow!.querySelector('.recipe-create-page__drag-handle')!,
{ pointerId: 3, pointerType: 'mouse', button: 0 },
);
fireEvent.pointerMove(secondIngredientRow!, {
pointerId: 3,
pointerType: 'mouse',
});
fireEvent.pointerUp(window, { pointerId: 3, pointerType: 'mouse' });

expect(screen.getByLabelText('Ingredient 1')).toHaveValue('Sugar');
expect(screen.getByLabelText('Ingredient 2')).toHaveValue('Flour');
Expand All @@ -96,8 +161,15 @@ describe('RecipeCreatePage', () => {
.getByLabelText('Step 2')
.closest('.recipe-create-page__repeatable-row');

fireEvent.dragStart(firstInstructionRow!);
fireEvent.drop(secondInstructionRow!, { dataTransfer: {} });
fireEvent.pointerDown(
firstInstructionRow!.querySelector('.recipe-create-page__drag-handle')!,
{ pointerId: 4, pointerType: 'touch', button: 0 },
);
fireEvent.pointerMove(secondInstructionRow!, {
pointerId: 4,
pointerType: 'touch',
});
fireEvent.pointerUp(window, { pointerId: 4, pointerType: 'touch' });

expect(screen.getByLabelText('Step 1')).toHaveValue('Bake');
expect(screen.getByLabelText('Step 2')).toHaveValue('Mix');
Expand Down Expand Up @@ -174,6 +246,8 @@ describe('RecipeCreatePage', () => {
await user.type(screen.getByLabelText(/Servings/), '2');
await user.selectOptions(screen.getByLabelText(/Category/), 'dinner');
await user.type(screen.getByLabelText('Ingredient 1'), '200g pasta');
await user.type(screen.getByLabelText('Ingredient 1 amount'), '200');
await user.selectOptions(screen.getByLabelText('Ingredient 1 unit'), 'g');
await user.type(screen.getByLabelText('Step 1'), 'Boil the pasta.');
await user.click(screen.getByRole('button', { name: 'Publish recipe' }));

Expand Down
Loading