2019-06-28 09:33:07 +02:00
|
|
|
// @flow
|
|
|
|
import React from 'react';
|
2020-05-11 17:54:39 +02:00
|
|
|
import Button from 'component/button';
|
2019-06-28 09:33:07 +02:00
|
|
|
import Page from 'component/page';
|
2020-05-11 17:54:39 +02:00
|
|
|
import Spinner from 'component/spinner';
|
2019-06-28 09:33:07 +02:00
|
|
|
import DownloadList from 'page/fileListDownloaded';
|
2020-05-11 17:54:39 +02:00
|
|
|
import Yrbl from 'component/yrbl';
|
2020-05-21 17:38:28 +02:00
|
|
|
import { useHistory } from 'react-router';
|
2020-05-11 17:54:39 +02:00
|
|
|
|
2020-05-21 19:23:52 +02:00
|
|
|
// https://github.com/lbryio/lbry-sdk/issues/2964
|
2020-05-21 19:18:55 +02:00
|
|
|
export const PURCHASES_PAGE_SIZE = 10;
|
|
|
|
|
2020-05-11 17:54:39 +02:00
|
|
|
type Props = {
|
|
|
|
allDownloadedUrlsCount: number,
|
|
|
|
myPurchases: Array<string>,
|
|
|
|
fetchingMyPurchases: boolean,
|
|
|
|
fetchingFileList: boolean,
|
2020-05-21 19:18:55 +02:00
|
|
|
doPurchaseList: (number, number) => void,
|
2020-05-11 17:54:39 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
function LibraryPage(props: Props) {
|
2020-05-21 17:38:28 +02:00
|
|
|
const { allDownloadedUrlsCount, myPurchases, fetchingMyPurchases, fetchingFileList, doPurchaseList } = props;
|
|
|
|
const { location } = useHistory();
|
|
|
|
const urlParams = new URLSearchParams(location.search);
|
|
|
|
const page = Number(urlParams.get('page')) || 1;
|
|
|
|
const hasDownloads = allDownloadedUrlsCount > 0 || (myPurchases && myPurchases.length > 0);
|
2020-05-11 17:54:39 +02:00
|
|
|
const loading = fetchingFileList || fetchingMyPurchases;
|
2019-06-28 09:33:07 +02:00
|
|
|
|
2020-05-21 17:38:28 +02:00
|
|
|
React.useEffect(() => {
|
2020-05-21 19:18:55 +02:00
|
|
|
doPurchaseList(page, PURCHASES_PAGE_SIZE);
|
2020-05-21 17:38:28 +02:00
|
|
|
}, [doPurchaseList, page]);
|
|
|
|
|
2019-06-28 09:33:07 +02:00
|
|
|
return (
|
|
|
|
<Page>
|
2020-05-11 17:54:39 +02:00
|
|
|
{loading && !hasDownloads && (
|
|
|
|
<div className="main--empty">
|
|
|
|
<Spinner delayed />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
|
|
|
|
{!loading && !hasDownloads && (
|
|
|
|
<div className="main--empty">
|
|
|
|
<Yrbl
|
2022-01-07 20:02:33 +01:00
|
|
|
title={__("You haven't downloaded anything from LBRY yet")}
|
2020-09-02 22:08:37 +02:00
|
|
|
actions={
|
2020-05-11 17:54:39 +02:00
|
|
|
<div className="section__actions">
|
2020-05-21 17:38:28 +02:00
|
|
|
<Button button="primary" navigate="/" label={__('Explore New Content')} />
|
2020-05-11 17:54:39 +02:00
|
|
|
</div>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
|
|
|
|
{hasDownloads && <DownloadList />}
|
2019-06-28 09:33:07 +02:00
|
|
|
</Page>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default LibraryPage;
|