lbry-desktop/ui/page/fileListPublished/view.jsx

168 lines
5.4 KiB
React
Raw Normal View History

// @flow
2020-07-23 19:02:07 +02:00
import * as PAGES from 'constants/pages';
import * as ICONS from 'constants/icons';
2019-06-11 20:10:58 +02:00
import React, { useEffect } from 'react';
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';
2022-04-04 14:05:46 +02:00
import ClaimPreview from 'component/claimPreview';
2018-03-26 23:32:43 +02:00
import Page from 'component/page';
2019-09-23 19:32:38 +02:00
import Paginate from 'component/common/paginate';
import { PAGE_PARAM, PAGE_SIZE_PARAM } from 'constants/claim';
import WebUploadList from 'component/webUploadList';
import Spinner from 'component/spinner';
2020-09-04 19:14:48 +02:00
import Yrbl from 'component/yrbl';
import classnames from 'classnames';
import useFetchViewCount from 'effects/use-fetch-view-count';
const FILTER_ALL = 'stream,repost';
const FILTER_UPLOADS = 'stream';
const FILTER_REPOSTS = 'repost';
type Props = {
uploadCount: number,
claimsByUri: { [string]: any },
2018-10-26 06:20:18 +02:00
checkPendingPublishes: () => void,
clearPublish: () => void,
fetchClaimListMine: (number, number, boolean, Array<string>) => void,
fetching: boolean,
2019-09-25 23:37:01 +02:00
urls: Array<string>,
urlTotal: number,
history: { replace: (string) => void, push: (string) => void },
2019-09-23 19:32:38 +02:00
page: number,
pageSize: number,
doFetchViewCount: (claimIdCsv: string) => void,
};
2019-06-11 20:10:58 +02:00
function FileListPublished(props: Props) {
const {
uploadCount,
claimsByUri,
checkPendingPublishes,
clearPublish,
fetchClaimListMine,
fetching,
urls,
urlTotal,
page,
pageSize,
doFetchViewCount,
} = props;
const [filterBy, setFilterBy] = React.useState(FILTER_ALL);
const params = {};
params[PAGE_PARAM] = Number(page);
params[PAGE_SIZE_PARAM] = Number(pageSize);
const paramsString = JSON.stringify(params);
2019-06-11 20:10:58 +02:00
useEffect(() => {
2018-10-26 06:20:18 +02:00
checkPendingPublishes();
}, [checkPendingPublishes]);
useEffect(() => {
if (paramsString && fetchClaimListMine) {
const params = JSON.parse(paramsString);
fetchClaimListMine(params.page, params.page_size, true, filterBy.split(','));
}
}, [uploadCount, paramsString, filterBy, fetchClaimListMine]);
useFetchViewCount(!fetching, urls, claimsByUri, doFetchViewCount);
2019-06-11 20:10:58 +02:00
return (
2020-01-02 21:36:03 +01:00
<Page>
2020-05-28 16:45:56 +02:00
<div className="card-stack">
<WebUploadList />
2020-06-02 18:32:58 +02:00
{!!(urls && urls.length) && (
<>
<ClaimList
2021-03-16 16:45:14 +01:00
header={
<span>
<Button
button="alt"
label={__('All')}
aria-label={__('All uploads')}
onClick={() => setFilterBy(FILTER_ALL)}
className={classnames(`button-toggle`, {
'button-toggle--active': filterBy === FILTER_ALL,
})}
/>
<Button
button="alt"
label={__('Uploads')}
onClick={() => setFilterBy(FILTER_UPLOADS)}
className={classnames(`button-toggle`, {
'button-toggle--active': filterBy === FILTER_UPLOADS,
})}
/>
<Button
button="alt"
label={__('Reposts')}
onClick={() => setFilterBy(FILTER_REPOSTS)}
className={classnames(`button-toggle`, {
'button-toggle--active': filterBy === FILTER_REPOSTS,
})}
/>
</span>
}
headerAltControls={
<div className="card__actions--inline">
{!fetching && (
<Button
button="alt"
label={__('Refresh')}
icon={ICONS.REFRESH}
onClick={() => fetchClaimListMine(params.page, params.page_size, true, filterBy.split(','))}
/>
)}
<Button
icon={ICONS.PUBLISH}
button="primary"
label={__('Upload')}
navigate={`/$/${PAGES.UPLOAD}`}
onClick={() => clearPublish()}
/>
</div>
}
persistedStorageKey="claim-list-published"
2022-04-04 14:05:46 +02:00
uris={fetching ? [] : urls}
loading={fetching}
/>
2022-04-04 14:05:46 +02:00
{fetching &&
new Array(Number(pageSize)).fill(1).map((x, i) => <ClaimPreview key={i} placeholder="loading" />)}
<Paginate totalPages={urlTotal > 0 ? Math.ceil(urlTotal / Number(pageSize)) : 1} />
</>
2020-06-02 18:32:58 +02:00
)}
2020-05-28 16:45:56 +02:00
</div>
{!(urls && urls.length) && (
<React.Fragment>
{!fetching ? (
<section className="main--empty">
2020-09-04 19:14:48 +02:00
<Yrbl
title={__('No uploads')}
subtitle={__("You haven't uploaded anything yet. This is where you can find them when you do!")}
actions={
<div className="section__actions">
<Button
button="primary"
navigate={`/$/${PAGES.UPLOAD}`}
label={__('Upload Something New')}
onClick={() => clearPublish()}
/>
</div>
}
/>
</section>
) : (
<section className="main--empty">
2020-09-04 19:14:48 +02:00
<Spinner delayed />
</section>
)}
</React.Fragment>
2019-06-11 20:10:58 +02:00
)}
</Page>
);
2017-05-01 08:26:09 +02:00
}
2017-06-06 06:21:55 +02:00
export default FileListPublished;