import React, { useEffect, ReactElement } from "react"; import { getDownloadProgress, getBundlesForComic, } from "../actions/airdcpp.actions"; import { useDispatch, useSelector } from "react-redux"; import { RootState } from "threetwo-ui-typings"; import { isNil, map } from "lodash"; import prettyBytes from "pretty-bytes"; import dayjs from "dayjs"; import ellipsize from "ellipsize"; interface IDownloadsPanelProps { data: any; comicObjectId: string; } export const DownloadsPanel = ( props: IDownloadsPanelProps, ): ReactElement | null => { const downloadProgressTick = useSelector( (state: RootState) => state.airdcpp.downloadProgressData, ); const bundles = useSelector((state: RootState) => { return state.airdcpp.bundles; }); console.log("BANDYA", bundles); const dispatch = useDispatch(); useEffect(() => { dispatch(getBundlesForComic(props.comicObjectId)); dispatch(getDownloadProgress(props.comicObjectId)); }, [dispatch]); const ProgressTick = (props) => { console.log("tick", props); return (
{JSON.stringify(props.data.downloadProgressTick)} {(parseInt(props.data.downloaded_bytes) / parseInt(props.data.size)) * 100} %
{props.data.name}
{prettyBytes(props.data.downloaded_bytes)} of{" "} {prettyBytes(props.data.size)}
{prettyBytes(props.data.speed)} per second.
Time left: {parseInt(props.data.seconds_left) / 60}
{props.data.target}
); }; const Bundles = (props) => { console.log(props); return ( {!isNil(props.data) && props.data && map(props.data, (bundle) => ( ))}
Filename Size Download Time
{ellipsize(bundle.name, 58)}
{bundle.target}
{prettyBytes(bundle.size)} {dayjs .unix(bundle.time_finished) .format("h:mm on ddd, D MMM, YYYY")}
); }; return !isNil(props.data) ? ( <> {!isNil(downloadProgressTick) ? ( ) : null} ) : null; }; export default DownloadsPanel;