Skip to content

Commit

Permalink
Merge pull request #9 from lizaklimova/add-recipe
Browse files Browse the repository at this point in the history
Add recipe
  • Loading branch information
lizaklimova authored Jan 15, 2024
2 parents bbb8db4 + b14045e commit a458ad9
Show file tree
Hide file tree
Showing 18 changed files with 145 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import styled from 'styled-components';
33 changes: 33 additions & 0 deletions src/components/AddRecipe/AddRecipeForm/AddRecipeForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import RecipeDescriptionFields from 'components/AddRecipe/RecipeDescriptionFields';
import RecipeIngredientsFields from 'components/AddRecipe/RecipeIngredientsFields';
import RecipePreparationFields from 'components/AddRecipe/RecipePreparationFields';
import { FC, FormEvent } from 'react';
import { useNavigate } from 'react-router-dom';

//TODO install React-Select
// містить стейт => зберігаються заповнені у формі дані
// всі поля required, валідуються. Інфа якщо значення невалідне
const AddRecipeForm: FC = () => {
const inputValues = 'test';
const navigate = useNavigate();

const handleFormSubmit = (e: FormEvent) => {
e.preventDefault();

navigate('/my');
};

return (
<form onSubmit={handleFormSubmit}>
<RecipeDescriptionFields
value={inputValues}
onSubmit={handleFormSubmit}
/>
<RecipeIngredientsFields />
<RecipePreparationFields />
<button type="submit">Add</button>
</form>
);
};

export default AddRecipeForm;
1 change: 1 addition & 0 deletions src/components/AddRecipe/AddRecipeForm/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './AddRecipeForm';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import styled from 'styled-components';
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { FC, FormEvent } from 'react';

interface RecipeDescriptionFieldsProps {
value: string;
onSubmit: (e: FormEvent, data: unknown) => void;
}

// time 5mins-120mins. Interval 5mins
// selects must have visible 6 options, other scroll
const RecipeDescriptionFields: FC<RecipeDescriptionFieldsProps> = ({
value,
onSubmit,
}) => {
return (
<div>
<input type="file" name="picture" />
<div>
<input type="text" name="title" />
<input type="text" name="about" />
<select name="category"></select>
<select name="time"></select>
<select name="" />
</div>
</div>
);
};

export default RecipeDescriptionFields;
1 change: 1 addition & 0 deletions src/components/AddRecipe/RecipeDescriptionFields/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './RecipeDescriptionFields';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import styled from 'styled-components';
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { useState } from 'react';

const RecipeIngredientsFields = () => {
const [count, setCount] = useState<number>(3);

return (
<>
<div>
<h3>Ingredients</h3>
<div>
<button
onClick={() => {
setCount(prev => prev + 1);
}}
>
-
</button>
<span>{count}</span>
<button
onClick={() => {
setCount(prev => {
if (prev === 1) return prev;
return prev - 1;
});
}}
>
+
</button>
</div>
</div>
<ul>
{/* Create Item component and map in ul */}
<li>
<select name="ingredient"></select>
<select name="weight"></select>
<button>delete</button>
</li>
</ul>
</>
);
};

export default RecipeIngredientsFields;
1 change: 1 addition & 0 deletions src/components/AddRecipe/RecipeIngredientsFields/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './RecipeIngredientsFields';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import styled from 'styled-components';
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const RecipePreparationFields = () => {
return (
<>
<h3>Recipe Preparation</h3>
<textarea name="recipe" placeholder="Enter recipe" required />
</>
);
};

export default RecipePreparationFields;
1 change: 1 addition & 0 deletions src/components/AddRecipe/RecipePreparationFields/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './RecipePreparationFields';
1 change: 1 addition & 0 deletions src/components/AddRecipe/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './AddRecipeForm';
1 change: 0 additions & 1 deletion src/components/AddRecipes/AddRecipes.styled.tsx

This file was deleted.

5 changes: 0 additions & 5 deletions src/components/AddRecipes/AddRecipes.tsx

This file was deleted.

1 change: 0 additions & 1 deletion src/components/AddRecipes/index.ts

This file was deleted.

11 changes: 11 additions & 0 deletions src/components/MainTitle/MainTitle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { FC } from 'react';

interface IMainTitleProps {
title: string;
}

const MainTitle: FC<IMainTitleProps> = ({ title }) => {
return <h2>{title}</h2>;
};

export default MainTitle;
14 changes: 11 additions & 3 deletions src/pages/AddRecipesPage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { FC } from 'react';
import AddRecipeForm from 'components/AddRecipe';
import MainTitle from 'components/MainTitle/MainTitle';

const AddRecipesPage: FC = () => {
return <div></div>;
const AddRecipesPage = () => {
return (
<>
<section>
<MainTitle title={'Add recipe'} />
<AddRecipeForm />
</section>
</>
);
};

export default AddRecipesPage;

0 comments on commit a458ad9

Please sign in to comment.