2018-03-26 23:32:43 +02:00
|
|
|
// @flow
|
2020-01-29 17:38:46 +01:00
|
|
|
import type { Node } from 'react';
|
2020-12-15 19:54:35 +01:00
|
|
|
import { getThumbnailCdnUrl } from 'util/thumbnail';
|
2017-12-21 22:08:54 +01:00
|
|
|
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';
|
2021-08-02 14:33:31 +02:00
|
|
|
import { MISSING_THUMB_DEFAULT } from 'config';
|
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
|
2020-01-29 17:38:46 +01:00
|
|
|
children?: Node,
|
2020-05-29 19:26:06 +02:00
|
|
|
allowGifs: boolean,
|
2020-11-02 17:51:08 +01:00
|
|
|
claim: ?StreamClaim,
|
2021-04-07 07:33:36 +02:00
|
|
|
doResolveUri: (string) => void,
|
2020-11-02 17:51:08 +01:00
|
|
|
className?: string,
|
2022-04-22 05:00:57 +02:00
|
|
|
watchedPercentage: number,
|
|
|
|
showPercentage: boolean,
|
2018-03-26 23:32:43 +02:00
|
|
|
};
|
2018-01-09 02:15:44 +01:00
|
|
|
|
2020-11-02 17:51:08 +01:00
|
|
|
function FileThumbnail(props: Props) {
|
2022-04-22 05:00:57 +02:00
|
|
|
const {
|
|
|
|
claim,
|
|
|
|
uri,
|
|
|
|
doResolveUri,
|
|
|
|
thumbnail: rawThumbnail,
|
|
|
|
children,
|
|
|
|
allowGifs = false,
|
|
|
|
className,
|
|
|
|
watchedPercentage,
|
|
|
|
showPercentage,
|
|
|
|
} = props;
|
2021-06-23 06:05:47 +02:00
|
|
|
|
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;
|
2021-06-23 06:05:47 +02:00
|
|
|
|
2020-11-02 17:51:08 +01:00
|
|
|
const hasResolvedClaim = claim !== undefined;
|
2021-06-23 06:05:47 +02:00
|
|
|
const isGif = thumbnail && thumbnail.endsWith('gif');
|
2019-10-06 07:47:08 +02:00
|
|
|
|
2022-04-22 17:34:55 +02:00
|
|
|
const viewedBar = Boolean(showPercentage && watchedPercentage) && (
|
2022-04-12 18:05:47 +02:00
|
|
|
<div className="file-thumbnail__viewed-bar">
|
2022-04-22 05:00:57 +02:00
|
|
|
<div className="file-thumbnail__viewed-bar-progress" style={{ width: `${watchedPercentage}%` }} />
|
2022-04-12 18:05:47 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
2020-11-02 17:51:08 +01:00
|
|
|
React.useEffect(() => {
|
2020-12-24 17:58:19 +01:00
|
|
|
if (!hasResolvedClaim && uri) {
|
2020-11-02 17:51:08 +01:00
|
|
|
doResolveUri(uri);
|
2020-05-28 19:07:04 +02:00
|
|
|
}
|
2020-11-02 17:51:08 +01:00
|
|
|
}, [hasResolvedClaim, uri, doResolveUri]);
|
2020-05-28 19:07:04 +02:00
|
|
|
|
2021-06-23 06:05:47 +02:00
|
|
|
if (!allowGifs && isGif) {
|
2020-01-29 17:38:46 +01:00
|
|
|
return (
|
2020-11-02 17:51:08 +01:00
|
|
|
<FreezeframeWrapper src={thumbnail} className={classnames('media__thumb', className)}>
|
2020-01-29 17:38:46 +01:00
|
|
|
{children}
|
2022-04-12 18:05:47 +02:00
|
|
|
{viewedBar}
|
2020-11-02 17:51:08 +01:00
|
|
|
</FreezeframeWrapper>
|
2020-01-29 17:38:46 +01:00
|
|
|
);
|
2017-07-14 01:18:28 +02:00
|
|
|
}
|
2020-11-02 17:51:08 +01:00
|
|
|
|
2021-08-02 14:33:31 +02:00
|
|
|
const fallback = MISSING_THUMB_DEFAULT ? getThumbnailCdnUrl({ thumbnail: MISSING_THUMB_DEFAULT }) : undefined;
|
|
|
|
|
2020-12-08 21:10:11 +01:00
|
|
|
let url = thumbnail || (hasResolvedClaim ? Placeholder : '');
|
|
|
|
// @if TARGET='web'
|
|
|
|
// Pass image urls through a compression proxy
|
2021-06-23 06:05:47 +02:00
|
|
|
if (thumbnail && !(isGif && allowGifs)) {
|
2020-12-15 19:54:35 +01:00
|
|
|
url = getThumbnailCdnUrl({ thumbnail });
|
2020-12-08 21:10:11 +01:00
|
|
|
}
|
|
|
|
// @endif
|
2020-11-02 17:51:08 +01:00
|
|
|
|
2021-06-23 06:05:47 +02:00
|
|
|
const thumbnailUrl = url ? url.replace(/'/g, "\\'") : '';
|
2021-04-07 07:33:36 +02:00
|
|
|
|
2021-06-23 06:05:47 +02:00
|
|
|
if (hasResolvedClaim || thumbnailUrl) {
|
2021-07-29 09:53:56 +02:00
|
|
|
return (
|
2021-08-02 14:33:31 +02:00
|
|
|
<Thumb thumb={thumbnailUrl} fallback={fallback} className={className}>
|
2021-07-29 09:53:56 +02:00
|
|
|
{children}
|
2022-04-12 18:05:47 +02:00
|
|
|
{viewedBar}
|
2021-07-29 09:53:56 +02:00
|
|
|
</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}
|
2022-04-12 18:05:47 +02:00
|
|
|
{viewedBar}
|
2020-11-02 17:51:08 +01:00
|
|
|
</div>
|
|
|
|
);
|
2017-07-14 01:18:28 +02:00
|
|
|
}
|
|
|
|
|
2020-05-28 19:07:04 +02:00
|
|
|
export default FileThumbnail;
|