mirror of
https://git.vectorsigma.ru/public/tubearchivist.git
synced 2026-08-04 22:59:39 +00:00
Refac extract VideoThumbnail into a component
This commit is contained in:
@@ -6,9 +6,8 @@ import formatDate from '../functions/formatDates';
|
|||||||
import Button from './Button';
|
import Button from './Button';
|
||||||
import deleteDownloadById from '../api/actions/deleteDownloadById';
|
import deleteDownloadById from '../api/actions/deleteDownloadById';
|
||||||
import updateDownloadQueueStatusById from '../api/actions/updateDownloadQueueStatusById';
|
import updateDownloadQueueStatusById from '../api/actions/updateDownloadQueueStatusById';
|
||||||
import getApiUrl from '../configuration/getApiUrl';
|
|
||||||
import { useUserConfigStore } from '../stores/UserConfigStore';
|
import { useUserConfigStore } from '../stores/UserConfigStore';
|
||||||
import defaultVideoThumb from '/img/default-video-thumb.jpg';
|
import VideoThumbnail from './VideoThumbail';
|
||||||
|
|
||||||
type DownloadListItemProps = {
|
type DownloadListItemProps = {
|
||||||
download: Download;
|
download: Download;
|
||||||
@@ -22,24 +21,11 @@ const DownloadListItem = ({ download, setRefresh }: DownloadListItemProps) => {
|
|||||||
|
|
||||||
const [hideDownload, setHideDownload] = useState(false);
|
const [hideDownload, setHideDownload] = useState(false);
|
||||||
|
|
||||||
let src = `${getApiUrl()}${download.vid_thumb_url}`;
|
|
||||||
|
|
||||||
if (download.vid_thumb_url === undefined) {
|
|
||||||
src = defaultVideoThumb;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`video-item ${view}`} id={`dl-${download.youtube_id}`}>
|
<div className={`video-item ${view}`} id={`dl-${download.youtube_id}`}>
|
||||||
<div className={`video-thumb-wrap ${view}`}>
|
<div className={`video-thumb-wrap ${view}`}>
|
||||||
<div className="video-thumb">
|
<div className="video-thumb">
|
||||||
<img
|
<VideoThumbnail videoThumbUrl={download.vid_thumb_url} />
|
||||||
src={src}
|
|
||||||
alt="video_thumb"
|
|
||||||
onError={({ currentTarget }) => {
|
|
||||||
currentTarget.onerror = null; // prevents looping
|
|
||||||
currentTarget.src = defaultVideoThumb;
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<div className="video-tags">
|
<div className="video-tags">
|
||||||
{showIgnored && <span>ignored</span>}
|
{showIgnored && <span>ignored</span>}
|
||||||
|
|||||||
@@ -4,14 +4,13 @@ import { VideoType, ViewLayoutType } from '../pages/Home';
|
|||||||
import iconPlay from '/img/icon-play.svg';
|
import iconPlay from '/img/icon-play.svg';
|
||||||
import iconDotMenu from '/img/icon-dot-menu.svg';
|
import iconDotMenu from '/img/icon-dot-menu.svg';
|
||||||
import iconClose from '/img/icon-close.svg';
|
import iconClose from '/img/icon-close.svg';
|
||||||
import defaultVideoThumb from '/img/default-video-thumb.jpg';
|
|
||||||
import updateWatchedState from '../api/actions/updateWatchedState';
|
import updateWatchedState from '../api/actions/updateWatchedState';
|
||||||
import formatDate from '../functions/formatDates';
|
import formatDate from '../functions/formatDates';
|
||||||
import WatchedCheckBox from './WatchedCheckBox';
|
import WatchedCheckBox from './WatchedCheckBox';
|
||||||
import MoveVideoMenu from './MoveVideoMenu';
|
import MoveVideoMenu from './MoveVideoMenu';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import getApiUrl from '../configuration/getApiUrl';
|
|
||||||
import deleteVideoProgressById from '../api/actions/deleteVideoProgressById';
|
import deleteVideoProgressById from '../api/actions/deleteVideoProgressById';
|
||||||
|
import VideoThumbnail from './VideoThumbail';
|
||||||
|
|
||||||
type VideoListItemProps = {
|
type VideoListItemProps = {
|
||||||
video: VideoType;
|
video: VideoType;
|
||||||
@@ -36,12 +35,6 @@ const VideoListItem = ({
|
|||||||
return <p>No video found.</p>;
|
return <p>No video found.</p>;
|
||||||
}
|
}
|
||||||
|
|
||||||
let videoThumbSrc = `${getApiUrl()}${video.vid_thumb_url}`;
|
|
||||||
|
|
||||||
if (video.vid_thumb_url === undefined) {
|
|
||||||
videoThumbSrc = defaultVideoThumb;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`video-item ${viewLayout}`}>
|
<div className={`video-item ${viewLayout}`}>
|
||||||
<a
|
<a
|
||||||
@@ -51,14 +44,7 @@ const VideoListItem = ({
|
|||||||
>
|
>
|
||||||
<div className={`video-thumb-wrap ${viewLayout}`}>
|
<div className={`video-thumb-wrap ${viewLayout}`}>
|
||||||
<div className="video-thumb">
|
<div className="video-thumb">
|
||||||
<img
|
<VideoThumbnail videoThumbUrl={video.vid_thumb_url} />
|
||||||
src={videoThumbSrc}
|
|
||||||
alt="video-thumb"
|
|
||||||
onError={({ currentTarget }) => {
|
|
||||||
currentTarget.onerror = null; // prevents looping
|
|
||||||
currentTarget.src = defaultVideoThumb;
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{video.player.progress && (
|
{video.player.progress && (
|
||||||
<div
|
<div
|
||||||
|
|||||||
27
frontend/src/components/VideoThumbail.tsx
Normal file
27
frontend/src/components/VideoThumbail.tsx
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import getApiUrl from '../configuration/getApiUrl';
|
||||||
|
import defaultVideoThumb from '/img/default-video-thumb.jpg';
|
||||||
|
|
||||||
|
type VideoThumbailProps = {
|
||||||
|
videoThumbUrl: string | undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
const VideoThumbnail = ({ videoThumbUrl }: VideoThumbailProps) => {
|
||||||
|
let src = `${getApiUrl()}${videoThumbUrl}`;
|
||||||
|
|
||||||
|
if (videoThumbUrl === undefined) {
|
||||||
|
src = defaultVideoThumb;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<img
|
||||||
|
src={src}
|
||||||
|
alt="video_thumb"
|
||||||
|
onError={({ currentTarget }) => {
|
||||||
|
currentTarget.onerror = null; // prevents looping
|
||||||
|
currentTarget.src = defaultVideoThumb;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default VideoThumbnail;
|
||||||
Reference in New Issue
Block a user