Skip to content

Commit

Permalink
Add ability to edit recipe (#273)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielkjellid authored Jun 6, 2024
1 parent d029b7d commit 0f1d6b4
Show file tree
Hide file tree
Showing 40 changed files with 1,506 additions and 897 deletions.
2 changes: 1 addition & 1 deletion frontend/apps/recipe/components/Recipe/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function Recipe({ recipe }: RecipeProps) {
<div className="lg:grid-cols-3 xl:grid-cols-5 grid grid-cols-1 gap-6 px-12">
<div className="xl:row-span-2 order-1 col-span-1">
<RecipeSection title="Ingredients">
{recipe.ingredientGroups.map((group) => (
{recipe.ingredientItemGroups.map((group) => (
<RecipeIngredientGroup key={group.id} title={group.title}>
{group.ingredientItems.map((item) => (
<RecipeIngredientGroup.Item
Expand Down
10 changes: 7 additions & 3 deletions frontend/apps/recipe/detail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ import View from '../../../components/View'
import { useCommonContext } from '../../../contexts/CommonProvider'
import { useFetch } from '../../../hooks/fetcher'
import { type RecipeDetailRecordAPIResponse, RecipeStatus } from '../../../types'
import { routes as recipesRoutes } from '../../recipes/routes'
import { urls } from '../../urls'
import { Recipe } from '../components/Recipe'

interface RecipeDetailInnerProps {
recipeId: string
results: {
recipeResponse: RecipeDetailRecordAPIResponse
}
}

function RecipeDetailInner({ results }: RecipeDetailInnerProps) {
function RecipeDetailInner({ recipeId, results }: RecipeDetailInnerProps) {
const navigate = useNavigate()
const { currentUser } = useCommonContext()
const { data: recipe } = results.recipeResponse
Expand Down Expand Up @@ -65,7 +67,9 @@ function RecipeDetailInner({ results }: RecipeDetailInnerProps) {
View in admin
</MButton>
)}
<Button onClick={() => navigate('/')}>Edit recipe</Button>
<a href={recipesRoutes.edit.build({ recipeId: recipeId })}>
<Button>Edit recipe</Button>
</a>
</div>
</div>
)}
Expand All @@ -86,7 +90,7 @@ function RecipeDetail() {
<View<object, RecipeDetailInnerProps>
component={RecipeDetailInner}
results={{ recipeResponse: recipeResponse }}
componentProps={{}}
componentProps={{ recipeId: recipeId }}
loadingProps={{ description: 'Loading recipe' }}
errorProps={{
description: 'There was an error retrieving the recipe. Please try again later.',
Expand Down
4 changes: 3 additions & 1 deletion frontend/apps/recipes/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Route, Routes } from 'react-router-dom'
import { useStrippedRoute } from '../../hooks/route'

import { RecipeCreate } from './create'
import { RecipeEdit } from './edit'
import { RecipeOverview } from './overview'
import { routes } from './routes'

Expand All @@ -12,7 +13,8 @@ export function RecipesApp() {
return (
<Routes>
<Route path={baseRoute(routes.overview.path)} element={<RecipeOverview />} />
<Route path={baseRoute(routes.createRecipe.path)} element={<RecipeCreate />} />
<Route path={baseRoute(routes.create.path)} element={<RecipeCreate />} />
<Route path={baseRoute(routes.edit.path)} element={<RecipeEdit />} />
</Routes>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import { Draggable } from 'react-beautiful-dnd'

import { type UnitOption } from '../../../../contexts/UnitsProvider'
import { type UnitRecord, type RecipeIngredientRecord } from '../../../../types'

import {
type IngredientItemGroup,
type IngredientItem,
type ActionFunc,
type IngredientGroupActions,
type FormError,
type FormErrorInner,
} from '../types'
} from './types'

interface IngredientOptionProps extends React.ComponentPropsWithoutRef<'div'> {
image?: string | null
Expand Down Expand Up @@ -105,8 +106,10 @@ function IngredientInput({
// Filter out already used ingredients in the same group.
.filter(
(ingredient) =>
(ingredientItem && ingredientItem.ingredient.id === ingredient.id) ||
!ingredientItemGroup.ingredientItems
.flatMap((ingredientItem) => ingredientItem.ingredient.id)
.filter((id) => id !== undefined)
.includes(ingredient.id)
)
.map((ingredient) => ({
Expand Down Expand Up @@ -155,7 +158,7 @@ function IngredientInput({
/>
<TextInput
label="Comment"
value={ingredientItem.additionalInfo}
value={ingredientItem.additionalInfo || ''}
placeholder="Optional comment"
onChange={(event) => handleInputChange('additionalInfo', event)}
error={!!error}
Expand Down
Loading

0 comments on commit 0f1d6b4

Please sign in to comment.