From 610ea65c671906f71bd6ececc93d0ce24d048fdb Mon Sep 17 00:00:00 2001 From: Tom Date: Tue, 25 Apr 2023 21:30:10 +0200 Subject: [PATCH] fix all eslint warnings --- src/App.js | 6 +- src/components/Post.jsx | 44 +++++++------- src/components/ReplyModal.jsx | 4 +- src/components/styled/Board.styled.jsx | 59 ++++++++++++++----- src/components/styled/CaptchaModal.styled.jsx | 5 +- src/components/styled/ReplyModal.styled.jsx | 5 +- .../styled/SettingsModal.styled.jsx | 6 +- src/components/styled/Thread.styled.jsx | 40 +++++++++---- src/components/views/Board.jsx | 9 ++- src/components/views/Catalog.jsx | 8 +-- src/components/views/Pending.jsx | 3 +- src/components/views/Thread.jsx | 30 +++++----- src/hooks/useError.js | 4 +- src/hooks/useSuccess.js | 4 +- 14 files changed, 144 insertions(+), 83 deletions(-) diff --git a/src/App.js b/src/App.js index 11a3daef..9f9a3625 100644 --- a/src/App.js +++ b/src/App.js @@ -125,7 +125,7 @@ export default function App() { return () => { darkModeMediaQuery.removeEventListener('change', darkModeListener); }; - }, [isHomeRoute]); + }, [isHomeRoute, setBodyStyle, setSelectedStyle]); // fetch default subplebbits useEffect(() => { @@ -143,7 +143,7 @@ export default function App() { return () => { didCancel = true; }; - }, []); + }, [setDefaultSubplebbits]); // handle nested routes useEffect(() => { @@ -162,7 +162,7 @@ export default function App() { setIsSettingsOpen(false); } - }, [location.pathname]); + }, [location.pathname, setIsSettingsOpen, setShowPostForm, setShowPostFormLink]); return (
diff --git a/src/components/Post.jsx b/src/components/Post.jsx index 8ddb71f6..c9178fa1 100644 --- a/src/components/Post.jsx +++ b/src/components/Post.jsx @@ -1,6 +1,6 @@ import React from 'react'; import ReactMarkdown from 'react-markdown'; -import { Link } from 'react-router-dom'; +// import { Link } from 'react-router-dom'; import rehypeSanitize from 'rehype-sanitize'; import breaks from 'remark-breaks'; @@ -28,28 +28,28 @@ const blockquoteToGreentext = () => (tree) => { }); }; -const createQuotelink = (handlequoteclick, comment, children) => { - const text = children.map((child) => (typeof child === 'string' ? child : child.props.children)).join(''); - const regex = /(\s|^)(c\/[A-Za-z0-9]{12}|c\/[A-Za-z0-9]{45})(?=\s|$)/g; - const parts = text.split(regex); +// const createQuotelink = (handlequoteclick, comment, children) => { +// const text = children.map((child) => (typeof child === 'string' ? child : child.props.children)).join(''); +// const regex = /(\s|^)(c\/[A-Za-z0-9]{12}|c\/[A-Za-z0-9]{45})(?=\s|$)/g; +// const parts = text.split(regex); - return parts.flatMap((part, i) => { - if (regex.test(part)) { - return [ - - {part.trim()} - , - ]; - } else { - return [part]; - } - }); -}; +// return parts.flatMap((part, i) => { +// if (regex.test(part)) { +// return [ +// +// {part.trim()} +// , +// ]; +// } else { +// return [part]; +// } +// }); +// }; const Post = ({ content, handlequoteclick, comment }) => { diff --git a/src/components/ReplyModal.jsx b/src/components/ReplyModal.jsx index 4fa141df..9e3544f8 100644 --- a/src/components/ReplyModal.jsx +++ b/src/components/ReplyModal.jsx @@ -83,7 +83,7 @@ const ReplyModal = ({ isOpen, closeModal }) => { if (index !== undefined) { setPendingCommentIndex(index); } - }, [index, location]); + }, [index, location, setPendingCommentIndex]); const resetFields = () => { @@ -116,7 +116,7 @@ const ReplyModal = ({ isOpen, closeModal }) => { closeModal(); })(); } - }, [publishCommentOptions]); + }, [publishCommentOptions, closeModal, publishComment]); const getChallengeAnswersFromUser = async (challenges) => { diff --git a/src/components/styled/Board.styled.jsx b/src/components/styled/Board.styled.jsx index 9398ff87..2a52a05b 100644 --- a/src/components/styled/Board.styled.jsx +++ b/src/components/styled/Board.styled.jsx @@ -220,7 +220,10 @@ export const NavBar = styled.div` background-color: #ddd; border-bottom: 2px solid #ccc; }`; - } + + default: + return ''; + } }}`; export const Header = styled.div` @@ -410,7 +413,10 @@ export const Header = styled.div` margin-top: 5px; font-size: 9pt; }`; - } + + default: + return ''; + } }} `; @@ -445,8 +451,11 @@ export const Break = styled.hr` return `width: 90%; border: none; border-top: 1px solid #ddd; - height: 0;`; - } + height: 0;`; + + default: + return ''; + } }} `; @@ -600,7 +609,9 @@ export const PostFormLink = styled.div` color: #333 !important; white-space: nowrap; }`; - + + default: + return ''; } }} `; @@ -1123,7 +1134,10 @@ export const PostFormTable = styled.table` width: 100% } }`; - } + + default: + return ''; + } }} #t-help { @@ -1224,8 +1238,10 @@ export const PostForm = styled.div` a:hover { color: #ff3300; }`; - - } + + default: + return ''; + } }} `; @@ -1369,8 +1385,10 @@ export const TopBar = styled.div` a:hover { color: #ff3300; }`; - - } + + default: + return ''; + } }} @media (min-width: 480px) { @@ -1533,6 +1551,9 @@ export const TopBar = styled.div` color: #333 !important; white-space: nowrap; }`; + + default: + return ''; } }} `; @@ -1598,8 +1619,10 @@ export const BoardForm = styled.div` background-color: #ccc !important; border: 1px solid #ccc !important; }`; - - } + + default: + return ''; + } }} } @@ -2873,8 +2896,10 @@ export const BoardForm = styled.div` border-top: 1px solid #ddd; height: 0; }`; - - } + + default: + return ''; + } }} @media (max-width: 480px) { @@ -2934,6 +2959,9 @@ export const BoardForm = styled.div` return `.highlighted { background-color: #ccc !important; }`; + + default: + return ''; } }} @@ -3635,6 +3663,9 @@ export const BoardForm = styled.div` } } }`; + + default: + return ''; } }} } diff --git a/src/components/styled/CaptchaModal.styled.jsx b/src/components/styled/CaptchaModal.styled.jsx index 2b30e05c..6a23701d 100644 --- a/src/components/styled/CaptchaModal.styled.jsx +++ b/src/components/styled/CaptchaModal.styled.jsx @@ -236,6 +236,9 @@ export const StyledModal = styled(Modal)` span { color: #333; }`; - } + + default: + return ''; + } }} `; \ No newline at end of file diff --git a/src/components/styled/ReplyModal.styled.jsx b/src/components/styled/ReplyModal.styled.jsx index 4c6c086d..ca3dde3e 100644 --- a/src/components/styled/ReplyModal.styled.jsx +++ b/src/components/styled/ReplyModal.styled.jsx @@ -254,6 +254,9 @@ export const StyledModal = styled(Modal)` span { color: #000; }`; - } + + default: + return ''; + } }} `; \ No newline at end of file diff --git a/src/components/styled/SettingsModal.styled.jsx b/src/components/styled/SettingsModal.styled.jsx index a70c47ae..5360553a 100644 --- a/src/components/styled/SettingsModal.styled.jsx +++ b/src/components/styled/SettingsModal.styled.jsx @@ -364,7 +364,9 @@ export const StyledModal = styled(Modal)` color: #f30 !important; } }`; - - } + + default: + return ''; + } }} `; \ No newline at end of file diff --git a/src/components/styled/Thread.styled.jsx b/src/components/styled/Thread.styled.jsx index 49c6389e..60e04acb 100644 --- a/src/components/styled/Thread.styled.jsx +++ b/src/components/styled/Thread.styled.jsx @@ -164,6 +164,9 @@ export const ReplyFormLink = styled.div` color: #333 !important; white-space: nowrap; }`; + + default: + return ''; } }} `; @@ -386,7 +389,8 @@ export const TopBar = styled.div` color: #ff3300 !important; } }`; - + default: + return ''; } }} @@ -514,7 +518,9 @@ export const TopBar = styled.div` color: #333 !important; white-space: nowrap; }`; - + + default: + return ''; } }} `; @@ -678,7 +684,9 @@ export const BottomBar = styled.div` padding-bottom: 5px; padding-top: 5px; }`; - + + default: + return ''; } }} `; @@ -735,16 +743,17 @@ export const BoardForm = styled.div` return `.highlighted { background-color: #1d1d21 !important; border: 1px solid #111 !important; - } -`; + }`; case 'Photon': return `.highlighted { background-color: #ccc !important; border: 1px solid #ccc !important; }`; - - } + + default: + return ''; + } }} } @@ -2018,7 +2027,9 @@ export const BoardForm = styled.div` border-top: 1px solid #ddd; height: 0; }`; - + + default: + return ''; } }} @@ -2079,7 +2090,10 @@ export const BoardForm = styled.div` return `.highlighted { background-color: #ccc !important; }`; - } + + default: + return ''; + } }} ${({ selectedStyle }) => { @@ -2780,6 +2794,9 @@ export const BoardForm = styled.div` } } }`; + + default: + return ''; } }} } @@ -2896,6 +2913,9 @@ export const Footer = styled.div` color: #f30; } }`; - } + + default: + return ''; + } }} `; \ No newline at end of file diff --git a/src/components/views/Board.jsx b/src/components/views/Board.jsx index 055473b7..44c0dff1 100644 --- a/src/components/views/Board.jsx +++ b/src/components/views/Board.jsx @@ -207,7 +207,7 @@ const Board = () => { setPendingCommentIndex(index); navigate(`/profile/c/${index}`); } - }, [index]); + }, [index, navigate, setPendingCommentIndex]); const resetFields = () => { @@ -240,7 +240,7 @@ const Board = () => { resetFields(); })(); } - }, [publishCommentOptions]); + }, [publishCommentOptions, publishComment]); const getChallengeAnswersFromUser = async (challenges) => { @@ -369,12 +369,12 @@ const Board = () => {
[ - event.target.style.cursor='pointer'}>Start a New Thread + {}} onClick={useClickForm()} onMouseOver={(event) => event.target.style.cursor='pointer'}>Start a New Thread ]
- event.target.style.cursor='pointer'}>Start a New Thread + {}} onClick={useClickForm()} onMouseOver={(event) => event.target.style.cursor='pointer'}>Start a New Thread
@@ -452,7 +452,6 @@ const Board = () => { hasMore={hasMore} > {selectedFeed.map((thread) => { - const { replies: { pages: { topAll: {} = {} } = {} } = {} } = thread; const { displayedReplies, omittedCount } = filteredRepliesByThread[thread.cid] || {}; const commentMediaInfo = getCommentMediaInfo(thread); const fallbackImgUrl = "/assets/filedeleted-res.gif"; diff --git a/src/components/views/Catalog.jsx b/src/components/views/Catalog.jsx index 368a9b49..ee1f9640 100644 --- a/src/components/views/Catalog.jsx +++ b/src/components/views/Catalog.jsx @@ -133,7 +133,7 @@ const Catalog = () => { setPendingCommentIndex(index); navigate(`/profile/c/${index}`); } - }, [index]); + }, [index, navigate, setPendingCommentIndex]); const resetFields = () => { @@ -166,7 +166,7 @@ const Catalog = () => { resetFields(); })(); } - }, [publishCommentOptions]); + }, [publishCommentOptions, publishComment]); const getChallengeAnswersFromUser = async (challenges) => { @@ -284,12 +284,12 @@ const Catalog = () => {
[ - event.target.style.cursor='pointer'}>Start a New Thread + {}} onClick={useClickForm()} onMouseOver={(event) => event.target.style.cursor='pointer'}>Start a New Thread ]
- event.target.style.cursor='pointer'}>Start a New Thread + {}} onClick={useClickForm()} onMouseOver={(event) => event.target.style.cursor='pointer'}>Start a New Thread
diff --git a/src/components/views/Pending.jsx b/src/components/views/Pending.jsx index b59f0d70..b279b89a 100644 --- a/src/components/views/Pending.jsx +++ b/src/components/views/Pending.jsx @@ -184,7 +184,8 @@ const Pending = () => {
Link:  - { + { commentMediaInfo?.url.length > 30 ? commentMediaInfo?.url.slice(0, 30) + "(...)" : commentMediaInfo?.url diff --git a/src/components/views/Thread.jsx b/src/components/views/Thread.jsx index bedd6226..420b29f4 100644 --- a/src/components/views/Thread.jsx +++ b/src/components/views/Thread.jsx @@ -75,7 +75,7 @@ const Thread = () => { parentCids: [ selectedThread || 'n/a', ...flattenedReplies.map(reply => reply.cid) ] - }), [flattenedReplies]); + }), [flattenedReplies, selectedThread]); const { accountComments } = useAccountComments({filter}); @@ -100,7 +100,7 @@ const Thread = () => { if (selectedSubplebbit) { setSelectedTitle(selectedSubplebbit.title); } - }, [subplebbitAddress, setSelectedAddress, setSelectedTitle, defaultSubplebbits]); + }, [subplebbitAddress, setSelectedAddress, setSelectedTitle, defaultSubplebbits, setSelectedThread, threadCid]); // mobile navbar scroll effect useEffect(() => { @@ -167,7 +167,7 @@ const Thread = () => { if (index !== undefined) { setPendingCommentIndex(index); } - }, [index]); + }, [index, setPendingCommentIndex]); const resetFields = () => { @@ -199,7 +199,7 @@ const Thread = () => { resetFields(); })(); } - }, [publishCommentOptions]); + }, [publishCommentOptions, publishComment]); const getChallengeAnswersFromUser = async (challenges) => { @@ -338,17 +338,17 @@ const Thread = () => {
[ - {handleClickForm(); setSelectedShortCid(comment.shortCid)}} onMouseOver={(event) => event.target.style.cursor='pointer'}>Post a Reply + {}} onClick={() => {handleClickForm(); setSelectedShortCid(comment.shortCid)}} onMouseOver={(event) => event.target.style.cursor='pointer'}>Post a Reply ]
- {handleClickForm(); setSelectedShortCid(comment.shortCid)}} onMouseOver={(event) => event.target.style.cursor='pointer'}>Post a Reply + {}} onClick={() => {handleClickForm(); setSelectedShortCid(comment.shortCid)}} onMouseOver={(event) => event.target.style.cursor='pointer'}>Post a Reply
@@ -407,7 +407,7 @@ const Thread = () => { [ - window.scrollTo(0, document.body.scrollHeight)} + {}} onClick={() => window.scrollTo(0, document.body.scrollHeight)} onMouseOver={(event) => event.target.style.cursor='pointer'} onTouchStart={() => window.scrollTo(0, document.body.scrollHeight)}>Bottom ] @@ -443,7 +443,8 @@ const Thread = () => {
Link:  - { + { commentMediaInfo?.url.length > 30 ? commentMediaInfo?.url.slice(0, 30) + "(...)" : commentMediaInfo?.url @@ -628,7 +629,8 @@ const Thread = () => { style={{marginBottom: "5px"}}>
Link:  - { + { replyMediaInfo?.url.length > 30 ? replyMediaInfo?.url.slice(0, 30) + "(...)" : replyMediaInfo?.url @@ -917,14 +919,14 @@ const Thread = () => { [ - window.scrollTo(0, 0)} + {}} onClick={() => window.scrollTo(0, 0)} onMouseOver={(event) => event.target.style.cursor='pointer'} onTouchStart={() => window.scrollTo(0, 0)}>Top ] [ - {setIsReplyOpen(true); setSelectedParentCid(comment.cid); setSelectedShortCid(comment.shortCid);}} onMouseOver={(event) => event.target.style.cursor='pointer'}>Post a Reply + {}} onClick={() => {setIsReplyOpen(true); setSelectedParentCid(comment.cid); setSelectedShortCid(comment.shortCid);}} onMouseOver={(event) => event.target.style.cursor='pointer'}>Post a Reply ] {comment.replyCount > 0 ? ( @@ -973,7 +975,7 @@ const Thread = () => {
- {setIsReplyOpen(true); setSelectedParentCid(comment.cid); setSelectedShortCid(comment.shortCid);}} onMouseOver={(event) => event.target.style.cursor='pointer'}>Post a Reply + {}} onClick={() => {setIsReplyOpen(true); setSelectedParentCid(comment.cid); setSelectedShortCid(comment.shortCid);}} onMouseOver={(event) => event.target.style.cursor='pointer'}>Post a Reply
@@ -989,7 +991,7 @@ const Thread = () => {
- window.scrollTo(0, 0)} + {}} onClick={() => window.scrollTo(0, 0)} onMouseOver={(event) => event.target.style.cursor='pointer'} onTouchStart={() => window.scrollTo(0, 0)} style={{marginRight: "10px", marginLeft: "10px"}} diff --git a/src/hooks/useError.js b/src/hooks/useError.js index 1264d072..6fa6a26d 100644 --- a/src/hooks/useError.js +++ b/src/hooks/useError.js @@ -1,7 +1,7 @@ import { useEffect } from "react"; import { toast } from "react-toastify"; -const useError = (message, deps) => { +const useError = (message) => { useEffect(() => { if (message) { const toastId = toast.error(message.toString(), { @@ -19,7 +19,7 @@ const useError = (message, deps) => { toast.dismiss(toastId); }; } - }, deps); + }, [message]); }; export default useError; \ No newline at end of file diff --git a/src/hooks/useSuccess.js b/src/hooks/useSuccess.js index 8e87a53c..7e182a86 100644 --- a/src/hooks/useSuccess.js +++ b/src/hooks/useSuccess.js @@ -1,7 +1,7 @@ import { useEffect } from "react"; import { toast } from "react-toastify"; -const useSuccess = (message, deps) => { +const useSuccess = (message) => { useEffect(() => { if (message) { const toastId = toast.success(message.toString(), { @@ -19,7 +19,7 @@ const useSuccess = (message, deps) => { toast.dismiss(toastId); }; } - }, deps); + }, [message]); }; export default useSuccess; \ No newline at end of file