From e5f30771d0a6d2257c8ce6c6adac5663f2de1dff Mon Sep 17 00:00:00 2001 From: Mikayla Dobson Date: Sun, 30 Jan 2022 12:03:08 -0600 Subject: [PATCH 1/5] updated readme.md --- README.md | 74 +++++++++++++++++++++++++------------------------------ 1 file changed, 33 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index f91225f..7409736 100644 --- a/README.md +++ b/README.md @@ -1,44 +1,36 @@ +# Reddit, but it's all cats! +## React/Redux project developed by Mikayla Dobson + +This project was completed as a portfolio project in Codecademy's Full Stack Engineer Pro course! + +The goal of this project was to build a read-only client for browsing Reddit, allowing the user to read data from posts, view discussion threads, and search posts within the feed. + +In order to make this project my own, I populated my feed with content from some of my favorite cat related subreddits. + +Additional features implemented include: + +- Ability to toggle subreddit visibility in the sidebar +- Displays certain addition post and discussion metadata +- Optimized rendering with subsections of the total feed, by page of 20 posts +- CI/CD and Web Hosting with Netlify + +## Changelog: + +### Version 0.1, 01/30/2022 + +First project build! + +Many features still need to be built out, but much of the initial functionality exists, including: + +- Post rendering +- Media rendering +- Discussion thread rendering +- UI design + +------ + This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app), using the [Redux](https://redux.js.org/) and [Redux Toolkit](https://redux-toolkit.js.org/) template. -## Available Scripts +All associated developer scripts apply. -In the project directory, you can run: - -### `npm start` - -Runs the app in the development mode.
-Open [http://localhost:3000](http://localhost:3000) to view it in the browser. - -The page will reload if you make edits.
-You will also see any lint errors in the console. - -### `npm test` - -Launches the test runner in the interactive watch mode.
-See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. - -### `npm run build` - -Builds the app for production to the `build` folder.
-It correctly bundles React in production mode and optimizes the build for the best performance. - -The build is minified and the filenames include the hashes.
-Your app is ready to be deployed! - -See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. - -### `npm run eject` - -**Note: this is a one-way operation. Once you `eject`, you can’t go back!** - -If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. - -Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. - -You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. - -## Learn More - -You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). - -To learn React, check out the [React documentation](https://reactjs.org/). +Related documentation can be found [here]((https://facebook.github.io/create-react-app/docs/getting-started)). \ No newline at end of file From a77adade9f8c4fcad58e965bc803c7df27072132 Mon Sep 17 00:00:00 2001 From: Mikayla Dobson Date: Sun, 30 Jan 2022 12:54:51 -0600 Subject: [PATCH 2/5] building out feed page system --- README.md | 2 +- src/features/posts/Feed.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7409736..cf20909 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Additional features implemented include: ## Changelog: -### Version 0.1, 01/30/2022 +### Version 0, 01/30/2022 First project build! diff --git a/src/features/posts/Feed.js b/src/features/posts/Feed.js index 1ad0345..ba093b9 100644 --- a/src/features/posts/Feed.js +++ b/src/features/posts/Feed.js @@ -10,6 +10,9 @@ export default function Feed() { const [endpoints, setEndpoints] = useState(null); // Expects to receive an array of endpoints from which to fetch the posts const [data, setData] = useState(null); // Receives data from getPosts and them maps it onto Post components const [feed, setFeed] = useState(null); // Expects to receive an array of Post components mapped with data from fetchBySub + + const [feedPage, setFeedPage] = useState(['']); // Expects an array of arrays (pages of feed posts) + const [currentPage, setCurrentPage] = useState(0); const dispatch = useDispatch(); // const posts = useSelector(selectPosts); From b5be28b14ae213e135a04724f5ce439473f6c282 Mon Sep 17 00:00:00 2001 From: Mikayla Dobson Date: Sun, 30 Jan 2022 14:16:12 -0600 Subject: [PATCH 3/5] divides feed into pages, introduces primitive page change system --- src/features/posts/Feed.js | 115 +++++++++++++++++++++++++++++++++++-- 1 file changed, 109 insertions(+), 6 deletions(-) diff --git a/src/features/posts/Feed.js b/src/features/posts/Feed.js index ba093b9..2452d64 100644 --- a/src/features/posts/Feed.js +++ b/src/features/posts/Feed.js @@ -11,8 +11,8 @@ export default function Feed() { const [data, setData] = useState(null); // Receives data from getPosts and them maps it onto Post components const [feed, setFeed] = useState(null); // Expects to receive an array of Post components mapped with data from fetchBySub - const [feedPage, setFeedPage] = useState(['']); // Expects an array of arrays (pages of feed posts) - const [currentPage, setCurrentPage] = useState(0); + const [feedPages, setFeedPages] = useState(null); // Expects an array of arrays (pages of feed posts) + const [currentPage, setCurrentPage] = useState(0); // Determines current feed page; corresponds to index of feedPage array const dispatch = useDispatch(); // const posts = useSelector(selectPosts); @@ -70,8 +70,6 @@ export default function Feed() { } }; - console.log(extractedPosts); - const comparePosts = (a,b) => { // sorting function: compares time posted within each object in array if (a.data.created_utc > b.data.created_utc) { return -1; @@ -90,8 +88,9 @@ export default function Feed() { data={post.data} key={v4()} /> - ); + ) }) + // dispatch(updatePosts(newFeed)); // stores current feed in state of postsSlice setFeed(newFeed); } @@ -108,9 +107,113 @@ export default function Feed() { }, [data, setFeed, dispatch]); + + useEffect(() => { + let isActive = false; + + if (!feed) { + isActive = false; + } else if (feed) { + isActive = true; + } + + if (isActive) { + try { + let allPages = []; + for (let i = 0; i < feed.length; i += 10) { + let indivPage = []; + indivPage = feed.slice(i,i+10); + allPages.push(indivPage); + } + setFeedPages(allPages); + } catch(e) { + console.log(e); + } + } + + return () => { + isActive = false; + } + },[feed, setFeedPages]); + + + // useEffect(() => { // this loops handles mapping the feed onto individual pages, + // let isActive = true; // allowing the application to render subsets of the whole feed at once, reducing render times + + // const doPages = async () => { + // try { + // let localFeed = await feed; + + // if (localFeed) { + // for (let i = 0; i < feed.length; i += 10) { + // let allPages = []; + // for (let j = 0; j < 10; j++) { + // let indivPage = []; + // if (feed[i+j]) { + // indivPage.push(feed[i+j]) + // } else { + // return; + // } + // allPages.push(indivPage); + // } + // setFeedPages(allPages); + // } + // } + // } catch(e) { + // console.log(e); + // } + // } + + // if (isActive && feed) { + // doPages(); + // } + + // return () => { + // isActive = false; + // } + + // }, [feed, feedPages]); + + const handleIncrement = () => { + if (currentPage + 1 > feedPages.length) { + return; + } else { + setCurrentPage((prev) => prev+1); + window.scrollTo(0,0); + } + } + + const handleDecrement = () => { + if (currentPage - 1 < 0) { + return; + } else { + setCurrentPage((prev) => prev-1); + window.scrollTo(0,0); + } + } + return ( <> - {feed ? feed :

Loading cats for you...

} + {feedPages ? + +
+ +

Page {currentPage} of {feedPages.length ? feedPages.length : 'unknown'}

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

Loading cats for you...

} + {feedPages ? + +
+ +

Page {currentPage} of {feedPages.length ? feedPages.length : 'unknown'}

+ +
+ + : null } ); } \ No newline at end of file From f797ea784f1c1103bdb714e9b8926f975991b4a3 Mon Sep 17 00:00:00 2001 From: Mikayla Dobson Date: Sun, 30 Jan 2022 14:27:49 -0600 Subject: [PATCH 4/5] page handling object better styled --- src/App.css | 44 ++++++++++++++++++++++++++++++++++++++ src/features/posts/Feed.js | 4 ++-- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/App.css b/src/App.css index f4760fb..136efa4 100644 --- a/src/App.css +++ b/src/App.css @@ -79,6 +79,10 @@ width: 6rem; } +.sidebar-button:hover { + background-color: rgb(218, 171, 216); +} + .sidebar-button:active { background-color: darkorchid; transition: background-color 35ms linear; @@ -131,4 +135,44 @@ display: hidden; flex-direction: column; align-items: center; +} + +.page-handling { + display: inline-flex; + flex-direction: row; + align-items: center; + justify-content: space-between; + padding: 2rem; + background-color: orchid; + border-radius: 15px; + width: 50%; + height: 3rem; +} + +.page-handling button { + background-color: rgb(218, 171, 216); + border: transparent; + border-radius: 50%; + height: 3.5rem; + width: 3.5rem; + box-shadow:2rem rgb(111, 30, 151); +} + +.page-handling button:hover { + background-color: rgb(202, 186, 201); +} + +.page-handling button:active { + background-color: rgb(247, 233, 246); +} + +#top-page-handling { + margin-bottom: -1rem; + margin-top: 2rem; +} + +#bottom-page-handling { + margin-top: 5rem; + position: relative; + bottom: 6rem; } \ No newline at end of file diff --git a/src/features/posts/Feed.js b/src/features/posts/Feed.js index 2452d64..6d8cdf7 100644 --- a/src/features/posts/Feed.js +++ b/src/features/posts/Feed.js @@ -196,7 +196,7 @@ export default function Feed() { <> {feedPages ? -
+

