teble added for file list

This commit is contained in:
Daniel Shleifman
2021-05-31 12:44:13 +03:00
parent 618062d819
commit 1f7554489c
4 changed files with 238 additions and 101 deletions

View File

@@ -10,6 +10,7 @@
"fontsource-roboto": "^4.0.0", "fontsource-roboto": "^4.0.0",
"konva": "^8.0.1", "konva": "^8.0.1",
"material-ui-image": "^3.3.2", "material-ui-image": "^3.3.2",
"parse-torrent-title": "^1.3.0",
"react": "^17.0.2", "react": "^17.0.2",
"react-copy-to-clipboard": "^5.0.3", "react-copy-to-clipboard": "^5.0.3",
"react-dom": "^17.0.2", "react-dom": "^17.0.2",

View File

@@ -3,6 +3,7 @@ import { getPeerString, humanizeSize } from 'utils/Utils'
import { CopyToClipboard } from 'react-copy-to-clipboard' import { CopyToClipboard } from 'react-copy-to-clipboard'
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
import { Button, ButtonGroup, Typography } from '@material-ui/core' import { Button, ButtonGroup, Typography } from '@material-ui/core'
import ptt from 'parse-torrent-title'
import { import {
ArrowDownward as ArrowDownwardIcon, ArrowDownward as ArrowDownwardIcon,
ArrowUpward as ArrowUpwardIcon, ArrowUpward as ArrowUpwardIcon,
@@ -26,17 +27,18 @@ import {
SectionTitle, SectionTitle,
SectionSubName, SectionSubName,
StatisticsWrapper, StatisticsWrapper,
ButtonSection,
LoadingProgress, LoadingProgress,
SectionHeader, SectionHeader,
CacheSection, CacheSection,
ButtonSectionButton,
TorrentFilesSection, TorrentFilesSection,
Divider, Divider,
SmallLabel, SmallLabel,
Table,
} from './style' } from './style'
import StatisticsField from './StatisticsField' import StatisticsField from './StatisticsField'
ptt.addHandler('part', /Part[. ]([0-9])/i, { type: 'integer' })
const shortenText = (text, count) => text.slice(0, count) + (text.length > count ? '...' : '') const shortenText = (text, count) => text.slice(0, count) + (text.length > count ? '...' : '')
export default function DialogTorrentDetailsContent({ closeDialog, torrent }) { export default function DialogTorrentDetailsContent({ closeDialog, torrent }) {
@@ -45,6 +47,11 @@ export default function DialogTorrentDetailsContent({ closeDialog, torrent }) {
const [viewedFileList, setViewedFileList] = useState() const [viewedFileList, setViewedFileList] = useState()
const [playableFileList, setPlayableFileList] = useState() const [playableFileList, setPlayableFileList] = useState()
const isOnlyOnePlayableFile = playableFileList?.length === 1
const latestViewedFileId = viewedFileList?.[viewedFileList?.length - 1]
const latestViewedFile = playableFileList?.find(({ id }) => id === latestViewedFileId)?.path
const latestViewedFileData = latestViewedFile && ptt.parse(latestViewedFile)
const { const {
poster, poster,
hash, hash,
@@ -87,7 +94,7 @@ export default function DialogTorrentDetailsContent({ closeDialog, torrent }) {
// getting viewed file list // getting viewed file list
axios.post(viewedHost(), { action: 'list', hash }).then(({ data }) => { axios.post(viewedHost(), { action: 'list', hash }).then(({ data }) => {
if (data) { if (data) {
const lst = data.map(itm => itm.file_index) const lst = data.map(itm => itm.file_index).sort((a, b) => a - b)
setViewedFileList(lst) setViewedFileList(lst)
} else setViewedFileList() } else setViewedFileList()
}) })
@@ -148,43 +155,70 @@ export default function DialogTorrentDetailsContent({ closeDialog, torrent }) {
<StatisticsField <StatisticsField
title='Peers' title='Peers'
value={getPeerString(torrent)} value={getPeerString(torrent)}
iconBg='#0146ad' iconBg='#cdc118'
valueBg='#0058db' valueBg='#d8cb18'
icon={SwapVerticalCircleIcon} icon={SwapVerticalCircleIcon}
/> />
<StatisticsField <StatisticsField
title='Torrent size' title='Torrent size'
value={humanizeSize(torrentSize)} value={humanizeSize(torrentSize)}
iconBg='#0146ad' iconBg='#9b01ad'
valueBg='#0058db' valueBg='#ac03bf'
icon={ViewAgendaIcon} icon={ViewAgendaIcon}
/> />
</StatisticsWrapper> </StatisticsWrapper>
<Divider /> <Divider />
<SmallLabel>Download Playlist</SmallLabel> {!isOnlyOnePlayableFile && !!viewedFileList?.length && (
<>
<SmallLabel>Download Playlist</SmallLabel>
<SectionSubName mb={10}>
<strong>Latest file played:</strong> {latestViewedFileData.title}.
{latestViewedFileData.season && (
<>
{' '}
Season: {latestViewedFileData.season}. Episode: {latestViewedFileData.episode}.
</>
)}
</SectionSubName>
<MainSectionButtonGroup>
<Button variant='contained' color='primary' size='large'>
full
</Button>
<Button variant='contained' color='primary' size='large'>
from latest file
</Button>
</MainSectionButtonGroup>
</>
)}
<SmallLabel mb={10}>Torrent State</SmallLabel>
<MainSectionButtonGroup> <MainSectionButtonGroup>
<Button variant='contained' color='primary' size='large'> <Button onClick={() => removeTorrentViews()} variant='contained' color='primary' size='large'>
full remove views
</Button> </Button>
<Button variant='contained' color='primary' size='large'> <Button onClick={() => dropTorrent()} variant='contained' color='primary' size='large'>
latest drop torrent
</Button> </Button>
</MainSectionButtonGroup> </MainSectionButtonGroup>
<SmallLabel>More</SmallLabel> <SmallLabel mb={10}>Info</SmallLabel>
<MainSectionButtonGroup> <MainSectionButtonGroup>
<Button variant='contained' color='primary' size='large'> {(isOnlyOnePlayableFile || !viewedFileList?.length) && (
copy hash <Button variant='contained' color='primary' size='large'>
</Button> download playlist
<Button variant='contained' color='primary' size='large'> </Button>
remove views )}
</Button> <CopyToClipboard text={hash}>
<Button variant='contained' color='primary' size='large'> <Button variant='contained' color='primary' size='large'>
drop torrent copy hash
</Button> </Button>
</CopyToClipboard>
</MainSectionButtonGroup> </MainSectionButtonGroup>
{/* <MainSectionButtonGroup> {/* <MainSectionButtonGroup>
@@ -232,47 +266,116 @@ export default function DialogTorrentDetailsContent({ closeDialog, torrent }) {
</Button> </Button>
</CacheSection> </CacheSection>
<ButtonSection>
<CopyToClipboard text={hash}>
<ButtonSectionButton>
<div className='hash-group'>
<div>copy hash</div>
<div className='hash-text'>{hash}</div>
</div>
</ButtonSectionButton>
</CopyToClipboard>
<ButtonSectionButton onClick={() => removeTorrentViews()}>remove views</ButtonSectionButton>
<ButtonSectionButton onClick={() => dropTorrent()}>drop torrent</ButtonSectionButton>
<ButtonSectionButton>download full playlist</ButtonSectionButton>
<ButtonSectionButton>download playlist after last view</ButtonSectionButton>
</ButtonSection>
<TorrentFilesSection> <TorrentFilesSection>
<SectionTitle mb={20}>Torrent Content</SectionTitle> <SectionTitle mb={20}>Torrent Content</SectionTitle>
<Table>
<thead>
<tr>
<th style={{ width: '0' }}>viewed</th>
<th>name</th>
<th style={{ width: '0' }}>season</th>
<th style={{ width: '0' }}>episode</th>
<th style={{ width: '0' }}>resolution</th>
<th style={{ width: '100px' }}>size</th>
<th style={{ width: '400px' }}>actions</th>
</tr>
</thead>
<tbody>
<tr className='viewed-file-row'>
<td className='viewed-file-indicator' />
<td>Jupiters Legacy</td>
<td>3</td>
<td>1</td>
<td>1080p</td>
<td>945,41 MB</td>
<td className='button-cell'>
<Button variant='outlined' color='primary' size='small'>
Preload
</Button>
<Button variant='outlined' color='primary' size='small'>
Open link
</Button>
<Button variant='outlined' color='primary' size='small'>
Copy link
</Button>
</td>
</tr>
<tr className='viewed-file-row'>
<td className='viewed-file-indicator' />
<td>Jupiters Legacy</td>
<td>3</td>
<td>2</td>
<td>1080p</td>
<td>712,47 MB</td>
<td className='button-cell'>
<Button variant='outlined' color='primary' size='small'>
Preload
</Button>
<Button variant='outlined' color='primary' size='small'>
Open link
</Button>
<Button variant='outlined' color='primary' size='small'>
Copy link
</Button>
</td>
</tr>
<tr>
<td />
<td>Jupiters Legacy</td>
<td>3</td>
<td>3</td>
<td>1080p</td>
<td>687,44 MB</td>
<td className='button-cell'>
<Button variant='outlined' color='primary' size='small'>
Preload
</Button>
<Button variant='outlined' color='primary' size='small'>
Open link
</Button>
<Button variant='outlined' color='primary' size='small'>
Copy link
</Button>
</td>
</tr>
</tbody>
</Table>
{!playableFileList?.length {!playableFileList?.length
? 'No playable files in this torrent' ? 'No playable files in this torrent'
: playableFileList.map(({ id, path, length }) => ( : playableFileList.map(({ id, path, length }) => {
<ButtonGroup key={id} disableElevation variant='contained' color='primary'> {
<Button> /* console.log(ptt.parse(path)) */
<a href={getFileLink(path, id)}> }
<Typography> {
{path.split('\\').pop().split('/').pop()} | {humanizeSize(length)}{' '} /* console.log({ title: ptt.parse(path).title })
{viewedFileList && viewedFileList?.indexOf(id) !== -1 && '| ✓'} console.log({ resolution: ptt.parse(path).resolution })
</Typography> console.log({ episode: ptt.parse(path).episode })
</a> console.log({ season: ptt.parse(path).season }) */
</Button> }
<Button onClick={() => preloadBuffer(id)}> return (
<CachedIcon /> <ButtonGroup key={id} disableElevation variant='contained' color='primary'>
<Typography>Preload</Typography> <Button>
</Button> <a href={getFileLink(path, id)}>
</ButtonGroup> <Typography>
))} {path.split('\\').pop().split('/').pop()} | {humanizeSize(length)}{' '}
{viewedFileList && viewedFileList?.indexOf(id) !== -1 && '| ✓'}
</Typography>
</a>
</Button>
<Button onClick={() => preloadBuffer(id)}>
<CachedIcon />
<Typography>Preload</Typography>
</Button>
</ButtonGroup>
)
})}
</TorrentFilesSection> </TorrentFilesSection>
</DialogContentGrid> </DialogContentGrid>
)} )}

