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

96 lines
2.8 KiB
React
Raw Normal View History

2018-03-26 23:32:43 +02:00
// @flow
import type { Node } from 'react';
import {
THUMBNAIL_WIDTH,
THUMBNAIL_WIDTH_MOBILE,
THUMBNAIL_HEIGHT,
THUMBNAIL_HEIGHT_MOBILE,
THUMBNAIL_QUALITY,
MISSING_THUMB_DEFAULT,
} from 'config';
import { useIsMobile } from 'effects/use-screensize';
import { getImageProxyUrl, getThumbnailCdnUrl } from 'util/thumbnail';
import React from 'react';
2020-05-28 19:07:04 +02:00
import FreezeframeWrapper from './FreezeframeWrapper';
2019-03-05 05:46:57 +01:00
import Placeholder from './placeholder.png';
2020-11-02 17:51:08 +01:00
import classnames from 'classnames';
2021-06-14 15:24:21 +02:00
import Thumb from './thumb';
2017-07-14 01:18:28 +02:00
2018-03-26 23:32:43 +02:00
type Props = {
2020-11-02 17:51:08 +01:00
uri: string,
2018-03-26 23:32:43 +02:00
thumbnail: ?string, // externally sourced image
children?: Node,
allowGifs: boolean,
2020-11-02 17:51:08 +01:00
claim: ?StreamClaim,
doResolveUri: (string) => void,
2020-11-02 17:51:08 +01:00
className?: string,
2018-03-26 23:32:43 +02:00
};
2020-11-02 17:51:08 +01:00
function FileThumbnail(props: Props) {
const { claim, uri, doResolveUri, thumbnail: rawThumbnail, children, allowGifs = false, className } = props;
2020-11-02 17:51:08 +01:00
const passedThumbnail = rawThumbnail && rawThumbnail.trim().replace(/^http:\/\//i, 'https://');
const thumbnailFromClaim =
uri && claim && claim.value && claim.value.thumbnail ? claim.value.thumbnail.url : undefined;
const thumbnail = passedThumbnail || thumbnailFromClaim;
2020-11-02 17:51:08 +01:00
const hasResolvedClaim = claim !== undefined;
const isGif = thumbnail && thumbnail.endsWith('gif');
const isMobile = useIsMobile();
2020-11-02 17:51:08 +01:00
React.useEffect(() => {
if (!hasResolvedClaim && uri && !passedThumbnail) {
2020-11-02 17:51:08 +01:00
doResolveUri(uri);
2020-05-28 19:07:04 +02:00
}
}, [hasResolvedClaim, uri, doResolveUri, passedThumbnail]);
2020-05-28 19:07:04 +02:00
if (!allowGifs && isGif) {
const url = getImageProxyUrl(thumbnail);
return (
<FreezeframeWrapper src={url} className={classnames('media__thumb', className)}>
{children}
2020-11-02 17:51:08 +01:00
</FreezeframeWrapper>
);
2017-07-14 01:18:28 +02:00
}
2020-11-02 17:51:08 +01:00
const fallback = MISSING_THUMB_DEFAULT ? getThumbnailCdnUrl({ thumbnail: MISSING_THUMB_DEFAULT }) : undefined;
let url = thumbnail || (hasResolvedClaim ? Placeholder : '');
// @if TARGET='web'
// Pass image urls through a compression proxy
if (thumbnail) {
if (isGif) {
url = getImageProxyUrl(thumbnail); // Note: the '!allowGifs' case is handled in Freezeframe above.
} else {
url = getThumbnailCdnUrl({
thumbnail,
width: isMobile ? THUMBNAIL_WIDTH_MOBILE : THUMBNAIL_WIDTH,
height: isMobile ? THUMBNAIL_HEIGHT_MOBILE : THUMBNAIL_HEIGHT,
quality: THUMBNAIL_QUALITY,
});
}
}
// @endif
2020-11-02 17:51:08 +01:00
const thumbnailUrl = url ? url.replace(/'/g, "\\'") : '';
if (hasResolvedClaim || thumbnailUrl) {
return (
<Thumb thumb={thumbnailUrl} fallback={fallback} className={className}>
{children}
</Thumb>
);
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
}
2020-11-02 17:51:08 +01:00
return (
<div
className={classnames('media__thumb', className, {
'media__thumb--resolving': !hasResolvedClaim,
})}
>
{children}
</div>
);
2017-07-14 01:18:28 +02:00
}
2020-05-28 19:07:04 +02:00
export default FileThumbnail;