├── .gitignore ├── README.md ├── data └── db.json ├── package-lock.json ├── package.json ├── public └── index.html └── src ├── App.css ├── App.js ├── assets └── mode_icon.svg ├── components ├── Navbar.css ├── Navbar.js ├── RecipeList.css ├── RecipeList.js ├── Sarchbar.css ├── Searchbar.js ├── ThemeSelector.css └── ThemeSelector.js ├── context └── useThemContext.js ├── firebase └── config.js ├── hooks ├── useFetch.js └── useTheme.js ├── index.css ├── index.js └── pages ├── create ├── Create.css └── Create.js ├── home ├── Home.css └── Home.js ├── recipe ├── Recipe.css └── Recipe.js └── search ├── Search.css └── Search.js /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `npm start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in your browser. 13 | 14 | The page will reload when you make changes.\ 15 | You may also see any lint errors in the console. 16 | 17 | ### `npm test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `npm run build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `npm run eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can't go back!** 35 | 36 | If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own. 39 | 40 | You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | 48 | ### Code Splitting 49 | 50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) 51 | 52 | ### Analyzing the Bundle Size 53 | 54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) 55 | 56 | ### Making a Progressive Web App 57 | 58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) 59 | 60 | ### Advanced Configuration 61 | 62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) 63 | 64 | ### Deployment 65 | 66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) 67 | 68 | ### `npm run build` fails to minify 69 | 70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) 71 | -------------------------------------------------------------------------------- /data/db.json: -------------------------------------------------------------------------------- 1 | { 2 | "recipes": [ 3 | { 4 | "id": "1", 5 | "title": "Veggie Stew", 6 | "ingredients": [ 7 | "1 Carrot", 8 | "1 Leek", 9 | "200g Tofu", 10 | "300ml Veg stock" 11 | ], 12 | "method": "1. Pre-heat the oven to 200C/3C/gas 5. Place the carrot, leek and tofu in a large bowl. Add the stock and mix well. 2. Add the rest of the ingredients and mix well. 3. Place the mixture in a large bowl and cover with a lid. 4. Place the lid on the oven and cook for 40 minutes. 5. Serve with a slaw of your choice", 13 | "cookingTime": "45 minutes" 14 | }, 15 | { 16 | "id": "2", 17 | "title": "Veggie Pizza", 18 | "ingredients": [ 19 | "1 Base", 20 | "Tomata pasata", 21 | "1 Green pepper", 22 | "100g Mushrooms" 23 | ], 24 | "method": "1. Pre-heat the oven to 200C/3C/gas 5. Add the pasata, green pepper and mushrooms to the base. Place the lid on the oven and cook for 30 minutes. 5. Serve with a slaw of your choice", 25 | "cookingTime": "35 minutes" 26 | }, 27 | { 28 | "id": "3", 29 | "title": "Greek Salad", 30 | "ingredients": [ 31 | "1 Onion", 32 | "1 Block of Feta", 33 | "Olives", 34 | "Tomatoes", 35 | "Olive Oil" 36 | ], 37 | "method": "Lorem ipsum dolor, sit amet consectetur adipisicing elit. Esse minima ex rem quis similique eum ratione quaerat, voluptas molestias ut repudiandae delectus voluptates. Eius esse at tenetur ab accusamus excepturi?", 38 | "cookingTime": "35 minutes" 39 | }, 40 | { 41 | "title": "New Recipe", 42 | "method": "bla bla bla bla bla", 43 | "cookingTime": "45 minutes", 44 | "ingredients": [ 45 | "salt", 46 | "gruch", 47 | "non", 48 | "bodring" 49 | ], 50 | "id": "woc3kZa" 51 | }, 52 | { 53 | "title": "Hello", 54 | "method": "bla bla bla\n", 55 | "cookingTime": "15 minutes", 56 | "ingredients": [ 57 | "1", 58 | "2", 59 | "3", 60 | "4", 61 | "5" 62 | ], 63 | "id": "hrqK5ys" 64 | }, 65 | { 66 | "title": "Hello", 67 | "method": "bla bla bla\n", 68 | "cookingTime": "15 minutes", 69 | "ingredients": [ 70 | "1", 71 | "2", 72 | "3", 73 | "4", 74 | "5" 75 | ], 76 | "id": "aTTN0Bl" 77 | }, 78 | { 79 | "title": "Hello", 80 | "method": "bla bla bla\n", 81 | "cookingTime": "15 minutes", 82 | "ingredients": [ 83 | "1", 84 | "2", 85 | "3", 86 | "4", 87 | "5" 88 | ], 89 | "id": "kyY-vpj" 90 | }, 91 | { 92 | "title": "Hello", 93 | "method": "bla bla bla\n", 94 | "cookingTime": "15 minutes", 95 | "ingredients": [ 96 | "1", 97 | "2", 98 | "3", 99 | "4", 100 | "5" 101 | ], 102 | "id": "3YqULmh" 103 | }, 104 | { 105 | "title": "Hello", 106 | "method": "bla bla bla\n", 107 | "cookingTime": "15 minutes", 108 | "ingredients": [ 109 | "1", 110 | "2", 111 | "3", 112 | "4", 113 | "5" 114 | ], 115 | "id": "amjB2gr" 116 | }, 117 | { 118 | "title": "Osh", 119 | "method": "hello world", 120 | "cookingTime": "9 minutes", 121 | "ingredients": [ 122 | "1", 123 | "2", 124 | "3", 125 | "4", 126 | "5" 127 | ], 128 | "id": "PQ-Ea-A" 129 | }, 130 | { 131 | "title": "Osh", 132 | "method": "hello world", 133 | "cookingTime": "9 minutes", 134 | "ingredients": [ 135 | "1", 136 | "2", 137 | "3", 138 | "4", 139 | "5" 140 | ], 141 | "id": "FksTpOd" 142 | }, 143 | { 144 | "title": "1", 145 | "method": "1", 146 | "cookingTime": "11111 minutes", 147 | "ingredients": [ 148 | "1" 149 | ], 150 | "id": "gmX4TK3" 151 | }, 152 | { 153 | "title": "22", 154 | "method": "22212", 155 | "cookingTime": "2112 minutes", 156 | "ingredients": [ 157 | "222" 158 | ], 159 | "id": "JXaPXnw" 160 | } 161 | ] 162 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "akhror-kitchen-app", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.16.4", 7 | "@testing-library/react": "^13.2.0", 8 | "@testing-library/user-event": "^13.5.0", 9 | "firebase": "8.5", 10 | "react": "^18.1.0", 11 | "react-dom": "^18.1.0", 12 | "react-router-dom": "^6.3.0", 13 | "react-scripts": "5.0.1", 14 | "web-vitals": "^2.1.4" 15 | }, 16 | "scripts": { 17 | "start": "react-scripts start", 18 | "build": "react-scripts build", 19 | "test": "react-scripts test", 20 | "eject": "react-scripts eject" 21 | }, 22 | "eslintConfig": { 23 | "extends": [ 24 | "react-app", 25 | "react-app/jest" 26 | ] 27 | }, 28 | "browserslist": { 29 | "production": [ 30 | ">0.2%", 31 | "not dead", 32 | "not op_mini all" 33 | ], 34 | "development": [ 35 | "last 1 chrome version", 36 | "last 1 firefox version", 37 | "last 1 safari version" 38 | ] 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 11 | React App 12 | 13 | 14 | 15 |
16 | 17 | 18 | -------------------------------------------------------------------------------- /src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | min-height: 100%; 3 | transition: 0.5s; 4 | } 5 | 6 | .App.dark { 7 | background: #333; 8 | } 9 | -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import { BrowserRouter as Router, Route, Routes } from 'react-router-dom' 2 | 3 | // styles 4 | import './App.css' 5 | 6 | // pages components 7 | import Navbar from './components/Navbar' 8 | import Home from './pages/home/Home' 9 | import Recipe from './pages/recipe/Recipe' 10 | import Create from './pages/create/Create' 11 | import Search from './pages/search/Search' 12 | import ThemeSelector from './components/ThemeSelector' 13 | import { useTheme } from './hooks/useTheme' 14 | 15 | function App() { 16 | const { mode } = useTheme() 17 | return ( 18 |
19 | 20 | 21 | 22 | 23 | } /> 24 | } /> 25 | } /> 26 | } /> 27 | 28 | 29 |
30 | ) 31 | } 32 | 33 | export default App 34 | -------------------------------------------------------------------------------- /src/assets/mode_icon.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/components/Navbar.css: -------------------------------------------------------------------------------- 1 | .navbar { 2 | background: #58249c; 3 | padding: 20px; 4 | color: #fff; 5 | transition: 0.5s; 6 | } 7 | .navbar nav { 8 | display: flex; 9 | align-items: center; 10 | max-width: 1200px; 11 | margin: 0 auto; 12 | } 13 | .navbar a.brand { 14 | margin-right: auto; 15 | color: #fff; 16 | text-decoration: none; 17 | } 18 | .navbar a:last-child { 19 | color: #fff; 20 | text-decoration: none; 21 | margin-left: 40px; 22 | padding: 8px; 23 | border: 1px solid #fff; 24 | border-radius: 4px; 25 | } 26 | .navbar a:last-child:hover { 27 | background: #fff; 28 | color: #333; 29 | } 30 | -------------------------------------------------------------------------------- /src/components/Navbar.js: -------------------------------------------------------------------------------- 1 | // styles 2 | import { Link } from 'react-router-dom' 3 | import './Navbar.css' 4 | import { useTheme } from '../hooks/useTheme' 5 | 6 | function Navbar() { 7 | const { color } = useTheme() 8 | 9 | return ( 10 |
11 | 17 |
18 | ) 19 | } 20 | 21 | export default Navbar 22 | -------------------------------------------------------------------------------- /src/components/RecipeList.css: -------------------------------------------------------------------------------- 1 | .recipe-list { 2 | display: grid; 3 | grid-template-columns: 1fr 1fr 1fr; 4 | grid-gap: 40px; 5 | max-width: 1200px; 6 | margin: 40px auto; 7 | } 8 | .recipe-list .card { 9 | background: #fff; 10 | color: #333; 11 | padding: 20px; 12 | border-radius: 4px; 13 | box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.05); 14 | transition: all 0.3s ease; 15 | position: relative; 16 | } 17 | .recipe-list .card:hover { 18 | transform: rotate(3deg); 19 | } 20 | .recipe-list .card h3 { 21 | color: #555; 22 | margin-bottom: 6px; 23 | } 24 | .recipe-list .card p { 25 | color: #999; 26 | font-size: 0.9em; 27 | } 28 | .recipe-list .card div { 29 | color: #555; 30 | font-size: 0.7em; 31 | margin: 20px 0; 32 | line-height: 1.5em; 33 | } 34 | .recipe-list .card a { 35 | color: #555; 36 | text-decoration: none; 37 | display: block; 38 | background: #e2e2e2; 39 | font-size: 0.9em; 40 | width: 100px; 41 | text-align: center; 42 | width: 120px; 43 | padding: 8px; 44 | border-radius: 4px; 45 | margin: 20px auto 0; 46 | } 47 | .delete { 48 | position: absolute; 49 | top: 10px; 50 | right: 10px; 51 | cursor: pointer; 52 | filter: invert(60%); 53 | } 54 | 55 | /* dark mode */ 56 | .recipe-list .card.dark { 57 | background: #555; 58 | } 59 | .recipe-list .card.dark p, 60 | .recipe-list .card.dark h3, 61 | .recipe-list .card.dark div { 62 | color: #e4e4e4; 63 | } 64 | -------------------------------------------------------------------------------- /src/components/RecipeList.js: -------------------------------------------------------------------------------- 1 | // styles 2 | import './RecipeList.css' 3 | import { Link } from 'react-router-dom' 4 | import { useTheme } from '../hooks/useTheme' 5 | 6 | function RecipeList({ data }) { 7 | const { mode } = useTheme() 8 | 9 | return ( 10 |
11 | {data.map((recipe) => { 12 | return ( 13 |
14 |

{recipe.title}

15 |

{recipe.cookingTime} to make.

16 |
{recipe.method.substring(0, 100)}...
17 | Read More 18 |
19 | ) 20 | })} 21 |
22 | ) 23 | } 24 | 25 | export default RecipeList 26 | -------------------------------------------------------------------------------- /src/components/Sarchbar.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AkhrorSoliev/mykitechen-react-firebase/2201a696a857edcc33556c9e91cb2bb94ef15f1c/src/components/Sarchbar.css -------------------------------------------------------------------------------- /src/components/Searchbar.js: -------------------------------------------------------------------------------- 1 | // styles 2 | import './Sarchbar.css' 3 | 4 | function Searchbar() { 5 | return
Searchbar
6 | } 7 | 8 | export default Searchbar 9 | -------------------------------------------------------------------------------- /src/components/ThemeSelector.css: -------------------------------------------------------------------------------- 1 | .theme-selector { 2 | display: flex; 3 | justify-content: flex-end; 4 | align-items: center; 5 | max-width: 1200px; 6 | margin: 20px auto; 7 | } 8 | .theme-buttons div { 9 | display: inline-block; 10 | width: 20px; 11 | height: 20px; 12 | cursor: pointer; 13 | margin-left: 15px; 14 | border-radius: 50%; 15 | } 16 | 17 | .mode-toggle { 18 | display: inline-block; 19 | margin-right: auto; 20 | } 21 | 22 | .mode-toggle img { 23 | height: 35px; 24 | width: 35px; 25 | cursor: pointer; 26 | /* filter: invert(100%); */ 27 | } 28 | -------------------------------------------------------------------------------- /src/components/ThemeSelector.js: -------------------------------------------------------------------------------- 1 | // styles 2 | import './ThemeSelector.css' 3 | import { useTheme } from '../hooks/useTheme' 4 | import ModeIcon from '../assets/mode_icon.svg' 5 | 6 | const navThemeColors = ['#A91079', '#646FD4', '#F8B400'] 7 | 8 | function ThemeSelector() { 9 | const { changeNavColor, changeMode, mode } = useTheme() 10 | 11 | const toggleMode = () => { 12 | changeMode(mode === 'dark' ? 'light' : 'dark') 13 | } 14 | console.log(mode) 15 | 16 | return ( 17 |
18 |
19 | Mode Icon 29 |
30 |
31 | {navThemeColors.map((color) => ( 32 |
{ 35 | changeNavColor(color) 36 | }} 37 | style={{ background: color }} 38 | >
39 | ))} 40 |
41 |
42 | ) 43 | } 44 | 45 | export default ThemeSelector 46 | -------------------------------------------------------------------------------- /src/context/useThemContext.js: -------------------------------------------------------------------------------- 1 | import { createContext, useReducer } from 'react' 2 | 3 | export const ThemeContext = createContext() 4 | 5 | const changeColor = (state, action) => { 6 | switch (action.type) { 7 | case 'CHANGE_COLOR': 8 | return { ...state, color: action.payload } 9 | case 'CHANGE_MODE': 10 | return { ...state, mode: action.payload } 11 | default: 12 | return state 13 | } 14 | } 15 | 16 | export function ThemeProvider({ children }) { 17 | const [state, dispatch] = useReducer(changeColor, { 18 | color: 'black', 19 | mode: 'ligth', 20 | }) 21 | 22 | const changeNavColor = (color) => { 23 | dispatch({ type: 'CHANGE_COLOR', payload: color }) 24 | } 25 | 26 | const changeMode = (mode) => { 27 | dispatch({ type: 'CHANGE_MODE', payload: mode }) 28 | } 29 | 30 | return ( 31 | 32 | {children} 33 | 34 | ) 35 | } 36 | -------------------------------------------------------------------------------- /src/firebase/config.js: -------------------------------------------------------------------------------- 1 | import firebase from 'firebase' 2 | import 'firebase/firestore' 3 | 4 | // For Firebase JS SDK v7.20.0 and later, measurementId is optional 5 | const firebaseConfig = { 6 | apiKey: 'AIzaSyCZpdemKBDW4Jen5mrygQ7It_Mdzu-eWIY', 7 | authDomain: 'my-kitchen-464c5.firebaseapp.com', 8 | projectId: 'my-kitchen-464c5', 9 | storageBucket: 'my-kitchen-464c5.appspot.com', 10 | messagingSenderId: '154849546877', 11 | appId: '1:154849546877:web:3d1d28f50447bdfdee5714', 12 | measurementId: 'G-7S4BT3SGW1', 13 | } 14 | 15 | // init configs 16 | 17 | firebase.initializeApp(firebaseConfig) 18 | 19 | const projectFirstore = firebase.firestore() 20 | 21 | export { projectFirstore } 22 | -------------------------------------------------------------------------------- /src/hooks/useFetch.js: -------------------------------------------------------------------------------- 1 | import { useState, useEffect } from 'react' 2 | 3 | export const useFetch = (url, method = 'GET') => { 4 | const [data, setData] = useState(null) 5 | const [isPending, setIsPending] = useState(false) 6 | const [error, setError] = useState(null) 7 | const [options, setOptions] = useState(null) 8 | 9 | const postData = (postData) => { 10 | console.log(postData) 11 | setOptions({ 12 | method: 'POST', 13 | headers: { 14 | 'Content-Type': 'application/json', 15 | }, 16 | body: JSON.stringify(postData), 17 | }) 18 | } 19 | 20 | useEffect(() => { 21 | const controller = new AbortController() 22 | 23 | const fetchData = async (fetchOptions) => { 24 | setIsPending(true) 25 | 26 | try { 27 | const res = await fetch(url, { 28 | ...fetchOptions, 29 | signal: controller.signal, 30 | }) 31 | if (!res.ok) { 32 | throw new Error(res.statusText) 33 | } 34 | const data = await res.json() 35 | 36 | setIsPending(false) 37 | setData(data) 38 | setError(null) 39 | } catch (err) { 40 | if (err.name === 'AbortError') { 41 | console.log('the fetch was aborted') 42 | } else { 43 | setIsPending(false) 44 | setError('Could not fetch the data') 45 | } 46 | } 47 | } 48 | 49 | if (method === 'GET') { 50 | fetchData() 51 | } 52 | 53 | if (method === 'POST' && options) { 54 | fetchData(options) 55 | } 56 | 57 | return () => { 58 | controller.abort() 59 | } 60 | }, [url, method, options]) 61 | 62 | return { data, isPending, error, postData } 63 | } 64 | -------------------------------------------------------------------------------- /src/hooks/useTheme.js: -------------------------------------------------------------------------------- 1 | import { useContext } from 'react' 2 | import { ThemeContext } from '../context/useThemContext' 3 | 4 | export function useTheme() { 5 | const context = useContext(ThemeContext) 6 | 7 | if (!context) { 8 | throw new Error('useContext() must be use in ThemeContext Provider') 9 | } 10 | 11 | return context 12 | } 13 | -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | @import url('https://fonts.googleapis.com/css2?family=Raleway:wght@100;200;300;400;500;600;700;800&display=swap'); 2 | 3 | /* base styles */ 4 | html, 5 | body, 6 | #root { 7 | height: 100%; 8 | } 9 | body { 10 | font-family: Raleway, sans-serif; 11 | margin: 0; 12 | font-size: 1.4em; 13 | background: #dfdfdf; 14 | color: #333; 15 | } 16 | h1, 17 | h2, 18 | h3, 19 | p { 20 | margin: 0; 21 | } 22 | input, 23 | textarea { 24 | color: #333; 25 | padding: 8px; 26 | font-size: 1em; 27 | border-radius: 4px; 28 | border: 1px solid #d4d4d4; 29 | background-color: #fff; 30 | display: block; 31 | width: 100%; 32 | box-sizing: border-box; 33 | } 34 | .page-title { 35 | text-align: center; 36 | margin: 40px auto; 37 | color: #333; 38 | } 39 | .loading, 40 | .error { 41 | text-align: center; 42 | margin: 40px auto; 43 | } 44 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import ReactDOM from 'react-dom/client' 3 | import './index.css' 4 | import App from './App' 5 | import { ThemeProvider } from './context/useThemContext' 6 | 7 | const root = ReactDOM.createRoot(document.getElementById('root')) 8 | root.render( 9 | 10 | 11 | 12 | 13 | , 14 | ) 15 | -------------------------------------------------------------------------------- /src/pages/create/Create.css: -------------------------------------------------------------------------------- 1 | .create { 2 | color: #555; 3 | max-width: 480px; 4 | margin: 60px auto; 5 | } 6 | .create label span { 7 | display: block; 8 | margin: 30px 0 10px; 9 | } 10 | .create p { 11 | margin-top: 10px; 12 | font-size: 0.8em; 13 | } 14 | .create button { 15 | display: block; 16 | width: 100px; 17 | font-size: 1em; 18 | color: #fff; 19 | padding: 8px 20px; 20 | border: 0; 21 | border-radius: 4px; 22 | background-color: #58249c; 23 | cursor: pointer; 24 | text-decoration: none; 25 | margin: 20px auto; 26 | } 27 | .ingredients { 28 | display: flex; 29 | align-items: center; 30 | } 31 | .ingredients button { 32 | margin: 0 0 0 10px; 33 | } 34 | -------------------------------------------------------------------------------- /src/pages/create/Create.js: -------------------------------------------------------------------------------- 1 | // style 2 | import './Create.css' 3 | import { useState } from 'react' 4 | import { useNavigate } from 'react-router-dom' 5 | import { projectFirstore } from '../../firebase/config' 6 | 7 | function Create() { 8 | const [title, setTitle] = useState('') 9 | const [method, setMethod] = useState('') 10 | const [cookingTime, setCookingTime] = useState('') 11 | const [newIngredient, setNewIngredient] = useState('') 12 | const [ingredients, setIngredinets] = useState([]) 13 | const navigate = useNavigate() 14 | 15 | // handleSubmit 16 | const handleSubmit = async (e) => { 17 | e.preventDefault() 18 | const doc = { 19 | title, 20 | method, 21 | cookingTime: cookingTime + ' minutes', 22 | ingredients, 23 | } 24 | try { 25 | await projectFirstore.collection('recipes').add(doc) 26 | navigate('/') 27 | } catch (err) { 28 | console.log(err) 29 | } 30 | } 31 | 32 | const addIngredients = (e) => { 33 | e.preventDefault() 34 | if (!ingredients.includes(newIngredient) && newIngredient) { 35 | const newIng = [...ingredients, newIngredient] 36 | setIngredinets(newIng) 37 | } 38 | setNewIngredient('') 39 | } 40 | 41 | return ( 42 |
43 |

Create New Recipe

44 | 54 | 55 | 68 | 69 |