From e4b9290f81509f5c4cbaad4266a29725ef80971f Mon Sep 17 00:00:00 2001 From: donizer Date: Wed, 11 Oct 2023 13:12:35 +0300 Subject: [PATCH] fixes --- src/components/NewMovie/NewMovie.tsx | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/components/NewMovie/NewMovie.tsx b/src/components/NewMovie/NewMovie.tsx index e2dd4f34d..3ea7efb04 100644 --- a/src/components/NewMovie/NewMovie.tsx +++ b/src/components/NewMovie/NewMovie.tsx @@ -5,15 +5,19 @@ import { Movie } from '../../types/Movie'; // eslint-disable-next-line max-len const urlPattern = /^((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=+$,\w]+@)?[A-Za-z0-9.-]+|(?:www\.|[-;:&=+$,\w]+@)[A-Za-z0-9.-]+)((?:\/[+~%/.\w-_]*)?\??(?:[-+=&;%@,.\w_]*)#?(?:[,.!/\\\w]*))?)$/; -const NewMovie: React.FC<{ onAdd: (movie: Movie) => void }> = ({ onAdd }) => { +const movieTemplate: Movie = { + title: '', + description: '', + imgUrl: '', + imdbUrl: '', + imdbId: '', +}; + +type Props = { onAdd: (movie: Movie) => void }; + +const NewMovie: React.FC = ({ onAdd }) => { const [count, setCount] = useState(0); - const [formData, setFormData] = useState({ - title: '', - description: '', - imgUrl: '', - imdbUrl: '', - imdbId: '', - }); + const [formData, setFormData] = useState(movieTemplate); const handleInputChange = (e: React.ChangeEvent) => { const { name, value } = e.target; @@ -29,6 +33,7 @@ const NewMovie: React.FC<{ onAdd: (movie: Movie) => void }> = ({ onAdd }) => { setCount(prev => prev + 1); onAdd(movie); + setFormData(movieTemplate); } };