2022-03-01 04:19:20 +01:00
|
|
|
// @flow
|
|
|
|
import React from 'react';
|
2022-03-04 08:15:23 +01:00
|
|
|
import Button from 'component/button';
|
|
|
|
import ChannelThumbnail from 'component/channelThumbnail';
|
2022-03-01 04:19:20 +01:00
|
|
|
import ClaimList from 'component/claimList';
|
2022-03-04 08:15:23 +01:00
|
|
|
import ClaimPreviewTitle from 'component/claimPreviewTitle';
|
2022-03-01 04:19:20 +01:00
|
|
|
import DebouncedInput from 'component/common/debounced-input';
|
|
|
|
import Empty from 'component/common/empty';
|
|
|
|
import Page from 'component/page';
|
|
|
|
import Spinner from 'component/spinner';
|
|
|
|
import * as ICONS from 'constants/icons';
|
2022-03-04 08:15:23 +01:00
|
|
|
import { SIDEBAR_SUBS_DISPLAYED } from 'constants/subscriptions';
|
2022-05-16 08:42:17 +02:00
|
|
|
import useClaimListInfiniteScroll from 'effects/use-claimList-infinite-scroll';
|
2022-03-01 04:19:20 +01:00
|
|
|
|
|
|
|
function getFilteredUris(uris, filterQuery) {
|
|
|
|
if (filterQuery) {
|
|
|
|
const filterQueryLowerCase = filterQuery.toLowerCase();
|
|
|
|
return uris.filter((uri) => uri.toLowerCase().includes(filterQueryLowerCase));
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ****************************************************************************
|
|
|
|
// ChannelsFollowingManage
|
|
|
|
// ****************************************************************************
|
|
|
|
|
2022-03-01 07:40:35 +01:00
|
|
|
const FOLLOW_PAGE_SIZE = 30;
|
|
|
|
|
2022-03-01 04:19:20 +01:00
|
|
|
type Props = {
|
|
|
|
subscribedChannelUris: Array<string>,
|
2022-03-04 08:15:23 +01:00
|
|
|
lastActiveSubs: ?Array<Subscription>,
|
2022-03-01 07:40:35 +01:00
|
|
|
doResolveUris: (uris: Array<string>, returnCachedClaims: boolean, resolveReposts: boolean) => void,
|
2022-03-07 03:41:54 +01:00
|
|
|
doFetchLastActiveSubs: (force?: boolean, count?: number) => void,
|
2022-03-01 04:19:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
export default function ChannelsFollowingManage(props: Props) {
|
2022-03-07 03:41:54 +01:00
|
|
|
const { subscribedChannelUris, lastActiveSubs, doResolveUris, doFetchLastActiveSubs } = props;
|
2022-05-16 08:42:17 +02:00
|
|
|
const { uris, page, isLoadingPage, bumpPage } = useClaimListInfiniteScroll(
|
|
|
|
subscribedChannelUris,
|
|
|
|
doResolveUris,
|
|
|
|
FOLLOW_PAGE_SIZE
|
|
|
|
);
|
2022-03-01 07:40:35 +01:00
|
|
|
|
|
|
|
// Filtered query and their uris.
|
2022-03-01 04:19:20 +01:00
|
|
|
const [filterQuery, setFilterQuery] = React.useState('');
|
2022-03-01 07:40:35 +01:00
|
|
|
const [filteredUris, setFilteredUris] = React.useState(null);
|
|
|
|
|
|
|
|
async function resolveUris(uris) {
|
|
|
|
return doResolveUris(uris, true, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
const filteredUris = getFilteredUris(uris, filterQuery);
|
|
|
|
if (filteredUris) {
|
|
|
|
resolveUris(filteredUris).finally(() => setFilteredUris(filteredUris));
|
|
|
|
} else {
|
|
|
|
setFilteredUris(filteredUris);
|
|
|
|
}
|
2022-06-06 18:19:35 +02:00
|
|
|
// (only need to respond to 'filterQuery')
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
2022-03-01 07:40:35 +01:00
|
|
|
}, [filterQuery]);
|
|
|
|
|
2022-03-07 03:41:54 +01:00
|
|
|
React.useEffect(() => {
|
|
|
|
doFetchLastActiveSubs(true);
|
|
|
|
}, []);
|
|
|
|
|
2022-03-01 04:19:20 +01:00
|
|
|
return (
|
|
|
|
<Page className="followManage-wrapper" noFooter>
|
|
|
|
<div className="card__title-section">
|
|
|
|
<div className="card__title"> {__('Followed Channels')}</div>
|
|
|
|
</div>
|
|
|
|
|
2022-03-01 07:40:35 +01:00
|
|
|
{page < 0 ? (
|
2022-03-01 04:19:20 +01:00
|
|
|
<div className="main--empty">
|
2022-03-01 07:40:35 +01:00
|
|
|
<Spinner delayed />
|
2022-03-01 04:19:20 +01:00
|
|
|
</div>
|
|
|
|
) : uris && uris.length === 0 ? (
|
|
|
|
<Empty padded text="No followed channels." />
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<DebouncedInput icon={ICONS.SEARCH} placeholder={__('Filter')} onChange={setFilterQuery} inline />
|
2022-03-01 07:40:35 +01:00
|
|
|
|
2022-03-01 04:19:20 +01:00
|
|
|
{filteredUris && <ClaimList uris={filteredUris} />}
|
2022-03-01 07:40:35 +01:00
|
|
|
|
2022-03-04 08:15:23 +01:00
|
|
|
{!filteredUris && lastActiveSubs && lastActiveSubs.length === SIDEBAR_SUBS_DISPLAYED && (
|
|
|
|
<>
|
|
|
|
<div className="card__title-section">
|
|
|
|
<div className="card__subtitle"> {__('Recently Active')}</div>
|
|
|
|
</div>
|
|
|
|
<div className="followManage-wrapper__activeSubs">
|
|
|
|
{lastActiveSubs.map((sub) => {
|
|
|
|
return (
|
|
|
|
<div key={sub.uri} className="navigation-link__wrapper navigation__subscription">
|
|
|
|
<Button
|
|
|
|
navigate={sub.uri}
|
|
|
|
className="navigation-link navigation-link--with-thumbnail"
|
|
|
|
activeClass="navigation-link--active"
|
|
|
|
>
|
|
|
|
<ChannelThumbnail xsmall uri={sub.uri} hideStakedIndicator />
|
|
|
|
<div className="navigation__subscription-title">
|
|
|
|
<ClaimPreviewTitle uri={sub.uri} />
|
|
|
|
<span dir="auto" className="channel-name">
|
|
|
|
{sub.channelName}
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
|
2022-03-01 07:40:35 +01:00
|
|
|
{!filteredUris && uris.length > 0 && (
|
2022-03-04 08:15:23 +01:00
|
|
|
<>
|
|
|
|
<div className="card__title-section">
|
|
|
|
<div className="card__subtitle"> {__('All Channels')}</div>
|
|
|
|
</div>
|
|
|
|
<ClaimList
|
|
|
|
uris={uris.slice(0, (page + 1) * FOLLOW_PAGE_SIZE)}
|
|
|
|
onScrollBottom={bumpPage}
|
|
|
|
page={page + 1}
|
|
|
|
pageSize={FOLLOW_PAGE_SIZE}
|
2022-05-16 08:42:17 +02:00
|
|
|
loading={isLoadingPage}
|
2022-03-04 08:15:23 +01:00
|
|
|
useLoadingSpinner
|
|
|
|
/>
|
|
|
|
</>
|
2022-03-01 04:19:20 +01:00
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</Page>
|
|
|
|
);
|
|
|
|
}
|