Feed pages #9
74
README.md
74
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, 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.<br />
|
||||
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
|
||||
|
||||
The page will reload if you make edits.<br />
|
||||
You will also see any lint errors in the console.
|
||||
|
||||
### `npm test`
|
||||
|
||||
Launches the test runner in the interactive watch mode.<br />
|
||||
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.<br />
|
||||
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.<br />
|
||||
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)).
|
||||
45
src/App.css
45
src/App.css
@@ -6,6 +6,7 @@
|
||||
* Navbar styles
|
||||
* Sidebar styles
|
||||
* Feed styles
|
||||
* Media queries
|
||||
*****/
|
||||
|
||||
/* Google Fonts imports: */
|
||||
@@ -79,6 +80,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 +136,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;
|
||||
}
|
||||
@@ -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 [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);
|
||||
@@ -67,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;
|
||||
@@ -87,8 +88,9 @@ export default function Feed() {
|
||||
data={post.data}
|
||||
key={v4()}
|
||||
/>
|
||||
);
|
||||
)
|
||||
})
|
||||
|
||||
// dispatch(updatePosts(newFeed)); // stores current feed in state of postsSlice
|
||||
setFeed(newFeed);
|
||||
}
|
||||
@@ -105,9 +107,76 @@ export default function Feed() {
|
||||
|
||||
}, [data, setFeed, dispatch]);
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
let isActive = false;
|
||||
|
||||
if (!feed) {
|
||||
isActive = false;
|
||||
} else if (feed) {
|
||||
isActive = true;
|
||||
}
|
||||
|
||||
if (isActive) { // iterates through the total array of posts, stored in feed
|
||||
try {
|
||||
let allPages = [];
|
||||
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); // then stores them in an encompassing array of page arrays, as
|
||||
} catch(e) { // stateful variable "feedPages".
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
return () => {
|
||||
isActive = false;
|
||||
}
|
||||
},[feed, setFeedPages]);
|
||||
|
||||
|
||||
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); // includes a "send to top of page" feature on click
|
||||
}
|
||||
}
|
||||
|
||||
const handleDecrement = () => {
|
||||
if (currentPage - 1 < 0) {
|
||||
return;
|
||||
} else {
|
||||
setCurrentPage((prev) => prev-1);
|
||||
window.scrollTo(0,0);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{feed ? feed : <h1 className="loading-message">Loading cats for you...</h1>}
|
||||
{feedPages ?
|
||||
|
||||
<div className="page-handling" id="top-page-handling">
|
||||
<button className="decrement" onClick={handleDecrement}>-</button>
|
||||
<p>Page {currentPage} of {feedPages.length ? feedPages.length : 'unknown'}</p>
|
||||
<button className="increment" onClick={handleIncrement}>+</button>
|
||||
</div>
|
||||
|
||||
: null }
|
||||
|
||||
{feedPages ? feedPages[currentPage] : <h1 className="loading-message">Loading cats for you...</h1>}
|
||||
{feedPages ?
|
||||
|
||||
<div className="page-handling" id="bottom-page-handling">
|
||||
<button className="decrement" onClick={handleDecrement}>-</button>
|
||||
<p>Page {currentPage} of {feedPages.length ? feedPages.length : 'unknown'}</p>
|
||||
<button className="increment" onClick={handleIncrement}>+</button>
|
||||
</div>
|
||||
|
||||
: null }
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user