Page {currentPage} of {feedPages.length ? feedPages.length : 'unknown'}

@@ -207,7 +207,7 @@ export default function Feed() { {feedPages ? feedPages[currentPage] :

Loading cats for you...

} {feedPages ? -
+

Page {currentPage} of {feedPages.length ? feedPages.length : 'unknown'}

From 015553e23bf06225101542ad0df99dde15d0154b Mon Sep 17 00:00:00 2001 From: Mikayla Dobson Date: Sun, 30 Jan 2022 14:31:01 -0600 Subject: [PATCH 5/5] preparing to push --- src/App.css | 1 + src/features/posts/Feed.js | 51 ++++++-------------------------------- 2 files changed, 8 insertions(+), 44 deletions(-) diff --git a/src/App.css b/src/App.css index 136efa4..95c0ed7 100644 --- a/src/App.css +++ b/src/App.css @@ -6,6 +6,7 @@ * Navbar styles * Sidebar styles * Feed styles +* Media queries *****/ /* Google Fonts imports: */ diff --git a/src/features/posts/Feed.js b/src/features/posts/Feed.js index 6d8cdf7..b23f3d5 100644 --- a/src/features/posts/Feed.js +++ b/src/features/posts/Feed.js @@ -117,16 +117,16 @@ export default function Feed() { isActive = true; } - if (isActive) { + if (isActive) { // iterates through the total array of posts, stored in feed try { let allPages = []; - for (let i = 0; i < feed.length; i += 10) { - let indivPage = []; + for (let i = 0; i < feed.length; i += 10) { // maps through them in sets of ten, + let indivPage = []; // stores them in a corresponding inner page array, indivPage = feed.slice(i,i+10); allPages.push(indivPage); } - setFeedPages(allPages); - } catch(e) { + setFeedPages(allPages); // then stores them in an encompassing array of page arrays, as + } catch(e) { // stateful variable "feedPages". console.log(e); } } @@ -137,49 +137,12 @@ export default function Feed() { },[feed, setFeedPages]); - // useEffect(() => { // this loops handles mapping the feed onto individual pages, - // let isActive = true; // allowing the application to render subsets of the whole feed at once, reducing render times - - // const doPages = async () => { - // try { - // let localFeed = await feed; - - // if (localFeed) { - // for (let i = 0; i < feed.length; i += 10) { - // let allPages = []; - // for (let j = 0; j < 10; j++) { - // let indivPage = []; - // if (feed[i+j]) { - // indivPage.push(feed[i+j]) - // } else { - // return; - // } - // allPages.push(indivPage); - // } - // setFeedPages(allPages); - // } - // } - // } catch(e) { - // console.log(e); - // } - // } - - // if (isActive && feed) { - // doPages(); - // } - - // return () => { - // isActive = false; - // } - - // }, [feed, feedPages]); - - const handleIncrement = () => { + const handleIncrement = () => { // handles the logic of setting the current page value if (currentPage + 1 > feedPages.length) { return; } else { setCurrentPage((prev) => prev+1); - window.scrollTo(0,0); + window.scrollTo(0,0); // includes a "send to top of page" feature on click } }