lbry-desktop/ui/component/channelContent/view.jsx

321 lines
11 KiB
React
Raw Normal View History

2019-05-07 04:35:04 +02:00
// @flow
2021-07-26 19:04:43 +02:00
import { SHOW_ADS, SIMPLE_SITE } from 'config';
import * as CS from 'constants/claim_search';
import * as ICONS from 'constants/icons';
2019-05-07 04:35:04 +02:00
import React, { Fragment } from 'react';
import HiddenNsfwClaims from 'component/hiddenNsfwClaims';
import { useHistory } from 'react-router-dom';
import Button from 'component/button';
2020-02-28 15:40:18 +01:00
import ClaimListDiscover from 'component/claimListDiscover';
import Ads from 'web/component/ads';
import Icon from 'component/common/icon';
2021-03-19 21:14:31 +01:00
import LivestreamLink from 'component/livestreamLink';
import { Form, FormField } from 'component/common/form';
import { DEBOUNCE_WAIT_DURATION_MS } from 'constants/search';
import { lighthouse } from 'redux/actions/search';
2019-05-07 04:35:04 +02:00
const TYPES_TO_ALLOW_FILTER = ['stream', 'repost'];
2019-05-07 04:35:04 +02:00
type Props = {
uri: string,
totalPages: number,
fetching: boolean,
params: { page: number },
pageOfClaimsInChannel: Array<StreamClaim>,
channelIsBlocked: boolean,
2019-05-07 04:35:04 +02:00
channelIsMine: boolean,
fetchClaims: (string, number) => void,
channelIsBlackListed: boolean,
defaultPageSize?: number,
defaultInfiniteScroll?: Boolean,
claim: Claim,
2020-03-26 22:47:07 +01:00
isAuthenticated: boolean,
showMature: boolean,
tileLayout: boolean,
viewHiddenChannels: boolean,
doResolveUris: (Array<string>, boolean) => void,
wip wip wip - everything but publish, autoplay, and styling collection publishing add channel to collection publish cleanup wip bump clear mass add after success move collection item management controls redirect replace to published collection id bump playlist selector on create bump use new collection add ui element bump wip gitignore add content json wip bump context add to playlist basic collections page style pass wip wip: edits, buttons, styles... change fileAuthor to claimAuthor update, pending bugfixes, delete modal progress, collection header, other bugfixes bump cleaning show page bugfix builtin collection headers no playlists, no grid title wip style tweaks use normal looking claim previews for collection tiles add collection changes style library previews collection menulist for delete/view on library delete modal works for unpublished rearrange collection publish tabs clean up collection publishing and items show on odysee begin collectoin edit header and css renaming better thumbnails bump fix collection publish redirect view collection in menu does something copy and thumbs list previews, pending, context menus, list page enter to add collection, lists page empty state playable lists only, delete feature, bump put fileListDownloaded back better collection titles improve collection claim details fix horiz more icon fix up channel page style, copy, bump refactor preview overlay properties, fix reposts showing as floppydisk add watch later toast, small overlay properties on wunderbar results, fix collection actions buttons bump cleanup cleaning, refactoring bump preview thumb styling, cleanup support discover page lists search sync, bump bump, fix sync more enforce builtin order for now new lists page empty state try to indicate unpublished edits in lists bump fix autoplay and linting consts, fix autoplay bugs fixes cleanup fix, bump lists experimental ui, fixes refactor listIndex out hack in collection fallback thumb bump
2021-02-06 08:03:51 +01:00
claimType: string,
2021-06-10 23:01:32 +02:00
empty?: string,
2019-05-07 04:35:04 +02:00
};
function ChannelContent(props: Props) {
const {
uri,
fetching,
channelIsMine,
channelIsBlocked,
channelIsBlackListed,
claim,
isAuthenticated,
defaultPageSize = CS.PAGE_SIZE,
defaultInfiniteScroll = true,
showMature,
tileLayout,
viewHiddenChannels,
doResolveUris,
wip wip wip - everything but publish, autoplay, and styling collection publishing add channel to collection publish cleanup wip bump clear mass add after success move collection item management controls redirect replace to published collection id bump playlist selector on create bump use new collection add ui element bump wip gitignore add content json wip bump context add to playlist basic collections page style pass wip wip: edits, buttons, styles... change fileAuthor to claimAuthor update, pending bugfixes, delete modal progress, collection header, other bugfixes bump cleaning show page bugfix builtin collection headers no playlists, no grid title wip style tweaks use normal looking claim previews for collection tiles add collection changes style library previews collection menulist for delete/view on library delete modal works for unpublished rearrange collection publish tabs clean up collection publishing and items show on odysee begin collectoin edit header and css renaming better thumbnails bump fix collection publish redirect view collection in menu does something copy and thumbs list previews, pending, context menus, list page enter to add collection, lists page empty state playable lists only, delete feature, bump put fileListDownloaded back better collection titles improve collection claim details fix horiz more icon fix up channel page style, copy, bump refactor preview overlay properties, fix reposts showing as floppydisk add watch later toast, small overlay properties on wunderbar results, fix collection actions buttons bump cleanup cleaning, refactoring bump preview thumb styling, cleanup support discover page lists search sync, bump bump, fix sync more enforce builtin order for now new lists page empty state try to indicate unpublished edits in lists bump fix autoplay and linting consts, fix autoplay bugs fixes cleanup fix, bump lists experimental ui, fixes refactor listIndex out hack in collection fallback thumb bump
2021-02-06 08:03:51 +01:00
claimType,
2021-06-10 23:01:32 +02:00
empty,
} = props;
// const claimsInChannel = (claim && claim.meta.claims_in_channel) || 0;
const claimsInChannel = 9999;
const [searchQuery, setSearchQuery] = React.useState('');
const [searchResults, setSearchResults] = React.useState(undefined);
const {
location: { pathname, search },
} = useHistory();
const url = `${pathname}${search}`;
const claimId = claim && claim.claim_id;
const showFilters =
!claimType ||
(Array.isArray(claimType)
? claimType.every((ct) => TYPES_TO_ALLOW_FILTER.includes(ct))
: TYPES_TO_ALLOW_FILTER.includes(claimType));
function handleInputChange(e) {
const { value } = e.target;
setSearchQuery(value);
}
2021-12-08 20:59:30 +01:00
// returns true if passed element is fully visible on screen
2021-12-08 21:35:46 +01:00
// function isScrolledIntoView(el) {
// const rect = el.getBoundingClientRect();
// const elemTop = rect.top;
// const elemBottom = rect.bottom;
//
// // Only completely visible elements return true:
// const isVisible = elemTop >= 0 && elemBottom <= window.innerHeight;
// return isVisible;
// }
//
// React.useEffect(() => {
// if (isAuthenticated || !SHOW_ADS) {
// return;
// }
//
// const urlParams = new URLSearchParams(window.location.search);
// const viewType = urlParams.get('view');
//
// // only insert ad if it's a content view
// if (viewType !== 'content') return;
//
// (async function () {
// // test if adblock is enabled
// let adBlockEnabled = false;
// const googleAdUrl = 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js';
// try {
// await fetch(new Request(googleAdUrl)).catch((_) => {
// adBlockEnabled = true;
// });
// } catch (e) {
// adBlockEnabled = true;
// } finally {
// if (!adBlockEnabled) {
// // select the cards on page
// let cards = document.getElementsByClassName('card claim-preview--tile');
//
// // eslint-disable-next-line no-inner-declarations
// function checkFlag() {
// if (cards.length === 0) {
// window.setTimeout(checkFlag, 100);
// } else {
// // find the last fully visible card
// let lastCard;
//
// // width of browser window
// const windowWidth = window.innerWidth;
//
// // on small screens, grab the second item
// if (windowWidth <= 900) {
// lastCard = cards[1];
// } else {
// // otherwise, get the last fully visible card
// for (const card of cards) {
// const isFullyVisible = isScrolledIntoView(card);
// if (!isFullyVisible) break;
// lastCard = card;
// }
// }
//
// // clone the last card
// // $FlowFixMe
// const clonedCard = lastCard.cloneNode(true);
//
// // insert cloned card
// // $FlowFixMe
// lastCard.parentNode.insertBefore(clonedCard, lastCard);
//
// // delete last card so that it doesn't mess up formatting
// // $FlowFixMe
// // lastCard.remove();
//
// // change the appearance of the cloned card
// // $FlowFixMe
// clonedCard.querySelector('.claim__menu-button').remove();
//
// // $FlowFixMe
// clonedCard.querySelector('.truncated-text').innerHTML = __(
// 'Hate these? Login to Odysee for an ad free experience'
// );
//
// // $FlowFixMe
// clonedCard.querySelector('.claim-tile__info').remove();
//
// // $FlowFixMe
// clonedCard.querySelector('[role="none"]').removeAttribute('href');
//
// // $FlowFixMe
// clonedCard.querySelector('.claim-tile__header').firstChild.href = '/$/signin';
//
// // $FlowFixMe
// clonedCard.querySelector('.claim-tile__title').firstChild.removeAttribute('aria-label');
//
// // $FlowFixMe
// clonedCard.querySelector('.claim-tile__title').firstChild.removeAttribute('title');
//
// // $FlowFixMe
// clonedCard.querySelector('.claim-tile__header').firstChild.removeAttribute('aria-label');
//
// // $FlowFixMe
// clonedCard
// .querySelector('.media__thumb')
// .replaceWith(document.getElementsByClassName('homepageAdContainer')[0]);
//
// // show the homepage ad which is not displayed at first
// document.getElementsByClassName('homepageAdContainer')[0].style.display = 'block';
//
// // $FlowFixMe
// const imageHeight = window.getComputedStyle(lastCard.querySelector('.media__thumb')).height;
// // $FlowFixMe
// const imageWidth = window.getComputedStyle(lastCard.querySelector('.media__thumb')).width;
//
// const styles = `#av-container, #AVcontent, #aniBox {
// height: ${imageHeight} !important;
// width: ${imageWidth} !important;
// }`;
//
// const styleSheet = document.createElement('style');
// styleSheet.type = 'text/css';
// styleSheet.id = 'customAniviewStyling';
// styleSheet.innerText = styles;
// // $FlowFixMe
// document.head.appendChild(styleSheet);
//
// window.dispatchEvent(new CustomEvent('scroll'));
// }
// }
// checkFlag();
// }
// }
// })();
// }, []);
2021-12-08 20:59:30 +01:00
React.useEffect(() => {
const timer = setTimeout(() => {
if (searchQuery === '' || !claimId) {
// In order to display original search results, search results must be set to null. A query of '' should display original results.
return setSearchResults(null);
} else {
lighthouse
.search(
`s=${encodeURIComponent(searchQuery)}&channel_id=${encodeURIComponent(claimId)}${
2021-03-17 20:52:23 +01:00
!showMature ? '&nsfw=false&size=50&from=0' : ''
}`
)
.then(({ body: results }) => {
const urls = results.map(({ name, claimId }) => {
return `lbry://${name}#${claimId}`;
});
// Batch-resolve the urls before calling 'setSearchResults', as the
// latter will immediately cause the tiles to resolve, ending up
// calling doResolveUri one by one before the batched one.
doResolveUris(urls, true);
setSearchResults(urls);
})
.catch(() => {
setSearchResults(null);
});
}
}, DEBOUNCE_WAIT_DURATION_MS);
return () => clearTimeout(timer);
}, [claimId, searchQuery, showMature]);
React.useEffect(() => {
setSearchQuery('');
setSearchResults(null);
}, [url]);
2020-02-28 15:40:18 +01:00
2019-05-07 04:35:04 +02:00
return (
<Fragment>
2020-02-28 15:40:18 +01:00
{!fetching && Boolean(claimsInChannel) && !channelIsBlocked && !channelIsBlackListed && (
<HiddenNsfwClaims uri={uri} />
)}
2021-03-19 21:14:31 +01:00
<LivestreamLink uri={uri} />
{!fetching && channelIsBlackListed && (
<section className="card card--section">
<p>
{__(
2021-10-21 22:21:51 +02:00
'In response to a complaint we received under the US Digital Millennium Copyright Act, we have blocked access to this channel from our applications. Content may also be blocked due to DMCA Red Flag rules which are obvious copyright violations we come across, are discussed in public channels, or reported to us.'
)}
</p>
2020-05-01 19:55:42 +02:00
<div className="section__actions">
<Button button="link" href="https://odysee.com/@OdyseeHelp:b/copyright:f" label={__('Read More')} />
</div>
</section>
)}
{!fetching && channelIsBlocked && (
<div className="card--section">
2019-08-02 17:11:31 +02:00
<h2 className="help">{__('You have blocked this channel content.')}</h2>
</div>
)}
2019-05-07 04:35:04 +02:00
2020-02-28 15:40:18 +01:00
{!channelIsMine && claimsInChannel > 0 && <HiddenNsfwClaims uri={uri} />}
2019-10-27 15:41:43 +01:00
2021-12-08 20:59:30 +01:00
<Ads type="homepage" />
<ClaimListDiscover
2021-07-26 19:51:50 +02:00
hasSource
defaultFreshness={CS.FRESH_ALL}
showHiddenByUser={viewHiddenChannels}
forceShowReposts
2021-09-10 19:25:53 +02:00
fetchViewCount
hideFilters={!showFilters}
hideAdvancedFilter={!showFilters}
tileLayout={tileLayout}
uris={searchResults}
2021-07-17 20:55:18 +02:00
streamType={SIMPLE_SITE ? CS.CONTENT_ALL : undefined}
channelIds={[claimId]}
claimType={claimType}
feeAmount={CS.FEE_AMOUNT_ANY}
defaultOrderBy={CS.ORDER_BY_NEW}
pageSize={defaultPageSize}
infiniteScroll={defaultInfiniteScroll}
injectedItem={SHOW_ADS && !isAuthenticated && IS_WEB && <Ads type="video" />}
meta={
showFilters && (
<Form onSubmit={() => {}} className="wunderbar--inline">
<Icon icon={ICONS.SEARCH} />
<FormField
className="wunderbar__input--inline"
value={searchQuery}
onChange={handleInputChange}
type="text"
placeholder={__('Search')}
/>
</Form>
)
}
isChannel
channelIsMine={channelIsMine}
empty={empty}
/>
2019-05-07 04:35:04 +02:00
</Fragment>
);
}
export default ChannelContent;