error handling

This commit is contained in:
2022-01-30 11:26:39 -06:00
parent 2225c22abb
commit 8195e98058
4 changed files with 5 additions and 13 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View File

@@ -24,7 +24,7 @@
work correctly both with client-side routing and a non-root public URL. work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`. Learn how to configure a non-root public URL by running `npm run build`.
--> -->
<title>React Redux App</title> <title>Cat Reddit</title>
</head> </head>
<body> <body>
<noscript>You need to enable JavaScript to run this app.</noscript> <noscript>You need to enable JavaScript to run this app.</noscript>

View File

@@ -1,8 +1,8 @@
import React, { useState, useEffect } from "react"; import React, { useState, useEffect } from "react";
import { fetchBySub, selectPosts } from "./postsSlice"; import { fetchBySub, /* selectPosts */ } from "./postsSlice";
import { selectAllSubs } from "../reddit/redditSlice"; import { selectAllSubs } from "../reddit/redditSlice";
import { useSelector, useDispatch } from "react-redux"; import { useSelector, useDispatch } from "react-redux";
import { updatePosts } from "./postsSlice"; // import { updatePosts } from "./postsSlice";
import { v4 } from "uuid"; import { v4 } from "uuid";
import Post from "./Post"; import Post from "./Post";
@@ -12,7 +12,7 @@ export default function Feed() {
const [feed, setFeed] = useState(null); // Expects to receive an array of Post components mapped with data from fetchBySub const [feed, setFeed] = useState(null); // Expects to receive an array of Post components mapped with data from fetchBySub
const dispatch = useDispatch(); const dispatch = useDispatch();
const posts = useSelector(selectPosts); // const posts = useSelector(selectPosts);
const subs = useSelector(selectAllSubs); // Selects subreddits from redditSlice 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" useEffect(() => { // this useEffect loop pulls the endpoints from the selected subreddits and stores them as an array in "endpoints"
@@ -38,8 +38,6 @@ export default function Feed() {
useEffect(() => { // once this is done, this loop pulls posts from each endpoint useEffect(() => { // once this is done, this loop pulls posts from each endpoint
let isActive = true;
const getPosts = async(arr) => { const getPosts = async(arr) => {
if (endpoints) { if (endpoints) {
const mappedResults = arr.map(each => dispatch(fetchBySub(each))); // maps each endpoint into a call to dispatch fetchBySub const mappedResults = arr.map(each => dispatch(fetchBySub(each))); // maps each endpoint into a call to dispatch fetchBySub
@@ -50,11 +48,6 @@ export default function Feed() {
} }
getPosts(endpoints); getPosts(endpoints);
return () => {
isActive = false;
}
}, [dispatch, setData, endpoints]); }, [dispatch, setData, endpoints]);
useEffect(() => { useEffect(() => {

View File

@@ -1,5 +1,5 @@
import React, { useState, useEffect } from "react"; import React, { useState, useEffect } from "react";
import { useDispatch } from "react-redux"; // import { useDispatch } from "react-redux";
import Discussion from "../discussion/Discussion"; import Discussion from "../discussion/Discussion";
import './Post.css'; import './Post.css';
@@ -20,7 +20,6 @@ export default function Post({data, key}) {
const [body, setBody] = useState(selftext); const [body, setBody] = useState(selftext);
const [visible, setVisible] = useState('show '); const [visible, setVisible] = useState('show ');
const [commentStyle, setCommentStyle] = useState('comments-hidden'); const [commentStyle, setCommentStyle] = useState('comments-hidden');
const [crosspost, setCrosspost] = useState(undefined);
const postDate = new Date(time * 1000); // handles conversion from unix timestamp to local time and date strings const postDate = new Date(time * 1000); // handles conversion from unix timestamp to local time and date strings
const localTime = postDate.toLocaleTimeString(); const localTime = postDate.toLocaleTimeString();