diff --git a/src/App.css b/src/App.css index f25cd7b..af19ee1 100644 --- a/src/App.css +++ b/src/App.css @@ -128,9 +128,11 @@ .feed { display: inline-flex; + position: relative; flex-direction: column; position: relative; align-items: center; + top: 5rem; width: 90vw; top: 5rem; } diff --git a/src/App.js b/src/App.js index b68b3e8..47ef29b 100644 --- a/src/App.js +++ b/src/App.js @@ -7,9 +7,7 @@ function App() { return (
-
- -
+
); } diff --git a/src/features/discussion/Discussion.js b/src/features/discussion/Discussion.js index 89502c2..1eaabd5 100644 --- a/src/features/discussion/Discussion.js +++ b/src/features/discussion/Discussion.js @@ -1,5 +1,5 @@ import React, { useState, useEffect } from 'react'; -import { useDispatch, /* useSelector */ } from 'react-redux'; +import { useDispatch } from 'react-redux'; import { unwrapResult } from '@reduxjs/toolkit'; import { fetchComments } from '../posts/postsSlice'; import { v4 } from 'uuid'; @@ -27,23 +27,6 @@ export default function Discussion({permalink, isVisible}) { }, [dispatch, formattedLink, isVisible, setData]); - // if (data) { - // let commentData = data[1]; - // let commentArray = commentData.data.children; - - // let toExport = []; - // for (let comment of commentArray) { - // toExport.push( - //
- //

{'u/' + comment.data.author}

- //

{comment.data.body}

- //
- // ); - // } - - // setThread(toExport); - // } - useEffect(() => { if (data) { let commentData = data[1]; @@ -51,9 +34,6 @@ export default function Discussion({permalink, isVisible}) { const getReplies = (comment) => { if (comment.data.replies) { - console.log(comment.data.replies.data.children); - console.log(comment.data.replies.data.children[0].data.author) - return (

