diff --git a/web/src/components/DialogTorrentDetailsContent/StatisticsField.jsx b/web/src/components/DialogTorrentDetailsContent/StatisticsField.jsx new file mode 100644 index 0000000..7ddf8fa --- /dev/null +++ b/web/src/components/DialogTorrentDetailsContent/StatisticsField.jsx @@ -0,0 +1,14 @@ +import { StatisticsFieldWrapper, StatisticsFieldIcon, StatisticsFieldValue, StatisticsFieldTitle } from './style' + +export default function StatisticsField({ icon: Icon, title, value, iconBg, valueBg }) { + return ( + + {title} + + + + + {value} + + ) +} diff --git a/web/src/components/DialogTorrentDetailsContent/customHooks.jsx b/web/src/components/DialogTorrentDetailsContent/customHooks.jsx index aaaeead..41c0008 100644 --- a/web/src/components/DialogTorrentDetailsContent/customHooks.jsx +++ b/web/src/components/DialogTorrentDetailsContent/customHooks.jsx @@ -1,5 +1,5 @@ import { useEffect, useRef, useState } from 'react' -import { cacheHost } from 'utils/Hosts' +import { cacheHost, settingsHost } from 'utils/Hosts' import axios from 'axios' export const useUpdateCache = hash => { @@ -71,3 +71,12 @@ export const useCreateCacheMap = cache => { return cacheMap } + +export const useGetSettings = cache => { + const [settings, setSettings] = useState() + useEffect(() => { + axios.post(settingsHost(), { action: 'get' }).then(({ data }) => setSettings(data)) + }, [cache]) + + return settings +} diff --git a/web/src/components/DialogTorrentDetailsContent/index.jsx b/web/src/components/DialogTorrentDetailsContent/index.jsx index c0ef80a..b7c2c91 100644 --- a/web/src/components/DialogTorrentDetailsContent/index.jsx +++ b/web/src/components/DialogTorrentDetailsContent/index.jsx @@ -1,121 +1,34 @@ import styled, { css } from 'styled-components' import { NoImageIcon } from 'icons' import { getPeerString, humanizeSize } from 'utils/Utils' -import { viewedHost } from 'utils/Hosts' +// import { viewedHost } from 'utils/Hosts' import { CopyToClipboard } from 'react-copy-to-clipboard' import { useEffect, useState } from 'react' import { Button } from '@material-ui/core' +import { ArrowDownward, ArrowUpward, SwapVerticalCircle, ViewAgenda } from '@material-ui/icons' +import axios from 'axios' +import { torrentsHost } from 'utils/Hosts' -import { useUpdateCache, useCreateCacheMap } from './customHooks' +import { useUpdateCache, useCreateCacheMap, useGetSettings } from './customHooks' import DialogHeader from './DialogHeader' import TorrentCache from './TorrentCache' - -const DialogContentGrid = styled.div` - display: grid; - grid-template-rows: min-content min-content 80px min-content; -` -const Poster = styled.div` - ${({ poster }) => css` - height: 400px; - border-radius: 5px; - overflow: hidden; - - ${poster - ? css` - img { - border-radius: 5px; - height: 100%; - } - ` - : css` - width: 300px; - display: grid; - place-items: center; - background: #74c39c; - - svg { - transform: scale(2.5) translateY(-3px); - } - `} - `} -` -const TorrentMainSection = styled.section` - padding: 40px; - display: grid; - grid-template-columns: min-content 1fr; - gap: 30px; - background: lightgray; -` - -const TorrentData = styled.div` - > :not(:last-child) { - margin-bottom: 20px; - } -` - -const CacheSection = styled.section` - padding: 40px; - display: flex; - flex-direction: column; -` - -const ButtonSection = styled.section` - box-shadow: 0px 4px 4px -1px rgb(0 0 0 / 30%); - display: flex; - justify-content: space-evenly; - align-items: center; - text-transform: uppercase; -` - -const ButtonSectionButton = styled.div` - background: lightblue; - height: 100%; - flex: 1; - display: grid; - place-items: center; - cursor: pointer; - font-size: 15px; - - :not(:last-child) { - border-right: 1px solid blue; - } - - :hover { - background: red; - } - - .hash-group { - display: grid; - place-items: center; - } - - .hash-text { - font-size: 10px; - color: #7c7b7c; - } -` - -const TorrentFilesSection = styled.div`` - -const TorrentName = styled.div` - font-size: 50px; - font-weight: 200; - line-height: 1; -` -const TorrentSubName = styled.div` - color: #7c7b7c; -` - -const SectionTitle = styled.div` - font-size: 35px; - font-weight: 200; - line-height: 1; - margin-bottom: 20px; -` - -const DetailedTorrentCacheViewWrapper = styled.div` - padding-top: 50px; -` +import { + DetailedTorrentCacheViewWrapper, + DialogContentGrid, + TorrentMainSection, + Poster, + TorrentData, + SectionTitle, + SectionSubName, + StatisticsWrapper, + ButtonSection, + LoadingProgress, + SectionHeader, + CacheSection, + ButtonSectionButton, + TorrentFilesSection, +} from './style' +import StatisticsField from './StatisticsField' const shortenText = (text, count) => text.slice(0, count) + (text.length > count ? '...' : '') @@ -135,13 +48,22 @@ export default function DialogTorrentDetailsContent({ closeDialog, torrent }) { const cache = useUpdateCache(hash) const cacheMap = useCreateCacheMap(cache) + const settings = useGetSettings(cache) + + const dropTorrent = hash => { + axios.post(torrentsHost(), { action: 'drop', hash }).then(() => console.log('torrent dropped')) + } + + const { Capacity, PiecesCount, PiecesLength, Filled } = cache useEffect(() => { - const torrentLoaded = torrent.stat_string !== 'Torrent in db' && torrent.stat_string !== 'Torrent getting info' - torrentLoaded && isLoading && setIsLoading(false) - }, [torrent, isLoading]) + const cacheIsLoading = !Object.entries(cache).length - const { Capacity, PiecesCount, PiecesLength } = cache + if (cacheIsLoading && !isLoading) setIsLoading(true) + if (!cacheIsLoading && isLoading) setIsLoading(false) + }, [cache, isLoading]) + + const bufferSize = settings?.PreloadBuffer ? Capacity : 33554432 // Default is 32mb if PreloadBuffer is false return ( <> @@ -156,6 +78,9 @@ export default function DialogTorrentDetailsContent({ closeDialog, torrent }) { 'loading' ) : isDetailedCacheView ? ( +
PiecesCount: {PiecesCount}
+
PiecesLength: {humanizeSize(PiecesLength)}
+
status: {statString}
) : ( @@ -167,34 +92,62 @@ export default function DialogTorrentDetailsContent({ closeDialog, torrent }) {
{name && name !== title ? ( <> - {shortenText(name, 50)} - {shortenText(title, 160)} + {shortenText(name, 50)} + {shortenText(title, 160)} ) : ( - {shortenText(title, 50)} + {shortenText(title, 50)} )}
-
peers: {getPeerString(torrent)}
-
loaded: {getPreload(torrent)}
-
download speed: {humanizeSize(downloadSpeed)}
-
upload speed: {humanizeSize(uploadSpeed)}
-
status: {statString}
-
torrent size: {humanizeSize(torrentSize)}
+ + -
Capacity: {humanizeSize(Capacity)}
-
PiecesCount: {PiecesCount}
-
PiecesLength: {humanizeSize(PiecesLength)}
+ + + + + +
- Cache + + Buffer + {!settings?.PreloadBuffer && ( + Enable "Preload Buffer" in settings to change buffer size + )} + + -