From 1c8b5f74474702569bf29edfff40f54047638d17 Mon Sep 17 00:00:00 2001 From: Daniel Shleifman Date: Thu, 10 Jun 2021 23:06:49 +0300 Subject: [PATCH] refactor --- web/src/components/Add/AddDialog.jsx | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/web/src/components/Add/AddDialog.jsx b/web/src/components/Add/AddDialog.jsx index fd1d294..728da31 100644 --- a/web/src/components/Add/AddDialog.jsx +++ b/web/src/components/Add/AddDialog.jsx @@ -107,7 +107,7 @@ export default function AddDialog({ handleClose }) { [isUserInteractedWithPoster], ) - const delayedPosterSearch = useMemo(() => debounce(posterSearch, 2700), [posterSearch]) + const delayedPosterSearch = useMemo(() => debounce(posterSearch, 700), [posterSearch]) const prevTitleState = usePreviousState(title) const prevTorrentSourceState = usePreviousState(torrentSource) @@ -117,7 +117,7 @@ export default function AddDialog({ handleClose }) { const torrentSourceChanged = torrentSource !== prevTorrentSourceState const isCorrectSource = chechTorrentSource(torrentSource) - if (!isCorrectSource) return + if (!isCorrectSource) return setIsTorrentSourceCorrect(false) setIsTorrentSourceCorrect(true) @@ -144,12 +144,17 @@ export default function AddDialog({ handleClose }) { } }, [title, prevTitleState, delayedPosterSearch, posterSearch, posterSearchLanguage, skipDebounce]) + const removePoster = () => { + setIsPosterUrlCorrect(false) + setPosterUrl('') + } + useEffect(() => { if (!selectedFile && !torrentSource) { setTitle('') - setPosterUrl('') setPosterList() - setIsPosterUrlCorrect(false) + removePoster() + setIsUserInteractedWithPoster(false) } }, [selectedFile, torrentSource]) @@ -164,11 +169,6 @@ export default function AddDialog({ handleClose }) { const { getRootProps, getInputProps, isDragActive } = useDropzone({ onDrop: handleCapture, accept: '.torrent' }) - const removePoster = () => { - setIsPosterUrlCorrect(false) - setPosterUrl('') - } - const handleTorrentSourceChange = ({ target: { value } }) => setTorrentSource(value) const handleTitleChange = ({ target: { value } }) => setTitle(value) const handlePosterUrlChange = ({ target: { value } }) => { @@ -261,8 +261,7 @@ export default function AddDialog({ handleClose }) { - {/* */} - +