From cb101b22ec2341a9c23516df86bf2fb315fc8d13 Mon Sep 17 00:00:00 2001 From: Ruidy Date: Wed, 31 Mar 2021 16:39:07 +0200 Subject: [PATCH] strict typing (#7) * strict=true * typing and props --- .gitignore | 3 +- TODO.md | 1 + package.json | 1 + src/App.tsx | 7 +- src/components/ContactForm.tsx | 120 ------------------ src/components/CopyrightText.tsx | 18 ++- src/components/FooterLink.tsx | 9 +- src/components/GitHubLink.tsx | 24 ++-- src/components/LogInButton.tsx | 8 +- src/components/LogOutButton.tsx | 4 +- src/components/Logo.tsx | 5 +- src/components/Navbar.tsx | 8 +- src/components/PreLoader.tsx | 30 ++--- src/components/RandomButton.tsx | 16 ++- src/components/SearchBar.tsx | 15 ++- src/components/SideNav.tsx | 9 +- src/containers/Categories/index.tsx | 2 +- src/containers/Category/index.tsx | 2 +- .../Contact/components/ContactForm.tsx | 71 +++++++++++ .../Contact/components/ContactFormInput.tsx | 35 +++++ .../components/ContactFormSubmitButton.tsx | 16 +++ .../components/ContactFormSubmitted.tsx | 13 ++ .../components/ContactFormTextArea.tsx | 28 ++++ src/containers/Contact/index.tsx | 13 +- src/containers/Home/index.tsx | 4 +- .../Meal/components/MealIngredientList.tsx | 2 +- src/containers/Meal/components/MealPage.tsx | 2 +- src/containers/Meal/index.tsx | 45 +++---- src/containers/Meal/service.ts | 27 +++- src/containers/NotFound/index.tsx | 7 +- src/containers/Profile/index.tsx | 3 +- src/index.css | 2 +- src/index.jsx | 12 +- src/layouts/MainLayout.tsx | 20 ++- src/router/AppRouter.tsx | 10 +- src/router/PrivateRoute.tsx | 18 ++- src/serviceWorker.ts | 48 +++---- src/services/Firebase/context.js | 3 +- src/services/api.ts | 32 +++-- src/types/meal.ts | 12 +- src/utils/auth_config.json | 4 - tsconfig.json | 5 +- yarn.lock | 24 +++- 43 files changed, 447 insertions(+), 291 deletions(-) delete mode 100644 src/components/ContactForm.tsx create mode 100644 src/containers/Contact/components/ContactForm.tsx create mode 100644 src/containers/Contact/components/ContactFormInput.tsx create mode 100644 src/containers/Contact/components/ContactFormSubmitButton.tsx create mode 100644 src/containers/Contact/components/ContactFormSubmitted.tsx create mode 100644 src/containers/Contact/components/ContactFormTextArea.tsx delete mode 100644 src/utils/auth_config.json diff --git a/.gitignore b/.gitignore index 705ca36..19d6a6b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ build/ node_modules/ -/.idea \ No newline at end of file +/.idea +.env \ No newline at end of file diff --git a/TODO.md b/TODO.md index 1fcf4a3..895dfe8 100644 --- a/TODO.md +++ b/TODO.md @@ -14,3 +14,4 @@ - [ ] Use Css-in-Js - [ ] Redirect to 404 - [x] Typescript +- [ ] strict typing diff --git a/package.json b/package.json index 2fcae70..212fa14 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "devDependencies": { "@types/node": "^14.14.37", "@types/react": "^17.0.3", + "@types/react-router-dom": "^5.1.7", "typescript": "^4.2.3" } } diff --git a/src/App.tsx b/src/App.tsx index a4d84be..f364926 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -5,13 +5,16 @@ import MainLayout from "./layouts/MainLayout"; import { AppRouter } from "./router"; import { Router } from "./router/Router"; import { getData } from "./services/api"; +import { MealSummary } from "./types/meal"; import { useAuth0 } from "./utils/auth0-spa"; export const App: FC = () => { const { loading } = useAuth0(); const [searchString, setSearchString] = useState(""); - const [searchResults, setSearchResults] = useState({ meals: [] }); - const [meal, setMeal] = useState(null); + const [searchResults, setSearchResults] = useState({ + meals: [] as MealSummary[], + }); + const [_, setMeal] = useState(null); const getRandomMeal = () => { getData("random", setMeal); diff --git a/src/components/ContactForm.tsx b/src/components/ContactForm.tsx deleted file mode 100644 index 0023d31..0000000 --- a/src/components/ContactForm.tsx +++ /dev/null @@ -1,120 +0,0 @@ -import React, { useState } from "react"; -// import { notificationMail, confirmationMail } from "../utils/mail"; - -export const ContactForm = ({ setIsSubmitted }) => { - const [firstName, setFirstName] = useState(""); - const [lastName, setLastName] = useState(""); - const [email, setEmail] = useState(""); - const [phone, setPhone] = useState(""); - const [message, setMessage] = useState(""); - - const handleSubmit = (e) => { - e.preventDefault(); - // confirmationMail(email); - // const body = `Sender: ${firstName} ${lastName}\nPhone: ${phone}\nMessage: ${message}`; - // notificationMail(email, `New message from ${firstName} ${lastName}`, body); - setIsSubmitted(true); - }; - - return ( -
-
-
-
- -
-
- -
-
- -
-
- -
-
- - -
-
-
-
- ); -}; - -const ContactFormInput = ({ id, type = "text", value, dispatch }) => { - const handleChange = (e) => { - e.preventDefault(); - dispatch(e.target.value); - }; - - return ( -
- {/* account_circle */} - - -
- ); -}; - -const ContactFormTextArea = ({ id, value, dispatch }) => { - const handleChange = (e) => { - e.preventDefault(); - dispatch(e.target.value); - }; - - return ( -
- -