From 6a204b21c36453d77577264fdc22a00c388682fc Mon Sep 17 00:00:00 2001 From: ikprk Date: Sun, 26 May 2024 07:31:29 +0200 Subject: [PATCH 1/5] Initial shorts page --- .../BackgroundVideoPlayer.tsx | 26 +- .../BackgroundVideoPlayer/VideoProgress.tsx | 15 +- packages/atlas/src/config/routes.ts | 1 + packages/atlas/src/views/viewer/HomeView.tsx | 2 +- .../views/viewer/ShortsView/ShortsView.tsx | 237 ++++++++++++++++++ .../src/views/viewer/ShortsView/index.ts | 1 + .../atlas/src/views/viewer/ViewerLayout.tsx | 2 + 7 files changed, 275 insertions(+), 9 deletions(-) create mode 100644 packages/atlas/src/views/viewer/ShortsView/ShortsView.tsx create mode 100644 packages/atlas/src/views/viewer/ShortsView/index.ts diff --git a/packages/atlas/src/components/_video/BackgroundVideoPlayer/BackgroundVideoPlayer.tsx b/packages/atlas/src/components/_video/BackgroundVideoPlayer/BackgroundVideoPlayer.tsx index 2da75b69b7..c83a62e604 100644 --- a/packages/atlas/src/components/_video/BackgroundVideoPlayer/BackgroundVideoPlayer.tsx +++ b/packages/atlas/src/components/_video/BackgroundVideoPlayer/BackgroundVideoPlayer.tsx @@ -18,6 +18,8 @@ type BackgroundVideoPlayerProps = { withFade?: boolean src: string[] poster: string[] + onMuted?: (newState: boolean) => void + loop?: boolean customLink?: string } & Omit, 'src' | 'poster'> @@ -32,14 +34,16 @@ export const BackgroundVideoPlayer: FC = ({ handleActions, videoPlaytime, videoId, + onMuted, withFade, customLink, + loop, ...props }) => { const videoRef = useRef(null) const [isPosterVisible, setIsPosterVisible] = useState(true) const [isPlaying, setIsPlaying] = useState(autoPlay) - const [isMuted, setIsMuted] = useState(true) + const [isMuted, setIsMuted] = useState(props.muted) const [canPlay, setCanPlay] = useState(false) const initialRender = useRef(true) @@ -76,9 +80,12 @@ export const BackgroundVideoPlayer: FC = ({ } }, [canPlay]) + console.log('adf', playing, props.muted) + useEffect(() => { // show poster again when src changes setIsPosterVisible(true) + console.log('effect') if (!videoRef.current || playing === undefined || !canPlay) { return } @@ -97,9 +104,15 @@ export const BackgroundVideoPlayer: FC = ({ } const handleEnded = (e: SyntheticEvent) => { + onEnded?.(e) + + if (loop && videoRef.current) { + console.log('xd') + videoRef.current.currentTime = 0 + return + } setIsPosterVisible(true) setIsPlaying(false) - onEnded?.(e) } return ( @@ -112,13 +125,18 @@ export const BackgroundVideoPlayer: FC = ({ variant="tertiary" /> diff --git a/packages/atlas/src/components/_video/BackgroundVideoPlayer/BackgroundVideoPlayer.styles.ts b/packages/atlas/src/components/_video/BackgroundVideoPlayer/BackgroundVideoPlayer.styles.ts index 42fa1e7b64..f5371d4d0e 100644 --- a/packages/atlas/src/components/_video/BackgroundVideoPlayer/BackgroundVideoPlayer.styles.ts +++ b/packages/atlas/src/components/_video/BackgroundVideoPlayer/BackgroundVideoPlayer.styles.ts @@ -47,6 +47,7 @@ export const ButtonBox = styled.div` z-index: ${zIndex.modals}; display: flex; gap: ${sizes(2)}; + flex-direction: column-reverse; ${media.sm} { bottom: 32px; diff --git a/packages/atlas/src/components/_video/BackgroundVideoPlayer/BackgroundVideoPlayer.tsx b/packages/atlas/src/components/_video/BackgroundVideoPlayer/BackgroundVideoPlayer.tsx index c83a62e604..e271b6e5fe 100644 --- a/packages/atlas/src/components/_video/BackgroundVideoPlayer/BackgroundVideoPlayer.tsx +++ b/packages/atlas/src/components/_video/BackgroundVideoPlayer/BackgroundVideoPlayer.tsx @@ -80,12 +80,9 @@ export const BackgroundVideoPlayer: FC = ({ } }, [canPlay]) - console.log('adf', playing, props.muted) - useEffect(() => { // show poster again when src changes setIsPosterVisible(true) - console.log('effect') if (!videoRef.current || playing === undefined || !canPlay) { return } @@ -107,7 +104,6 @@ export const BackgroundVideoPlayer: FC = ({ onEnded?.(e) if (loop && videoRef.current) { - console.log('xd') videoRef.current.currentTime = 0 return } diff --git a/packages/atlas/src/views/viewer/ShortsView/ShortsView.tsx b/packages/atlas/src/views/viewer/ShortsView/ShortsView.tsx index 3f82b907f9..776ab4266f 100644 --- a/packages/atlas/src/views/viewer/ShortsView/ShortsView.tsx +++ b/packages/atlas/src/views/viewer/ShortsView/ShortsView.tsx @@ -7,6 +7,9 @@ import { GetBasicVideosConnectionLightweightDocument, useGetCuratedHompageVideosQuery, } from '@/api/queries/__generated__/videos.generated' +import { FlexBox } from '@/components/FlexBox' +import { Text } from '@/components/Text' +import { ChannelLink, FollowButton } from '@/components/_channel/ChannelLink' import { SkeletonLoader } from '@/components/_loaders/SkeletonLoader' import { BackgroundVideoPlayer } from '@/components/_video/BackgroundVideoPlayer' import { getPublicCryptoVideoFilter } from '@/config/contentFilter' @@ -36,8 +39,8 @@ export const ShortsView = () => { const newIndex = Number(entry.target.dataset.index) setActiveIndex(newIndex) setNextSlide(entries[newIndex + 1].target) - - if (tiles.length - newIndex < 2) { + console.log(tiles.length, tiles.length - newIndex, 'hh') + if (tiles.length - newIndex <= 2) { console.log('try fetch') if (!loading) { fetchMore({ @@ -57,9 +60,8 @@ export const ShortsView = () => { observerRef.current?.disconnect() } }, [activeIndex, fetchMore, loading, pageInfo?.endCursor, tiles.length]) - console.log('enext', nextSlide) + const goNextSlide = useCallback(() => { - console.log(nextSlide, 'scroll') nextSlide?.scrollIntoView({ behavior: 'smooth' }) }, [nextSlide]) @@ -99,7 +101,8 @@ const Container = styled.div` scroll-snap-type: y mandatory; align-items: center; scrollbar-width: none; - width: 100%; + width: calc(100% + 36px); + margin-left: -16px; ::-webkit-scrollbar { display: none; @@ -110,15 +113,21 @@ const ShortVideoPlaceholder = styled.div` display: grid; place-items: center; aspect-ratio: 9/16; - - /* background-color: green; */ - max-height: 90%; - width: 400px; - text-align: center; - vertical-align: middle; + max-height: 100%; + min-height: 100%; + min-width: 300px; + width: 100%; scroll-snap-stop: always; scroll-snap-align: center; + ${media.xs} { + width: 400px; + } + + ${media.sm} { + width: 500px; + } + ${media.xxl} { width: 40vw; height: 100%; @@ -139,13 +148,11 @@ const ShortVideoPlayer = ({ playNext: () => void }) => { const { video, loading } = useFullVideo(videoId) - const thumbnailUrls: string[] = video?.thumbnailPhoto?.resolvedUrls ?? [] const mediaUrls: string[] = video?.media?.resolvedUrls ?? [] - const isLoading = loading - console.log(loading) + return ( - {!isLoading ? ( + {!loading ? ( ) : ( - // - // - // )} + + + + + + + {video?.title} + + + {video?.description} + + ) } +const DetailsBox = styled(FlexBox)` + position: absolute; + bottom: 30px; + left: 10px; + max-width: 80%; + overflow: hidden; +` + const ShortVideoPlayerBox = styled.div` aspect-ratio: 9/16; - - /* background-color: green; */ - min-height: 90%; + min-height: 100%; max-height: 100%; width: 100%; position: relative; scroll-snap-stop: always; scroll-snap-align: center; - border: 1px solid red; overflow: hidden; + ${media.md} { + min-height: 95%; + max-height: 95%; + } + ${media.xxl} { width: 40vw; } @@ -201,6 +227,7 @@ export const useHomeVideos = () => { isShort_not_eq: undefined, isShortDerived_isNull: undefined, isShort_eq: true, + isShortDerived_eq: true, }), skipVideoIds: ['-1'], }, @@ -209,12 +236,24 @@ export const useHomeVideos = () => { const { columns, fetchMore, pageInfo, tiles } = useInfiniteVideoGrid({ query: GetBasicVideosConnectionLightweightDocument, variables: { - where: getPublicCryptoVideoFilter({ - id_not_in: avoidIds, - isShort_not_eq: undefined, - isShortDerived_isNull: undefined, - isShort_eq: true, - }), + where: { + OR: [ + getPublicCryptoVideoFilter({ + id_not_in: avoidIds, + isShort_not_eq: undefined, + isShortDerived_isNull: undefined, + isShort_eq: true, + orionLanguage_eq: 'en', + }), + getPublicCryptoVideoFilter({ + id_not_in: avoidIds, + isShort_not_eq: undefined, + isShortDerived_isNull: undefined, + isShortDerived_eq: true, + orionLanguage_eq: 'en', + }), + ], + }, orderBy: VideoOrderByInput.VideoRelevanceDesc, }, options: { From 16b20e36b4009d2b13fa3726d38ba04255aa1766 Mon Sep 17 00:00:00 2001 From: ikprk Date: Sun, 26 May 2024 11:32:29 +0200 Subject: [PATCH 3/5] Add small margin to details --- packages/atlas/src/views/viewer/ShortsView/ShortsView.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/atlas/src/views/viewer/ShortsView/ShortsView.tsx b/packages/atlas/src/views/viewer/ShortsView/ShortsView.tsx index 776ab4266f..0bd982885c 100644 --- a/packages/atlas/src/views/viewer/ShortsView/ShortsView.tsx +++ b/packages/atlas/src/views/viewer/ShortsView/ShortsView.tsx @@ -39,9 +39,7 @@ export const ShortsView = () => { const newIndex = Number(entry.target.dataset.index) setActiveIndex(newIndex) setNextSlide(entries[newIndex + 1].target) - console.log(tiles.length, tiles.length - newIndex, 'hh') if (tiles.length - newIndex <= 2) { - console.log('try fetch') if (!loading) { fetchMore({ variables: { first: 4 * 4, after: pageInfo?.endCursor }, @@ -176,7 +174,7 @@ const ShortVideoPlayer = ({ - + {video?.title} From ebd646d95cb823a60a68e0a7f24d88a0b5130b04 Mon Sep 17 00:00:00 2001 From: ikprk Date: Sun, 26 May 2024 11:52:47 +0200 Subject: [PATCH 4/5] Build fix --- packages/atlas/src/views/viewer/ShortsView/ShortsView.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/atlas/src/views/viewer/ShortsView/ShortsView.tsx b/packages/atlas/src/views/viewer/ShortsView/ShortsView.tsx index 0bd982885c..d5d1c67f8a 100644 --- a/packages/atlas/src/views/viewer/ShortsView/ShortsView.tsx +++ b/packages/atlas/src/views/viewer/ShortsView/ShortsView.tsx @@ -35,8 +35,9 @@ export const ShortsView = () => { observerRef.current = new IntersectionObserver((entries) => { entries.forEach((entry) => { + const target = entry.target as HTMLDivElement if (entry.isIntersecting) { - const newIndex = Number(entry.target.dataset.index) + const newIndex = Number(target.dataset.index) setActiveIndex(newIndex) setNextSlide(entries[newIndex + 1].target) if (tiles.length - newIndex <= 2) { From 9f5f3ea36f2fad49629d026b8885a89dac159985 Mon Sep 17 00:00:00 2001 From: ikprk Date: Sun, 26 May 2024 12:03:55 +0200 Subject: [PATCH 5/5] Improve loading stage --- .../views/viewer/ShortsView/ShortsView.tsx | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/packages/atlas/src/views/viewer/ShortsView/ShortsView.tsx b/packages/atlas/src/views/viewer/ShortsView/ShortsView.tsx index d5d1c67f8a..1fb7427c1e 100644 --- a/packages/atlas/src/views/viewer/ShortsView/ShortsView.tsx +++ b/packages/atlas/src/views/viewer/ShortsView/ShortsView.tsx @@ -74,8 +74,8 @@ export const ShortsView = () => { activeIndex > idx && idx > activeIndex - 2 ? 'prev' : '' } ${activeIndex < idx && idx < activeIndex + 2 ? 'next' : ''}`} > - {!id || activeIndex - 1 > idx || activeIndex + 2 < idx ? ( -
+ {activeIndex - 1 > idx || activeIndex + 2 < idx ? ( +
) : ( void playNext: () => void }) => { - const { video, loading } = useFullVideo(videoId) + const { video, loading } = useFullVideo(videoId ?? '') const mediaUrls: string[] = video?.media?.resolvedUrls ?? [] return ( - {!loading ? ( + {!loading && videoId ? ( ) : ( - + )} - - - - - - - {video?.title} - - - {video?.description} - - + {video ? ( + + + + + + + {video?.title} + + + {video?.description} + + + ) : null} ) }