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",
"konva": "^8.0.1",
"material-ui-image": "^3.3.2",
"parse-torrent-title": "^1.3.0",
"react": "^17.0.2",
"react-copy-to-clipboard": "^5.0.3",
"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 { useEffect, useState } from 'react'
import { Button, ButtonGroup, Typography } from '@material-ui/core'
import ptt from 'parse-torrent-title'
import {
ArrowDownward as ArrowDownwardIcon,
ArrowUpward as ArrowUpwardIcon,
@@ -26,17 +27,18 @@ import {
SectionTitle,
SectionSubName,
StatisticsWrapper,
ButtonSection,
LoadingProgress,
SectionHeader,
CacheSection,
ButtonSectionButton,
TorrentFilesSection,
Divider,
SmallLabel,
Table,
} from './style'
import StatisticsField from './StatisticsField'
ptt.addHandler('part', /Part[. ]([0-9])/i, { type: 'integer' })
const shortenText = (text, count) => text.slice(0, count) + (text.length > count ? '...' : '')
export default function DialogTorrentDetailsContent({ closeDialog, torrent }) {
@@ -45,6 +47,11 @@ export default function DialogTorrentDetailsContent({ closeDialog, torrent }) {
const [viewedFileList, setViewedFileList] = 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 {
poster,
hash,
@@ -87,7 +94,7 @@ export default function DialogTorrentDetailsContent({ closeDialog, torrent }) {
// getting viewed file list
axios.post(viewedHost(), { action: 'list', hash }).then(({ 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)
} else setViewedFileList()
})
@@ -148,43 +155,70 @@ export default function DialogTorrentDetailsContent({ closeDialog, torrent }) {
<StatisticsField
title='Peers'
value={getPeerString(torrent)}
iconBg='#0146ad'
valueBg='#0058db'
iconBg='#cdc118'
valueBg='#d8cb18'
icon={SwapVerticalCircleIcon}
/>
<StatisticsField
title='Torrent size'
value={humanizeSize(torrentSize)}
iconBg='#0146ad'
valueBg='#0058db'
iconBg='#9b01ad'
valueBg='#ac03bf'
icon={ViewAgendaIcon}
/>
</StatisticsWrapper>
<Divider />
{!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'>
latest
from latest file
</Button>
</MainSectionButtonGroup>
</>
)}
<SmallLabel mb={10}>Torrent State</SmallLabel>
<MainSectionButtonGroup>
<Button onClick={() => removeTorrentViews()} variant='contained' color='primary' size='large'>
remove views
</Button>
<Button onClick={() => dropTorrent()} variant='contained' color='primary' size='large'>
drop torrent
</Button>
</MainSectionButtonGroup>
<SmallLabel>More</SmallLabel>
<SmallLabel mb={10}>Info</SmallLabel>
<MainSectionButtonGroup>
{(isOnlyOnePlayableFile || !viewedFileList?.length) && (
<Button variant='contained' color='primary' size='large'>
download playlist
</Button>
)}
<CopyToClipboard text={hash}>
<Button variant='contained' color='primary' size='large'>
copy hash
</Button>
<Button variant='contained' color='primary' size='large'>
remove views
</Button>
<Button variant='contained' color='primary' size='large'>
drop torrent
</Button>
</CopyToClipboard>
</MainSectionButtonGroup>
{/* <MainSectionButtonGroup>
@@ -232,31 +266,99 @@ export default function DialogTorrentDetailsContent({ closeDialog, torrent }) {
</Button>
</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>
<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
? 'No playable files in this torrent'
: playableFileList.map(({ id, path, length }) => (
: playableFileList.map(({ id, path, length }) => {
{
/* console.log(ptt.parse(path)) */
}
{
/* console.log({ title: ptt.parse(path).title })
console.log({ resolution: ptt.parse(path).resolution })
console.log({ episode: ptt.parse(path).episode })
console.log({ season: ptt.parse(path).season }) */
}
return (
<ButtonGroup key={id} disableElevation variant='contained' color='primary'>
<Button>
<a href={getFileLink(path, id)}>
@@ -272,7 +374,8 @@ export default function DialogTorrentDetailsContent({ closeDialog, torrent }) {
<Typography>Preload</Typography>
</Button>
</ButtonGroup>
))}
)
})}
</TorrentFilesSection>
</DialogContentGrid>
)}

View File

@@ -3,10 +3,9 @@ import styled, { css } from 'styled-components'
export const DialogContentGrid = styled.div`
display: grid;
grid-template-columns: 70% 1fr;
grid-template-rows: min-content 80px min-content;
grid-template-rows: repeat(2, min-content);
grid-template-areas:
'main cache'
'buttons buttons'
'file-list file-list';
`
export const Poster = styled.div`
@@ -60,48 +59,13 @@ export const CacheSection = styled.section`
display: grid;
align-content: start;
grid-template-rows: min-content 1fr min-content;
background: #88cdaa;
`
export const ButtonSection = 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`
export const TorrentFilesSection = styled.section`
grid-area: file-list;
padding: 40px;
box-shadow: inset 3px 25px 8px -25px rgba(0, 0, 0, 0.5);
`
export const SectionSubName = styled.div`
@@ -208,8 +172,72 @@ export const Divider = styled.div`
`
export const SmallLabel = styled.div`
${({ mb }) => css`
${mb && `margin-bottom: ${mb}px`};
font-size: 20px;
margin-bottom: 10px;
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"
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:
version "6.0.1"
resolved "https://registry.yarnpkg.com/parse5/-/parse5-6.0.1.tgz#e1a1c085c569b3dc08321184f19a39cc27f7c30b"