Skip to content

Commit

Permalink
Add basic recheck torrent button
Browse files Browse the repository at this point in the history
  • Loading branch information
Leapward-Koex committed May 29, 2023
1 parent 7608f50 commit f10c381
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
4 changes: 3 additions & 1 deletion components/releasePageComponents/DownloadTorrentButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type DownloadTorrentButtonProps = {
showName: string;
episodeNumber: string;
callbackId: string;
showRecheckButton: boolean;
onDownloadStatusChange: (newStatus: DownloadingStatus) => void;
onFileSizeObtained?: (fileSize: number) => void;
onDownloadProgress?: (percentage: number) => void; // 0 -> 1
Expand All @@ -51,6 +52,7 @@ export const DownloadTorrentButton = ({
showName,
episodeNumber,
callbackId,
showRecheckButton,
onDownloadStatusChange,
onFileSizeObtained,
onDownloadProgress,
Expand Down Expand Up @@ -223,7 +225,7 @@ export const DownloadTorrentButton = ({

return (
<Button mode="text" onPress={onPress}>
{`${resolution}p`}
{showRecheckButton ? 'Recheck' : `${resolution}p`}
</Button>
);
};
53 changes: 51 additions & 2 deletions components/releasePageComponents/ReleaseShow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
humanFileSize,
isCastingAvailable,
} from '../../HelperFunctions';
import { ShowInfo, WatchList } from '../../models/models';
import { ShowInfo, ShowResolution, WatchList } from '../../models/models';
import { SubsPleaseApi } from '../../ExternalApis/SubsPleaseApi';
import nodejs from 'nodejs-mobile-react-native';
import * as Progress from 'react-native-progress';
Expand Down Expand Up @@ -182,12 +182,58 @@ export const ReleaseShow = observer(
);
};

const getRecheckButton = () => {
const magnet720 = showInfo.downloads.find(
(download) => download.res === '720',
)?.magnet;
const magnet1080 = showInfo.downloads.find(
(download) => download.res === '1080',
)?.magnet;
let downloadedResolution: ShowResolution | undefined;
if (showDownloaded === magnet720) {
downloadedResolution = '720';
} else if (showDownloaded === magnet1080) {
downloadedResolution = '1080';
}

if (downloadedResolution) {
return (
<DownloadTorrentButton
resolution={downloadedResolution}
showRecheckButton
availableDownloads={showInfo.downloads}
showName={showInfo.show}
episodeNumber={showInfo.episode}
callbackId={callbackId}
onDownloadStatusChange={setDownloadingStatus}
onDownloadSpeed={setDownloadSpeed}
onDownloadProgress={setDownloadProgress}
onUploadSpeed={setUploadSpeed}
onShowDownloaded={() =>
setShowDownloaded(
showInfo.downloads.find(
(download) =>
download.res === downloadedResolution,
)?.magnet || '',
)
}
/>
);
}
return <></>;
};

const getActionInfoSection = () => {
if (
showDownloaded &&
downloadingStatus === DownloadingStatus.NotDownloading
) {
return getPlayButton();
return (
<View style={{ flexDirection: 'row' }}>
{getPlayButton()}
{getRecheckButton()}
</View>
);
}
if (downloadingStatus === DownloadingStatus.NotDownloading) {
return (
Expand All @@ -198,6 +244,7 @@ export const ReleaseShow = observer(
showName={showInfo.show}
episodeNumber={showInfo.episode}
callbackId={callbackId}
showRecheckButton={false}
onDownloadStatusChange={setDownloadingStatus}
onDownloadSpeed={setDownloadSpeed}
onDownloadProgress={setDownloadProgress}
Expand All @@ -216,6 +263,7 @@ export const ReleaseShow = observer(
showName={showInfo.show}
episodeNumber={showInfo.episode}
callbackId={callbackId}
showRecheckButton={false}
onDownloadStatusChange={setDownloadingStatus}
onDownloadSpeed={setDownloadSpeed}
onDownloadProgress={setDownloadProgress}
Expand Down Expand Up @@ -282,6 +330,7 @@ export const ReleaseShow = observer(
</View>

{getPlayButton()}
{getRecheckButton()}
</View>
);
};
Expand Down

0 comments on commit f10c381

Please sign in to comment.