name and title has new function for parsing

This commit is contained in:
Daniel Shleifman
2021-06-15 00:24:11 +03:00
parent 8f414e88cb
commit b6fc8c0afb
3 changed files with 33 additions and 15 deletions

View File

@@ -15,7 +15,13 @@ import { ButtonWrapper, Content, Header } from './style'
import RightSideComponent from './RightSideComponent' import RightSideComponent from './RightSideComponent'
import LeftSideComponent from './LeftSideComponent' import LeftSideComponent from './LeftSideComponent'
export default function AddDialog({ handleClose, hash: originalHash, title: originalTitle, poster: originalPoster }) { export default function AddDialog({
handleClose,
hash: originalHash,
title: originalTitle,
name: originalName,
poster: originalPoster,
}) {
const { t } = useTranslation() const { t } = useTranslation()
const [torrentSource, setTorrentSource] = useState(originalHash || '') const [torrentSource, setTorrentSource] = useState(originalHash || '')
const [title, setTitle] = useState(originalTitle || '') const [title, setTitle] = useState(originalTitle || '')
@@ -110,7 +116,7 @@ export default function AddDialog({ handleClose, hash: originalHash, title: orig
posterSearch(title, posterSearchLanguage) posterSearch(title, posterSearchLanguage)
setSkipDebounce(false) setSkipDebounce(false)
} else { } else {
delayedPosterSearch(title, posterSearchLanguage) title === '' ? removePoster() : delayedPosterSearch(title, posterSearchLanguage)
} }
}, [title, prevTitleState, delayedPosterSearch, posterSearch, posterSearchLanguage, skipDebounce]) }, [title, prevTitleState, delayedPosterSearch, posterSearch, posterSearchLanguage, skipDebounce])
@@ -132,7 +138,14 @@ export default function AddDialog({ handleClose, hash: originalHash, title: orig
setIsLoadingButton(true) setIsLoadingButton(true)
if (isEditMode) { if (isEditMode) {
axios.post(torrentsHost(), { action: 'set', hash: originalHash, title, poster: posterUrl }).finally(handleClose) axios
.post(torrentsHost(), {
action: 'set',
hash: originalHash,
title: title === '' ? originalName : title,
poster: posterUrl,
})
.finally(handleClose)
} else if (selectedFile) { } else if (selectedFile) {
// file save // file save
const data = new FormData() const data = new FormData()

View File

@@ -100,17 +100,20 @@ export default function DialogTorrentDetailsContent({ closeDialog, torrent }) {
}, [hash]) }, [hash])
const bufferSize = settings?.PreloadBuffer ? Capacity : 33554432 // Default is 32mb if PreloadBuffer is false const bufferSize = settings?.PreloadBuffer ? Capacity : 33554432 // Default is 32mb if PreloadBuffer is false
// const bufferSize = Capacity
const getTitle = value => { const getParsedTitle = () => {
const torrentParsedName = value && ptt.parse(value)
const newNameStrings = [] const newNameStrings = []
if (torrentParsedName?.title) newNameStrings.push(` ${torrentParsedName?.title}`) const torrentParsedName = name && ptt.parse(name)
if (torrentParsedName?.year) newNameStrings.push(`. ${torrentParsedName?.year}.`)
if (torrentParsedName?.resolution) newNameStrings.push(` (${torrentParsedName?.resolution})`)
return newNameStrings.join(' ') if (title !== name) {
newNameStrings.push(title)
} else if (torrentParsedName?.title) newNameStrings.push(torrentParsedName?.title)
if (torrentParsedName?.year) newNameStrings.push(torrentParsedName?.year)
if (torrentParsedName?.resolution) newNameStrings.push(torrentParsedName?.resolution)
return newNameStrings.join('. ')
} }
return ( return (
@@ -141,13 +144,13 @@ export default function DialogTorrentDetailsContent({ closeDialog, torrent }) {
<Poster poster={poster}>{poster ? <img alt='poster' src={poster} /> : <NoImageIcon />}</Poster> <Poster poster={poster}>{poster ? <img alt='poster' src={poster} /> : <NoImageIcon />}</Poster>
<div> <div>
{name && name !== title ? ( {title && name !== title ? (
<> <>
<SectionTitle>{shortenText(getTitle(name), 50)}</SectionTitle> <SectionTitle>{shortenText(getParsedTitle(), 55)}</SectionTitle>
<SectionSubName mb={20}>{shortenText(title, 160)}</SectionSubName> <SectionSubName mb={20}>{shortenText(ptt.parse(name).title, 110)}</SectionSubName>
</> </>
) : ( ) : (
<SectionTitle mb={20}>{shortenText(getTitle(title), 50)}</SectionTitle> <SectionTitle mb={20}>{shortenText(getParsedTitle(), 55)}</SectionTitle>
)} )}
<WidgetWrapper> <WidgetWrapper>

View File

@@ -134,7 +134,9 @@ const Torrent = ({ torrent }) => {
</DialogActions> </DialogActions>
</Dialog> </Dialog>
{isEditDialogOpen && <AddDialog hash={hash} title={title} poster={poster} handleClose={handleCloseEditDialog} />} {isEditDialogOpen && (
<AddDialog hash={hash} title={title} name={name} poster={poster} handleClose={handleCloseEditDialog} />
)}
</> </>
) )
} }