Skip to content

Commit 6492a31

Browse files
committed
fix dep errors
1 parent 9001304 commit 6492a31

File tree

3 files changed

+35
-37
lines changed

3 files changed

+35
-37
lines changed

devblog/devblog/ClientApp/src/components/Notifications.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const Notification = ({ setBellDisplay, handleBellClick,
4848
}, 300);
4949
}
5050

51-
const handleClick = async (postId: number) => {
51+
const handleNotificationClick = async (postId: number) => {
5252
await fetch(`api/posts/getPageNum/${postId}`)
5353
.then((res) => { return res.json() })
5454
.then((data) => {
@@ -82,9 +82,9 @@ const Notification = ({ setBellDisplay, handleBellClick,
8282
<div className="notifications" style={{ display: bellDisplay }} >
8383
{notifications?.map((n) => <>
8484
<div className={`notification-item ${dismissedNotifications.includes(n.postId) ? 'dismissed' : ''}`}>
85-
<span onClick={() => handleClick(n.postId)}><img src={n.imgUrl} alt="post thumbnail" /></span>
85+
<span onClick={() => handleNotificationClick(n.postId)}><img src={n.imgUrl} alt="post thumbnail" /></span>
8686
<div className="notification-txt">
87-
<span onClick={() => handleClick(n.postId)}>{n.userName} posted</span>
87+
<span onClick={() => handleNotificationClick(n.postId)}>{n.userName} posted</span>
8888
<span onClick={() => deleteNotification(n.postId, n.userName)}>dismiss</span>
8989
</div>
9090
</div>

devblog/devblog/ClientApp/src/components/Post.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import ICommentProps from "../interfaces/ICommentProps";
77
import ReactMarkdown from "react-markdown";
88
import Vote from "./Vote";
99
import { Carousel } from 'react-responsive-carousel';
10-
import "react-responsive-carousel/lib/styles/carousel.min.css"; // requires a loader
10+
import "react-responsive-carousel/lib/styles/carousel.min.css";
1111
import "./styles/Post.css";
1212
import EditPost from "./EditPost";
1313
import { GetIsAdmin } from "./AuthenticationService";

devblog/devblog/ClientApp/src/pages/Posts.tsx

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,32 @@ const Posts = () => {
1616
const location = useLocation();
1717
const searchParams = new URLSearchParams(location.search);
1818
const pageParam = searchParams.get("pageNum");
19+
const postIdParam = searchParams.get("postId");
1920

21+
const handlePagerClick = (page: number) => {
22+
window.history.replaceState(null, '', '/posts');
23+
setPageNum(page);
24+
}
25+
26+
const Pager = () => {
27+
return <div className="pager">
28+
{pageNum > 1 ? (
29+
<MdChevronLeft className="arrow-visible" onClick={() => pageNum > 0 && handlePagerClick(pageNum - 1)} />
30+
) : (
31+
<MdChevronLeft className="arrow-hidden" />
32+
)}
33+
34+
<span>{pageNum}</span>
35+
36+
{pageNum < totalPages ? (
37+
<MdChevronRight className="arrow-visible" onClick={() => handlePagerClick(pageNum + 1)} />
38+
) : (
39+
<MdChevronRight className="arrow-hidden" />
40+
)}
41+
</div>
42+
}
43+
44+
// get all posts for a specific page
2045
useEffect(() => {
2146
fetch(`api/posts/page/${pageNum}`)
2247
.then((res) => { return res.json(); })
@@ -25,15 +50,19 @@ const Posts = () => {
2550

2651
}, [pageNum]);
2752

53+
// scroll to the selected post
2854
useEffect(() => {
2955
if (pageParam) {
3056
setPageNum(parseInt(pageParam));
3157

3258
setTimeout(() => {
33-
scrollToHash();
59+
const target = document.querySelector("#post" + postIdParam);
60+
if (target) {
61+
target.scrollIntoView({ behavior: "smooth" });
62+
}
3463
}, 1700);
3564
}
36-
}, []);
65+
}, [pageParam]);
3766

3867
useEffect(() => {
3968
setIsAdmin(GetIsAdmin);
@@ -50,37 +79,6 @@ const Posts = () => {
5079
}).catch((e) => console.log("Error retrieving post count: " + e));
5180
}, []);
5281

53-
const scrollToHash = () => {
54-
const postIdParam = searchParams.get("postId");
55-
const target = document.querySelector("#post" + postIdParam);
56-
if (target) {
57-
target.scrollIntoView({ behavior: "smooth" });
58-
}
59-
};
60-
61-
const handlePagerClick = (page: number) => {
62-
window.history.replaceState(null, '', '/posts');
63-
setPageNum(page);
64-
}
65-
66-
const Pager = () => {
67-
return <div className="pager">
68-
{pageNum > 1 ? (
69-
<MdChevronLeft className="arrow-visible" onClick={() => pageNum > 0 && handlePagerClick(pageNum - 1)} />
70-
) : (
71-
<MdChevronLeft className="arrow-hidden" />
72-
)}
73-
74-
<span>{pageNum}</span>
75-
76-
{pageNum < totalPages ? (
77-
<MdChevronRight className="arrow-visible" onClick={() => handlePagerClick(pageNum + 1)} />
78-
) : (
79-
<MdChevronRight className="arrow-hidden" />
80-
)}
81-
</div>
82-
}
83-
8482
return (
8583
<section className="posts">
8684
<Pager />

0 commit comments

Comments
 (0)