mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 21:46:11 +05:00
getTorrentList fn changed to support errorCallback
This commit is contained in:
@@ -8,10 +8,10 @@
|
|||||||
> `http://192.168.78.4:8090` - correct
|
> `http://192.168.78.4:8090` - correct
|
||||||
>
|
>
|
||||||
> `http://192.168.78.4:8090/` - wrong
|
> `http://192.168.78.4:8090/` - wrong
|
||||||
3. `npm start`
|
3. `yarn start`
|
||||||
|
|
||||||
### Eslint
|
### Eslint
|
||||||
> Prettier will fix the code every time the code is saved
|
> Prettier will fix the code every time the code is saved
|
||||||
|
|
||||||
- `npm run lint` - to find all linting problems
|
- `yarn lint` - to find all linting problems
|
||||||
- `npm run fix` - to fix code
|
- `yarn fix` - to fix code
|
||||||
42969
web/package-lock.json
generated
42969
web/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -20,7 +20,7 @@
|
|||||||
"test": "react-scripts test",
|
"test": "react-scripts test",
|
||||||
"eject": "react-scripts eject",
|
"eject": "react-scripts eject",
|
||||||
"lint": "eslint --ext .js,.jsx src --color",
|
"lint": "eslint --ext .js,.jsx src --color",
|
||||||
"fix": "eslint --ext .js,.jsx src --color --fix"
|
"fix": "yarn lint --fix"
|
||||||
},
|
},
|
||||||
"browserslist": {
|
"browserslist": {
|
||||||
"production": [
|
"production": [
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ export default function AboutDialog() {
|
|||||||
|
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
<a id='alert-dialog-description'>
|
<DialogContentText id='alert-dialog-description'>
|
||||||
<center>
|
<center>
|
||||||
<h2>Thanks to everyone who tested and helped.</h2>
|
<h2>Thanks to everyone who tested and helped.</h2>
|
||||||
</center>
|
</center>
|
||||||
|
|||||||
@@ -36,13 +36,8 @@ export default function MiniDrawer() {
|
|||||||
const [isDonationDialogOpen, setIsDonationDialogOpen] = useState(false)
|
const [isDonationDialogOpen, setIsDonationDialogOpen] = useState(false)
|
||||||
const [tsVersion, setTSVersion] = useState('')
|
const [tsVersion, setTSVersion] = useState('')
|
||||||
|
|
||||||
const handleDrawerOpen = () => {
|
const handleDrawerOpen = () => setIsDrawerOpen(true)
|
||||||
setIsDrawerOpen(true)
|
const handleDrawerClose = () => setIsDrawerOpen(false)
|
||||||
}
|
|
||||||
|
|
||||||
const handleDrawerClose = () => {
|
|
||||||
setIsDrawerOpen(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetch(`${getTorrServerHost()}/echo`)
|
fetch(`${getTorrServerHost()}/echo`)
|
||||||
|
|||||||
@@ -2,8 +2,7 @@ import styled from 'styled-components'
|
|||||||
import { useEffect, useRef, useState } from 'react'
|
import { useEffect, useRef, useState } from 'react'
|
||||||
import { Typography } from '@material-ui/core'
|
import { Typography } from '@material-ui/core'
|
||||||
import { torrentsHost } from 'utils/Hosts'
|
import { torrentsHost } from 'utils/Hosts'
|
||||||
|
import Torrent from 'components/Torrent'
|
||||||
import Torrent from './Torrent'
|
|
||||||
|
|
||||||
const TorrentListWrapper = styled.div`
|
const TorrentListWrapper = styled.div`
|
||||||
display: grid;
|
display: grid;
|
||||||
@@ -20,18 +19,38 @@ const TorrentListWrapper = styled.div`
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const getTorrentList = (callback, errorCallback) => {
|
||||||
|
fetch(torrentsHost(), {
|
||||||
|
method: 'post',
|
||||||
|
body: JSON.stringify({ action: 'list' }),
|
||||||
|
headers: {
|
||||||
|
Accept: 'application/json, text/plain, */*',
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.then(res => res.json())
|
||||||
|
.then(callback)
|
||||||
|
.catch(() => errorCallback())
|
||||||
|
}
|
||||||
|
|
||||||
export default function TorrentList() {
|
export default function TorrentList() {
|
||||||
const [torrents, setTorrents] = useState([])
|
const [torrents, setTorrents] = useState([])
|
||||||
const [offline, setOffline] = useState(true)
|
const [offline, setOffline] = useState(true)
|
||||||
const timerID = useRef(-1)
|
const timerID = useRef(-1)
|
||||||
|
|
||||||
|
const updateTorrentList = torrs => {
|
||||||
|
setTorrents(torrs)
|
||||||
|
setOffline(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
const resetTorrentList = () => {
|
||||||
|
setTorrents([])
|
||||||
|
setOffline(true)
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
timerID.current = setInterval(() => {
|
timerID.current = setInterval(() => {
|
||||||
getTorrentList(torrs => {
|
getTorrentList(updateTorrentList, resetTorrentList)
|
||||||
if (torrs) setOffline(false)
|
|
||||||
else setOffline(true)
|
|
||||||
setTorrents(torrs)
|
|
||||||
})
|
|
||||||
}, 1000)
|
}, 1000)
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
@@ -43,22 +62,11 @@ export default function TorrentList() {
|
|||||||
<TorrentListWrapper>
|
<TorrentListWrapper>
|
||||||
{offline ? (
|
{offline ? (
|
||||||
<Typography>Offline</Typography>
|
<Typography>Offline</Typography>
|
||||||
|
) : !torrents.length ? (
|
||||||
|
<Typography>No torrents added</Typography>
|
||||||
) : (
|
) : (
|
||||||
torrents && torrents.map(torrent => <Torrent key={torrent.hash} torrent={torrent} />)
|
torrents && torrents.map(torrent => <Torrent key={torrent.hash} torrent={torrent} />)
|
||||||
)}
|
)}
|
||||||
</TorrentListWrapper>
|
</TorrentListWrapper>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTorrentList(callback) {
|
|
||||||
fetch(torrentsHost(), {
|
|
||||||
method: 'post',
|
|
||||||
body: JSON.stringify({ action: 'list' }),
|
|
||||||
headers: {
|
|
||||||
Accept: 'application/json, text/plain, */*',
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.then(res => res.json())
|
|
||||||
.then(callback)
|
|
||||||
}
|
|
||||||
|
|||||||
13046
web/yarn.lock
Normal file
13046
web/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user