|
@@ -1,13 +1,17 @@
|
|
|
-import React from 'react'
|
|
|
-
|
|
|
+import React, { useState, useMemo, useCallback } from 'react'
|
|
|
+import { css } from '@emotion/core'
|
|
|
import styled from '@emotion/styled'
|
|
|
|
|
|
-import { breakpointsOfGrid, Gallery, MIN_VIDEO_PREVIEW_WIDTH, VideoPreviewBase } from '@/shared/components'
|
|
|
+import {
|
|
|
+ breakpointsOfGrid,
|
|
|
+ Gallery,
|
|
|
+ MIN_VIDEO_PREVIEW_WIDTH,
|
|
|
+ VideoPreviewBase,
|
|
|
+ CAROUSEL_ARROW_HEIGHT,
|
|
|
+} from '@/shared/components'
|
|
|
import VideoPreview from './VideoPreviewWithNavigation'
|
|
|
import { VideoFields } from '@/api/queries/__generated__/VideoFields'
|
|
|
-
|
|
|
-import { sizes, spacing } from '@/shared/theme'
|
|
|
-import { css } from '@emotion/core'
|
|
|
+import { sizes } from '@/shared/theme'
|
|
|
|
|
|
type VideoGalleryProps = {
|
|
|
title?: string
|
|
@@ -17,8 +21,6 @@ type VideoGalleryProps = {
|
|
|
|
|
|
const PLACEHOLDERS_COUNT = 12
|
|
|
|
|
|
-const trackPadding = `${spacing.xs} 0 0 0`
|
|
|
-
|
|
|
// This is needed since Gliderjs and the Grid have different resizing policies
|
|
|
const breakpoints = breakpointsOfGrid({
|
|
|
breakpoints: 6,
|
|
@@ -29,14 +31,36 @@ const breakpoints = breakpointsOfGrid({
|
|
|
breakpoint,
|
|
|
settings: {
|
|
|
slidesToShow: idx + 1,
|
|
|
+ slidesToScroll: idx + 1,
|
|
|
},
|
|
|
}))
|
|
|
|
|
|
const VideoGallery: React.FC<VideoGalleryProps> = ({ title, videos, loading }) => {
|
|
|
+ const [coverHeight, setCoverHeight] = useState<number>()
|
|
|
+ const onCoverResize = useCallback((_, imgHeight) => {
|
|
|
+ setCoverHeight(imgHeight)
|
|
|
+ }, [])
|
|
|
+ const arrowPosition = useMemo(() => {
|
|
|
+ if (!coverHeight) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ const topPx = (coverHeight - CAROUSEL_ARROW_HEIGHT) / 2
|
|
|
+ return css`
|
|
|
+ top: ${topPx}px;
|
|
|
+ `
|
|
|
+ }, [coverHeight])
|
|
|
+
|
|
|
const displayPlaceholders = loading || !videos
|
|
|
|
|
|
return (
|
|
|
- <Gallery title={title} trackPadding={trackPadding} responsive={breakpoints} itemWidth={MIN_VIDEO_PREVIEW_WIDTH}>
|
|
|
+ <Gallery
|
|
|
+ title={title}
|
|
|
+ paddingLeft={sizes.b2}
|
|
|
+ paddingTop={sizes.b2}
|
|
|
+ responsive={breakpoints}
|
|
|
+ itemWidth={MIN_VIDEO_PREVIEW_WIDTH}
|
|
|
+ arrowCss={arrowPosition}
|
|
|
+ >
|
|
|
{displayPlaceholders
|
|
|
? Array.from({ length: PLACEHOLDERS_COUNT }).map((_, idx) => (
|
|
|
<StyledVideoPreviewBase key={`video-placeholder-${idx}`} />
|
|
@@ -53,6 +77,7 @@ const VideoGallery: React.FC<VideoGalleryProps> = ({ title, videos, loading }) =
|
|
|
duration={video.duration}
|
|
|
posterURL={video.thumbnailUrl}
|
|
|
key={video.id}
|
|
|
+ onCoverResize={onCoverResize}
|
|
|
/>
|
|
|
))}
|
|
|
</Gallery>
|