From c07cda263cdbdb8ba11e4d34d1b208765ae63a81 Mon Sep 17 00:00:00 2001 From: Mikayla Dobson Date: Thu, 27 Jan 2022 13:38:50 -0600 Subject: [PATCH] several media types now accounted for --- src/App.js | 2 -- src/features/posts/Feed.js | 12 ++++++------ src/features/posts/Post.css | 9 +++++++++ src/features/posts/Post.js | 22 +++++++++++++++++----- src/features/posts/notepad.txt | 9 +++++++++ 5 files changed, 41 insertions(+), 13 deletions(-) create mode 100644 src/features/posts/notepad.txt diff --git a/src/App.js b/src/App.js index fa3593e..d081c13 100644 --- a/src/App.js +++ b/src/App.js @@ -8,14 +8,12 @@ function App() { return (
-

Stuff

{/* To do: import posts from post directory */} {/* Map post data onto individual post cards, handle undefined values */} -
diff --git a/src/features/posts/Feed.js b/src/features/posts/Feed.js index 8f772c1..d5e878d 100644 --- a/src/features/posts/Feed.js +++ b/src/features/posts/Feed.js @@ -1,5 +1,5 @@ import React, { useState, useEffect } from "react"; -import { fetchBySub, updatePosts, selectPosts } from "./postsSlice"; +import postsSlice, { fetchBySub, updatePosts, selectPosts } from "./postsSlice"; import { selectAllSubs } from "../reddit/redditSlice"; import { useSelector, useDispatch } from "react-redux"; import { v4 } from "uuid"; @@ -15,6 +15,7 @@ export default function Feed() { const getPosts = async() => { let myPosts = await dispatch(fetchBySub('https://www.reddit.com/r/cats.json')); myPosts = myPosts.payload; + console.log(myPosts); if (typeof myPosts === 'object' && isActive) { let newFeed = []; @@ -29,6 +30,9 @@ export default function Feed() { time={post.data.created_utc} id={v4()} media={post.data.post_hint === 'image' && post.data.url} + permalink={post.data.permalink} + selftext={post.data.selftext} + video={post.data.is_video ? post.data.media.reddit_video.fallback_url : null} /> ); } @@ -43,13 +47,9 @@ export default function Feed() { }, [dispatch]) - useEffect(() => { - console.log(feed); - }, [feed]) - return ( <> - {feed} + {feed ? feed :

Loading cats for you...

} ); } \ No newline at end of file diff --git a/src/features/posts/Post.css b/src/features/posts/Post.css index 7a5ed35..7577f35 100644 --- a/src/features/posts/Post.css +++ b/src/features/posts/Post.css @@ -14,6 +14,15 @@ height: 15rem; } +a { + font-size: 2rem; +} + +img, video { + max-height: 45rem; + object-fit: contain; +} + .post-metadata { display: inline-flex; flex-direction: row; diff --git a/src/features/posts/Post.js b/src/features/posts/Post.js index 0210f43..bc65e4a 100644 --- a/src/features/posts/Post.js +++ b/src/features/posts/Post.js @@ -1,15 +1,27 @@ -import React from "react"; +import React, { useState, useEffect } from "react"; import './Post.css'; -export default function Post({title,author,subreddit,ups,comments,time,id,media}) { +export default function Post({title,author,subreddit,ups,comments,time,id,media,permalink,selftext,video}) { + const limit = 300; + const [body, setBody] = useState(selftext); + + useEffect(() => { + if (selftext.length > limit) { + setBody(selftext.substring(0,limit) + '...'); + } else { + return; + } + }) return ( <>
-

{title ? title : 'title'}

- {title} + {title ? title : 'title'} + {media ? {title} : ''} + {video ? : ''} +

{body}

-

{author ? author : 'u/username'}

+

{author ? 'u/' + author : 'u/username'}

{time ? time : ''}

{comments ? comments : 'comments'}

diff --git a/src/features/posts/notepad.txt b/src/features/posts/notepad.txt new file mode 100644 index 0000000..79956f4 --- /dev/null +++ b/src/features/posts/notepad.txt @@ -0,0 +1,9 @@ +bitrate_kbps: 1200 +dash_url: "https://v.redd.it/5vx109l7x8e81/DASHPlaylist.mpd?a=1645903634%2CZThiNjM5ZTc5MmQ3ZmIxYzg4Y2YzYzc2MDk2MjgzNzU0N2RlOTZjMzhmNWFhN2VjNDI2OWZmNWI0MDY1NDQxOA%3D%3D&v=1&f=hd" +duration: 23 +fallback_url: "https://v.redd.it/5vx109l7x8e81/DASH_480.mp4?source=fallback" +height: 480 +hls_url: "https://v.redd.it/5vx109l7x8e81/HLSPlaylist.m3u8?a=1645903634%2COWI5Nzc2MzM0ZTExNTVlMWZiODBhMGJiMjMxYjU4NDk3ZDcwMTEzOGEyN2M4MDA3MmE0YWFlNzMzOTg0MjIzNw%3D%3D&v=1&f=hd" +is_gif: false +scrubber_media_url: "https://v.redd.it/5vx109l7x8e81/DASH_96.mp4" +transcoding_status: "completed" \ No newline at end of file