@@ -69,8 +49,6 @@ export default function Discussion({permalink, isVisible}) { } } - console.log(data); - setThread(comments.map((comment) => { return ( <> diff --git a/src/features/posts/Feed.js b/src/features/posts/Feed.js index 1852296..a063eda 100644 --- a/src/features/posts/Feed.js +++ b/src/features/posts/Feed.js @@ -2,7 +2,6 @@ import React, { useState, useEffect } from "react"; import { fetchBySub, /* selectPosts */ } from "./postsSlice"; import { selectAllSubs } from "../reddit/redditSlice"; import { useSelector, useDispatch } from "react-redux"; -// import { updatePosts } from "./postsSlice"; import { v4 } from "uuid"; import Post from "./Post"; @@ -15,7 +14,6 @@ export default function Feed() { const [currentPage, setCurrentPage] = useState(0); // Determines current feed page; corresponds to index of feedPage array const dispatch = useDispatch(); - // const posts = useSelector(selectPosts); const subs = useSelector(selectAllSubs); // Selects subreddits from redditSlice useEffect(() => { // this useEffect loop pulls the endpoints from the selected subreddits and stores them as an array in "endpoints" @@ -81,8 +79,6 @@ export default function Feed() { } let sortedPosts = extractedPosts.sort(comparePosts); // implements sorting function - - console.log(sortedPosts); let newFeed = sortedPosts.map((post) => { return ( @@ -93,7 +89,6 @@ export default function Feed() { ) }) - // dispatch(updatePosts(newFeed)); // stores current feed in state of postsSlice setFeed(newFeed); } @@ -158,27 +153,29 @@ export default function Feed() { } return ( - <> - {feedPages ? +

-
- -

Page {currentPage + 1} of {feedPages.length ? (feedPages.length + 1) : 'unknown'}

- + {feedPages ? + +
+ +

Page {currentPage + 1} of {feedPages.length ? (feedPages.length + 1) : 'unknown'}

+ +
+ + : null } + + {feedPages ? feedPages[currentPage] :

Loading cats for you...

} + {feedPages ? + +
+ +

Page {currentPage + 1} of {feedPages.length ? (feedPages.length + 1) : 'unknown'}

+ +
+ + : null } +
- - : null } - - {feedPages ? feedPages[currentPage] :

Loading cats for you...

} - {feedPages ? - -
- -

Page {currentPage + 1} of {feedPages.length ? (feedPages.length + 1) : 'unknown'}

- -
- - : null } - ); } \ No newline at end of file diff --git a/src/features/searchBar/searchBar.js b/src/features/searchBar/searchBar.js new file mode 100644 index 0000000..f84901b --- /dev/null +++ b/src/features/searchBar/searchBar.js @@ -0,0 +1,50 @@ +import React, { useState, useEffect } from "react"; +import { useDispatch, useSelector } from "react-redux"; +import { searchByActive } from '../posts/postsSlice'; +import { selectActive } from "../reddit/redditSlice"; + +export default function SearchBar() { + const dispatch = useDispatch(); + const activeSubs = useSelector(selectActive); + + const [term, setTerm] = useState(''); + const [results, setResults] = useState(null); + + const handleChange = (e) => { + e.preventDefault(); + setTerm(e.target.value); + } + + const handleSubmit = () => { + if (term && activeSubs) { + let extracted = []; + for (let sub in activeSubs) { + extracted.push(sub); + } + + console.log(extracted); + let mapped = extracted.map((sub) => dispatch(searchByActive({sub, term}))); + Promise.all([...mapped]).then((data) => setResults(data)); + } + } + + + useEffect(() => { + let active = true; + + if (results && active) { + console.log(results); + } + + return () => { + active = false; + } + }, [results, activeSubs]); + + return ( + <> + + + + ); +} \ No newline at end of file diff --git a/src/features/video/VideoPlayer.js b/src/features/video/VideoPlayer.js index cd7326f..330ade0 100644 --- a/src/features/video/VideoPlayer.js +++ b/src/features/video/VideoPlayer.js @@ -1,7 +1,6 @@ import { useState, useEffect, useRef } from 'react'; export default function VideoPlayer({data, src}) { - const vidControls = useRef(); const vid = useRef(); const aud = useRef(); // identifies location of video/audio in DOM @@ -14,24 +13,23 @@ export default function VideoPlayer({data, src}) { let url; // contains video source, routed accordingly by logic below if (crossPostSrc) { - url = crossPostSrc; // ... for crossposts - } else if (data.url) { - url = data.url; // ... for local posts, where the url - } else { // can be accessed at data.url - url = null; // otherwise, is null + url = crossPostSrc; + } else if (data.media.reddit_video.fallback_url) { + url = data.media.reddit_video.fallback_url; + } else { + url = null; } useEffect(() => { // checks the endpoint where audio may be found let checking = true; // if the fetch request throws an error, audio is set to null; const checkForAudio = async() => { // otherwise, audio is set to the endpoint, which is evaluated try { // below as truthy, and rendered in the page - await fetch(`${url}/DASH_audio.mp4`) + await fetch(`${data.url}/DASH_audio.mp4`) .then((response) => { - let status = response.status; - if (status > 400) { + if (!response.ok) { setAudio(null); } else { - setAudio(`${url}/DASH_audio.mp4`); + setAudio(`${data.url}/DASH_audio.mp4`); } }); } catch(e) { @@ -56,7 +54,7 @@ export default function VideoPlayer({data, src}) { if (checking) { checkForAudio(); - checkForVideo(data.media.reddit_video.fallback_url); + checkForVideo(url); checking = false; } @@ -70,7 +68,7 @@ export default function VideoPlayer({data, src}) { return; } - if (playing) { + if (audio && playing) { vid.current.play(); // synchronizes play/pause between two components vid.current.currentTime = aud.current.currentTime; // according to section of state } else if (!playing) { @@ -82,17 +80,16 @@ export default function VideoPlayer({data, src}) { <> {!video ? null :
- { !audio ? <> -
}