diff --git a/src/features/posts/Post.css b/src/features/posts/Post.css index 3395be0..a10a34a 100644 --- a/src/features/posts/Post.css +++ b/src/features/posts/Post.css @@ -64,6 +64,19 @@ img, video { color: rgb(97, 49, 95); } +.gallery-statement { + color: rgb(228, 180, 226); +} + +.gallery-statement a { + color: white; + text-decoration: none; +} + +.gallery-statement a:active { + color:rgb(97, 49, 95); +} + .num-comments { display: inline-flex; background-color: #7196be; diff --git a/src/features/posts/Post.js b/src/features/posts/Post.js index 6aa6fd1..330f688 100644 --- a/src/features/posts/Post.js +++ b/src/features/posts/Post.js @@ -1,6 +1,7 @@ import React, { useState, useEffect } from "react"; // import { useDispatch } from "react-redux"; import Discussion from "../discussion/Discussion"; +import VideoPlayer from "../video/VideoPlayer"; import './Post.css'; export default function Post({data, key}) { @@ -14,11 +15,6 @@ export default function Post({data, key}) { let media = data.post_hint === 'image' && data.url; let permalink = data.permalink; let selftext = data.selftext; - let video = data.is_video ? `${data.url}/DASH_1080.mp4` : null; // to do: handle media edge cases, especially video - - // fallback_url: "https://v.redd.it/0rditq5l49g81/DASH_1080.mp4?source=fallback" - // url: "https://v.redd.it/0rditq5l49g81" - // id: "sm2wym" const limit = 300; const [body, setBody] = useState(selftext); @@ -90,6 +86,10 @@ export default function Post({data, key}) { return; } } + + // Render function below: + // Each is preceded by a conditional so the program does not throw an error + // before the fetch requests' promises are fulfilled. return ( <> @@ -99,17 +99,16 @@ export default function Post({data, key}) { {title} :

[untitled]

} - {media ? {title} : ''} - {data.crosspost_parent_list ? handleCrosspost() : ''} + {media ? {title} : null} + + {data.crosspost_parent_list ? handleCrosspost() : null} {data.gallery_data ? -

View the gallery of photos corresponding to this post here.

+

View the gallery of photos corresponding to this post here.

: null} {data.is_video ? - + : null} {body ? diff --git a/src/features/video/VideoPlayer.js b/src/features/video/VideoPlayer.js index ad9198e..7309127 100644 --- a/src/features/video/VideoPlayer.js +++ b/src/features/video/VideoPlayer.js @@ -1,30 +1,33 @@ -import { useState, useRef } from 'react'; +import { useState, useEffect, useRef } from 'react'; export default function VideoPlayer({data}) { - let playerVideo = useRef(); - let playerAudio = useRef(); - const [playing, setPlaying] = useState(false); + const vid = useRef(); + const aud = useRef(); + + const vidPosition = useRef(0); + const audPosition = useRef(0); let url = data.url ? data.url : null; + const [playing, setPlaying] = useState(false); - const handlePlay = () => { - setPlaying(true); - + useEffect(() => { if (playing) { - playerAudio.current.currentTime = playerVideo.current.currentTime; - setPlaying(false); + aud.current.play(); + vid.current.currentTime = aud.current.currentTime; + } else if (!playing) { + aud.current.pause(); } - } - - const handlePause = () => { - playerAudio.current.pause(); - setPlaying(false); - } + }, [playing, aud, vid]); return (
- - + + +

{playing.toString()}

); } \ No newline at end of file