mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 21:46:11 +05:00
closing add dialog when torrent successfully added in DB
This commit is contained in:
@@ -42,19 +42,33 @@ export default function AddDialog({
|
|||||||
const [currentLang] = useChangeLanguage()
|
const [currentLang] = useChangeLanguage()
|
||||||
const [selectedFile, setSelectedFile] = useState()
|
const [selectedFile, setSelectedFile] = useState()
|
||||||
const [posterSearchLanguage, setPosterSearchLanguage] = useState(currentLang === 'ru' ? 'ru' : 'en')
|
const [posterSearchLanguage, setPosterSearchLanguage] = useState(currentLang === 'ru' ? 'ru' : 'en')
|
||||||
const [isLoadingButton, setIsLoadingButton] = useState(false)
|
const [isSaving, setIsSaving] = useState(false)
|
||||||
const [skipDebounce, setSkipDebounce] = useState(false)
|
const [skipDebounce, setSkipDebounce] = useState(false)
|
||||||
const [isCustomTitleEnabled, setIsCustomTitleEnabled] = useState(false)
|
const [isCustomTitleEnabled, setIsCustomTitleEnabled] = useState(false)
|
||||||
|
const [currentSourceHash, setCurrentSourceHash] = useState()
|
||||||
|
|
||||||
const { data: torrents } = useQuery('torrents', getTorrents, { retry: 1, refetchInterval: 1000 })
|
const { data: torrents } = useQuery('torrents', getTorrents, { retry: 1, refetchInterval: 1000 })
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const allHashes = torrents.map(({ hash }) => hash)
|
// getting hash from added torrent source
|
||||||
|
parseTorrent.remote(selectedFile || torrentSource, (_, { infoHash } = {}) => setCurrentSourceHash(infoHash))
|
||||||
|
}, [selectedFile, torrentSource])
|
||||||
|
|
||||||
parseTorrent.remote(selectedFile || torrentSource, (err, { infoHash } = {}) => {
|
useEffect(() => {
|
||||||
setIsHashAlreadyExists(allHashes.includes(infoHash))
|
// checking if torrent already exists in DB
|
||||||
})
|
if (!setCurrentSourceHash) return
|
||||||
}, [selectedFile, torrentSource, torrents])
|
|
||||||
|
const allHashes = torrents.map(({ hash }) => hash)
|
||||||
|
setIsHashAlreadyExists(allHashes.includes(currentSourceHash))
|
||||||
|
}, [currentSourceHash, torrents])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// closing dialog when torrent successfully added in DB
|
||||||
|
if (!isSaving) return
|
||||||
|
|
||||||
|
const allHashes = torrents.map(({ hash }) => hash)
|
||||||
|
allHashes.includes(currentSourceHash) && handleClose()
|
||||||
|
}, [isSaving, torrents, currentSourceHash, handleClose])
|
||||||
|
|
||||||
const fullScreen = useMediaQuery('@media (max-width:930px)')
|
const fullScreen = useMediaQuery('@media (max-width:930px)')
|
||||||
|
|
||||||
@@ -179,7 +193,7 @@ export default function AddDialog({
|
|||||||
])
|
])
|
||||||
|
|
||||||
const handleSave = () => {
|
const handleSave = () => {
|
||||||
setIsLoadingButton(true)
|
setIsSaving(true)
|
||||||
|
|
||||||
if (isEditMode) {
|
if (isEditMode) {
|
||||||
axios
|
axios
|
||||||
@@ -197,12 +211,12 @@ export default function AddDialog({
|
|||||||
data.append('file', selectedFile)
|
data.append('file', selectedFile)
|
||||||
title && data.append('title', title)
|
title && data.append('title', title)
|
||||||
posterUrl && data.append('poster', posterUrl)
|
posterUrl && data.append('poster', posterUrl)
|
||||||
axios.post(torrentUploadHost(), data).finally(handleClose)
|
axios.post(torrentUploadHost(), data).catch(handleClose)
|
||||||
} else {
|
} else {
|
||||||
// link save
|
// link save
|
||||||
axios
|
axios
|
||||||
.post(torrentsHost(), { action: 'add', link: torrentSource, title, poster: posterUrl, save_to_db: true })
|
.post(torrentsHost(), { action: 'add', link: torrentSource, title, poster: posterUrl, save_to_db: true })
|
||||||
.finally(handleClose)
|
.catch(handleClose)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,11 +282,7 @@ export default function AddDialog({
|
|||||||
onClick={handleSave}
|
onClick={handleSave}
|
||||||
color='primary'
|
color='primary'
|
||||||
>
|
>
|
||||||
{isLoadingButton ? (
|
{isSaving ? <CircularProgress style={{ color: 'white' }} size={20} /> : t(isEditMode ? 'Save' : 'Add')}
|
||||||
<CircularProgress style={{ color: 'white' }} size={20} />
|
|
||||||
) : (
|
|
||||||
t(isEditMode ? 'Save' : 'Add')
|
|
||||||
)}
|
|
||||||
</Button>
|
</Button>
|
||||||
</ButtonWrapper>
|
</ButtonWrapper>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
|
|||||||
Reference in New Issue
Block a user