View File

@@ -3,10 +3,9 @@ import styled, { css } from 'styled-components'
export const DialogContentGrid = styled.div` export const DialogContentGrid = styled.div`
display: grid; display: grid;
grid-template-columns: 70% 1fr; grid-template-columns: 70% 1fr;
grid-template-rows: min-content 80px min-content; grid-template-rows: repeat(2, min-content);
grid-template-areas: grid-template-areas:
'main cache' 'main cache'
'buttons buttons'
'file-list file-list'; 'file-list file-list';
` `
export const Poster = styled.div` export const Poster = styled.div`
@@ -60,48 +59,13 @@ export const CacheSection = styled.section`
display: grid; display: grid;
align-content: start; align-content: start;
grid-template-rows: min-content 1fr min-content; grid-template-rows: min-content 1fr min-content;
background: #88cdaa;
` `
export const ButtonSection = styled.section` export const TorrentFilesSection = styled.section`
grid-area: buttons;
box-shadow: 0px 4px 4px -1px rgb(0 0 0 / 30%);
display: flex;
justify-content: space-evenly;
align-items: center;
text-transform: uppercase;
`
export 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;
}
`
export const TorrentFilesSection = styled.div`
grid-area: file-list; grid-area: file-list;
padding: 40px; padding: 40px;
box-shadow: inset 3px 25px 8px -25px rgba(0, 0, 0, 0.5);
` `
export const SectionSubName = styled.div` export const SectionSubName = styled.div`
@@ -208,8 +172,72 @@ export const Divider = styled.div`
` `
export const SmallLabel = styled.div` export const SmallLabel = styled.div`
font-size: 20px; ${({ mb }) => css`
margin-bottom: 10px; ${mb && `margin-bottom: ${mb}px`};
font-weight: 300; font-size: 20px;
line-height: 1; font-weight: 300;
line-height: 1;
`}
`
export const Table = styled.table`
border-collapse: collapse;
margin: 25px 0;
font-size: 0.9em;
width: 100%;
border-radius: 5px 5px 0 0;
overflow: hidden;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.15);
thead tr {
background: #009879;
color: #fff;
text-align: left;
text-transform: uppercase;
}
th,
td {
padding: 12px 15px;
}
tbody tr {
border-bottom: 1px solid #ddd;
/* :nth-of-type(even) {
background: #f3f3f3;
} */
:last-of-type {
border-bottom: 2px solid #009879;
}
&.viewed-file-row {
color: lightgray;
background: #f3f3f3;
}
}
td {
&.viewed-file-indicator {
position: relative;
:before {
content: '';
width: 10px;
height: 10px;
background: #15d5af;
border-radius: 50%;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
}
&.button-cell {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 10px;
}
}
` `

View File

@@ -9057,6 +9057,11 @@ parse-passwd@^1.0.0:
resolved "https://registry.yarnpkg.com/parse-passwd/-/parse-passwd-1.0.0.tgz#6d5b934a456993b23d37f40a382d6f1666a8e5c6" resolved "https://registry.yarnpkg.com/parse-passwd/-/parse-passwd-1.0.0.tgz#6d5b934a456993b23d37f40a382d6f1666a8e5c6"
integrity sha1-bVuTSkVpk7I9N/QKOC1vFmao5cY= integrity sha1-bVuTSkVpk7I9N/QKOC1vFmao5cY=
parse-torrent-title@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/parse-torrent-title/-/parse-torrent-title-1.3.0.tgz#3dedea10277b17998b124a4fd67d9e190b0306b8"
integrity sha512-R5wya73/Ef0qUhb9177Ko8nRQyN1ziWD5DPnlrDrrgcchUnmIrG//cPENunvFYRZCLDZosXTKTo7TpQ2Pgbryg==
parse5@6.0.1: parse5@6.0.1:
version "6.0.1" version "6.0.1"
resolved "https://registry.yarnpkg.com/parse5/-/parse5-6.0.1.tgz#e1a1c085c569b3dc08321184f19a39cc27f7c30b" resolved "https://registry.yarnpkg.com/parse5/-/parse5-6.0.1.tgz#e1a1c085c569b3dc08321184f19a39cc27f7c30b"