From 0d41a9239909ba1a96e93dfbdc39474d039e3a53 Mon Sep 17 00:00:00 2001 From: GulSam00 Date: Sun, 6 Mar 2022 22:42:19 +0900 Subject: [PATCH 1/3] =?UTF-8?q?Feat=20:=20Alarm=20=EA=B8=80=20=EB=B0=94?= =?UTF-8?q?=EB=A1=9C=20=EA=B0=80=EA=B8=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Pages/AlarmPage/Components/AlarmBody.jsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Pages/AlarmPage/Components/AlarmBody.jsx b/src/Pages/AlarmPage/Components/AlarmBody.jsx index a25ddb4..716a7af 100644 --- a/src/Pages/AlarmPage/Components/AlarmBody.jsx +++ b/src/Pages/AlarmPage/Components/AlarmBody.jsx @@ -26,8 +26,7 @@ const AlarmBody = () => { const mainTextLen = 10; const moveArticles = articleId => { - alert('구현 중입니다!'); - // navi(`/article/${articleId}`); + navi(`/article/${articleId}`); }; const previewMainText = article => { @@ -68,7 +67,7 @@ const AlarmBody = () => { className="article" isRead={article.isRead} isNotice={false} - onClick={() => moveArticles(article.userId)} + onClick={() => moveArticles(article.articleId)} >
새 댓글
{previewMainText(article)}
From a8bf0fa6eef82c7f5fd9193bdb28ce3e2f0785ff Mon Sep 17 00:00:00 2001 From: GulSam00 Date: Wed, 9 Mar 2022 01:35:29 +0900 Subject: [PATCH 2/3] =?UTF-8?q?Feat=20:=20=EA=B2=8C=EC=8B=9C=ED=8C=90=20?= =?UTF-8?q?=EC=8A=A4=EC=9C=84=EC=B9=AD=20=EC=8B=9C=20=EB=AC=B4=ED=95=9C=20?= =?UTF-8?q?=EC=8A=A4=ED=81=AC=EB=A1=A4=20=EA=B5=AC=ED=98=84.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Components/PreviewArticle.jsx | 10 ++-- .../CategoryPage/Components/CategoryBody.jsx | 46 ++++++------------- 2 files changed, 19 insertions(+), 37 deletions(-) diff --git a/src/Components/PreviewArticle.jsx b/src/Components/PreviewArticle.jsx index ff47b36..4631e1c 100644 --- a/src/Components/PreviewArticle.jsx +++ b/src/Components/PreviewArticle.jsx @@ -7,10 +7,12 @@ import Styled from './PreviewArticle.styled'; const PreviewArticle = ({ article, isBestArticle, onClickArticle }) => { const getArticleTime = time => - dayjs(time).isSame(dayjs(), 'day') - ? dayjs(time).format('HH:mm') - : dayjs(time).format('MM/DD'); - const isNewArticle = time => dayjs().isBefore(dayjs(time).add(12, "hour")); + dayjs(time).isSame(dayjs(), 'day') + ? dayjs(time).format('HH:mm') + : dayjs(time).format('MM/DD'); + + const isNewArticle = time => dayjs().isBefore(dayjs(time).add(12, 'hour')); + isNewArticle(article.createdAt); return ( { // const [hasNextPage, setHasNextPage] = useState(true); let hasNextPage = true; const [target, setTarget] = useState(null); - const [curCate, setCurCate] = useState(''); const cateList = ['자유 게시판', '익명 게시판', '공지 게시판']; const loca = useLocation(); const navi = useNavigate(); @@ -36,37 +35,13 @@ const CategoryBody = () => { navi(`/article/${id}`); }; - // const setInitalArticles = async () => { - // setIsLoaded(true); - // const result = await ArticleService.getArticles(categoryId); - // console.log('result ,', result); - // const meta = result.meta; - // setArticles(result.data); - // setIsLoaded(false); - // setHasNextPage(meta.hasNextPage); - // hasNextPage = meta.hasNextPage; - // }; - const handleChangeCate = id => { navi(`/category/${parseInt(id) + 1}`); }; - - useEffect(() => { - if (categoryId > 3) { - alert('준비 중입니다!'); - navi('/'); - } - setCurCate(getCategoryByUrl(loca)); - }, [categoryId]); - - // 동기적으로 sleep하는 함수 - // const sleep = delay => { - // let start = new Date().getTime(); - // while (new Date().getTime() < start + delay); - // }; - const getMoreItem = async () => { + const getMoreArticles = async () => { if (!hasNextPage) return; + setIsLoaded(true); const result = await ArticleService.getArticles(categoryId, page); const newData = result.data; @@ -81,19 +56,24 @@ const CategoryBody = () => { const onIntersect = async ([entry], observer) => { if (entry.isIntersecting && !isLoaded) { + // console.log('page : ', page); + // console.log('cur article : ', articles); + // console.log('has nextPage : ', hasNextPage); observer.unobserve(entry.target); - await getMoreItem(); + await getMoreArticles(); observer.observe(entry.target); } }; + // 존재하지 않는 categortId 일 경우의 예외 처리, 하드 코딩. useEffect(() => { if (categoryId > 3) { - alert('준비 중입니다!'); - navi('/'); + navi('/error'); } - setCurCate(getCategoryByUrl(loca)); - }, []); + setArticles([]); + page = 1; + hasNextPage = true; + }, [categoryId]); useEffect(() => { let observer; @@ -105,7 +85,7 @@ const CategoryBody = () => { observer.observe(target); // observer가 해당 객체를 감시하여 변경된다면 onIntersect 콜백 함수를 실행할 것이다. } return () => observer && observer.disconnect(); // 주석 씌워도 잘 돌아가네? - }, [target]); + }, [target, categoryId]); return ( <> From a072c0cfffc594d9bd833534a6092f3fa8085166 Mon Sep 17 00:00:00 2001 From: GulSam00 Date: Wed, 9 Mar 2022 01:49:50 +0900 Subject: [PATCH 3/3] =?UTF-8?q?Modify=20:=20let=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EA=B4=80=EB=A6=AC=ED=95=98=EB=8A=94=20=EA=B0=92=20=EC=B4=88?= =?UTF-8?q?=EA=B8=B0=ED=99=94=20=EC=BD=94=EB=93=9C=20=EC=A0=9C=EA=B1=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Pages/CategoryPage/Components/CategoryBody.jsx | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Pages/CategoryPage/Components/CategoryBody.jsx b/src/Pages/CategoryPage/Components/CategoryBody.jsx index 249bd73..cdb90aa 100644 --- a/src/Pages/CategoryPage/Components/CategoryBody.jsx +++ b/src/Pages/CategoryPage/Components/CategoryBody.jsx @@ -56,9 +56,7 @@ const CategoryBody = () => { const onIntersect = async ([entry], observer) => { if (entry.isIntersecting && !isLoaded) { - // console.log('page : ', page); - // console.log('cur article : ', articles); - // console.log('has nextPage : ', hasNextPage); + // if (page === 1 && hasNextPage) console.log("리렌더링 확인") observer.unobserve(entry.target); await getMoreArticles(); observer.observe(entry.target); @@ -71,8 +69,9 @@ const CategoryBody = () => { navi('/error'); } setArticles([]); - page = 1; - hasNextPage = true; + // 리렌더링 되면서 let으로 선언한 page, hasNextPage가 자동으로 초기화 되므로 state만 초기화 주면 된다. + // page = 1; + // hasNextPage = true; }, [categoryId]); useEffect(() => {