2018-06-13 23:07:06 +02:00
|
|
|
// @flow
|
2020-05-11 17:54:39 +02:00
|
|
|
import * as ICONS from 'constants/icons';
|
2019-10-03 23:20:55 +02:00
|
|
|
import React, { useState } from 'react';
|
2020-06-10 05:55:04 +02:00
|
|
|
import usePersistedState from 'effects/use-persisted-state';
|
2018-03-26 23:32:43 +02:00
|
|
|
import Button from 'component/button';
|
2019-06-19 07:05:43 +02:00
|
|
|
import ClaimList from 'component/claimList';
|
2019-09-23 19:32:38 +02:00
|
|
|
import Paginate from 'component/common/paginate';
|
|
|
|
import { PAGE_SIZE } from 'constants/claim';
|
2019-10-03 23:20:55 +02:00
|
|
|
import { Form } from 'component/common/form-components/form';
|
|
|
|
import Icon from 'component/common/icon';
|
2020-05-11 17:54:39 +02:00
|
|
|
import { FormField } from 'component/common/form-components/form-field';
|
2019-10-03 23:20:55 +02:00
|
|
|
import { withRouter } from 'react-router';
|
2020-05-11 17:54:39 +02:00
|
|
|
import classnames from 'classnames';
|
2020-05-21 17:38:28 +02:00
|
|
|
import Yrbl from 'component/yrbl';
|
2020-05-21 19:18:55 +02:00
|
|
|
import { PURCHASES_PAGE_SIZE } from 'page/library/view';
|
|
|
|
import Spinner from 'component/spinner';
|
2017-04-23 18:10:45 +02:00
|
|
|
|
2018-06-13 23:07:06 +02:00
|
|
|
type Props = {
|
2020-05-11 17:54:39 +02:00
|
|
|
fetchingFileList: boolean,
|
2019-09-25 23:37:01 +02:00
|
|
|
downloadedUrls: Array<string>,
|
|
|
|
downloadedUrlsCount: ?number,
|
2019-09-23 19:32:38 +02:00
|
|
|
history: { replace: string => void },
|
2019-10-27 15:41:43 +01:00
|
|
|
query: string,
|
2020-05-11 17:54:39 +02:00
|
|
|
doPurchaseList: () => void,
|
|
|
|
myDownloads: Array<string>,
|
|
|
|
myPurchases: Array<string>,
|
|
|
|
myPurchasesCount: ?number,
|
|
|
|
fetchingMyPurchases: boolean,
|
2018-06-13 23:07:06 +02:00
|
|
|
};
|
|
|
|
|
2020-05-11 17:54:39 +02:00
|
|
|
const VIEW_DOWNLOADS = 'view_download';
|
|
|
|
const VIEW_PURCHASES = 'view_purchases';
|
2019-10-03 23:20:55 +02:00
|
|
|
|
2020-05-11 17:54:39 +02:00
|
|
|
function FileListDownloaded(props: Props) {
|
|
|
|
const {
|
|
|
|
history,
|
|
|
|
query,
|
|
|
|
downloadedUrlsCount,
|
|
|
|
myPurchasesCount,
|
|
|
|
myPurchases,
|
|
|
|
myDownloads,
|
|
|
|
fetchingFileList,
|
|
|
|
fetchingMyPurchases,
|
|
|
|
} = props;
|
|
|
|
const loading = fetchingFileList || fetchingMyPurchases;
|
2020-06-10 05:55:04 +02:00
|
|
|
const [viewMode, setViewMode] = usePersistedState('library-view-mode', VIEW_PURCHASES);
|
2019-10-03 23:20:55 +02:00
|
|
|
const [searchQuery, setSearchQuery] = useState('');
|
|
|
|
|
|
|
|
function handleInputChange(e) {
|
|
|
|
const { value } = e.target;
|
|
|
|
if (value !== searchQuery) {
|
|
|
|
setSearchQuery(value);
|
|
|
|
history.replace(`?query=${value}&page=1`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-11 20:10:58 +02:00
|
|
|
return (
|
2020-08-24 06:48:46 +02:00
|
|
|
<>
|
|
|
|
<div className="section__header--actions">
|
|
|
|
<div className="section__actions--inline">
|
2020-05-11 17:54:39 +02:00
|
|
|
<Button
|
|
|
|
icon={ICONS.LIBRARY}
|
|
|
|
button="alt"
|
2020-05-21 17:38:28 +02:00
|
|
|
label={__('Downloads')}
|
2020-05-11 17:54:39 +02:00
|
|
|
className={classnames(`button-toggle`, {
|
|
|
|
'button-toggle--active': viewMode === VIEW_DOWNLOADS,
|
|
|
|
})}
|
|
|
|
onClick={() => setViewMode(VIEW_DOWNLOADS)}
|
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
icon={ICONS.PURCHASED}
|
|
|
|
button="alt"
|
2020-05-21 17:38:28 +02:00
|
|
|
label={__('Purchases')}
|
2020-05-11 17:54:39 +02:00
|
|
|
className={classnames(`button-toggle`, {
|
|
|
|
'button-toggle--active': viewMode === VIEW_PURCHASES,
|
|
|
|
})}
|
|
|
|
onClick={() => setViewMode(VIEW_PURCHASES)}
|
|
|
|
/>
|
2020-05-21 19:18:55 +02:00
|
|
|
{loading && <Spinner type="small" />}
|
2020-05-11 17:54:39 +02:00
|
|
|
</div>
|
2020-08-24 06:48:46 +02:00
|
|
|
|
|
|
|
<Form onSubmit={() => {}} className="wunderbar--inline">
|
|
|
|
<Icon icon={ICONS.SEARCH} />
|
|
|
|
<FormField
|
|
|
|
className="wunderbar__input--inline"
|
|
|
|
onChange={handleInputChange}
|
|
|
|
value={query}
|
|
|
|
type="text"
|
|
|
|
name="query"
|
|
|
|
placeholder={__('Search')}
|
|
|
|
/>
|
|
|
|
</Form>
|
|
|
|
</div>
|
|
|
|
{IS_WEB && viewMode === VIEW_DOWNLOADS ? (
|
|
|
|
<div className="main--empty">
|
|
|
|
<Yrbl
|
|
|
|
title={__('Try Out the App!')}
|
|
|
|
subtitle={
|
|
|
|
<>
|
|
|
|
<p className="section__subtitle">
|
|
|
|
{__("Download the app to track files you've viewed and downloaded.")}
|
|
|
|
</p>
|
|
|
|
<div className="section__actions">
|
|
|
|
<Button button="primary" label={__('Get The App')} href="https://lbry.com/get" />
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
/>
|
2020-05-11 17:54:39 +02:00
|
|
|
</div>
|
2020-08-24 06:48:46 +02:00
|
|
|
) : (
|
|
|
|
<div>
|
|
|
|
<ClaimList
|
|
|
|
renderProperties={() => null}
|
|
|
|
empty={
|
|
|
|
viewMode === VIEW_PURCHASES && !query ? (
|
|
|
|
<div>{__('No purchases found.')}</div>
|
|
|
|
) : (
|
|
|
|
__('No results for %query%', { query })
|
|
|
|
)
|
|
|
|
}
|
|
|
|
uris={viewMode === VIEW_PURCHASES ? myPurchases : myDownloads}
|
|
|
|
loading={loading}
|
|
|
|
/>
|
|
|
|
{!query && (
|
|
|
|
<Paginate
|
|
|
|
totalPages={Math.ceil(
|
|
|
|
Number(viewMode === VIEW_PURCHASES ? myPurchasesCount : downloadedUrlsCount) /
|
|
|
|
Number(viewMode === VIEW_PURCHASES ? PURCHASES_PAGE_SIZE : PAGE_SIZE)
|
|
|
|
)}
|
2020-05-11 17:54:39 +02:00
|
|
|
/>
|
2020-08-24 06:48:46 +02:00
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</>
|
2019-06-11 20:10:58 +02:00
|
|
|
);
|
2017-04-23 18:10:45 +02:00
|
|
|
}
|
|
|
|
|
2019-10-03 23:20:55 +02:00
|
|
|
export default withRouter(FileListDownloaded);
|