From 2eb59621d352e5ce04a854fd0d11156254ed5de1 Mon Sep 17 00:00:00 2001 From: jundm Date: Wed, 23 Feb 2022 19:44:46 +0900 Subject: [PATCH] [FE]fix:add post answer like mutate --- backend/backend/settings/common.py | 2 +- frontend/README.md | 3 + frontend/components/Articles/ArticleList.tsx | 5 +- frontend/components/Articles/ArticleView.tsx | 27 ++++---- .../components/Articles/ArticleViewAnswer.tsx | 63 +++++++++---------- 5 files changed, 51 insertions(+), 49 deletions(-) diff --git a/backend/backend/settings/common.py b/backend/backend/settings/common.py index c0272cc..30c15ce 100644 --- a/backend/backend/settings/common.py +++ b/backend/backend/settings/common.py @@ -210,7 +210,7 @@ def get_secret(common, secrets=secrets): # JWT SIMPLE_JWT = { "AUTH_HEADER_TYPES": ("JWT",), - "ACCESS_TOKEN_LIFETIME": timedelta(minutes=15), + "ACCESS_TOKEN_LIFETIME": timedelta(minutes=30), "REFRESH_TOKEN_LIFETIME": timedelta(days=1), "ALGORITHM": "HS256", "SIGNING_KEY": SECRET_KEY, diff --git a/frontend/README.md b/frontend/README.md index d657879..8f225b6 100644 --- a/frontend/README.md +++ b/frontend/README.md @@ -23,3 +23,6 @@ axios https://axios-http.com/kr/docs/ formik https://formik.org/docs/overview spellchecker https://streetsidesoftware.com/vscode-spell-checker/docs/configuration/ + +남은기능 +404,내정보,댓글,대댓글 diff --git a/frontend/components/Articles/ArticleList.tsx b/frontend/components/Articles/ArticleList.tsx index 4eb0c0f..dd39eed 100644 --- a/frontend/components/Articles/ArticleList.tsx +++ b/frontend/components/Articles/ArticleList.tsx @@ -43,11 +43,10 @@ function ArticleList({ useEffect(() => { if (error) { - //! 중복이여도 없앨수가 없음 오류안나고 access토큰만 삭제되면 실행이 안됨 setVerifyToken(); - console.error(error.message); + // console.error(error.message); } - }, [error]); + }, [error, data]); const columns = [ { diff --git a/frontend/components/Articles/ArticleView.tsx b/frontend/components/Articles/ArticleView.tsx index adf2274..16a0efb 100644 --- a/frontend/components/Articles/ArticleView.tsx +++ b/frontend/components/Articles/ArticleView.tsx @@ -9,6 +9,7 @@ import { setVerifyToken } from "@utils/Cookies/TokenManager"; import axios from "axios"; import ArticleAnswerCreate from "./ArticleAnswerCreate"; import ArticleViewAnswer from "./ArticleViewAnswer"; +import { Div } from "@components/HeaderBig/styles"; interface ArticleViewProps { id: number; @@ -37,9 +38,8 @@ function ArticleView({ id }: ArticleViewProps) { const [answer, setAnswer] = useState(false); useEffect(() => { if (error) { - //! 중복이여도 없앨수가 없음 오류안나고 access토큰만 삭제되면 실행이 안됨 setVerifyToken(); - console.error(error.message); + // console.error(error.message); } }, [error, data]); @@ -120,16 +120,19 @@ function ArticleView({ id }: ArticleViewProps) { /> )} - {answered?.results?.map((answer: AnswerProps, index: number) => { - return ( - - ); - })} + {answered?.results?.map( + (answer: AnswerProps, index: number, children: any) => { + return ( + + ); + } + )}
-

{answer.title}

+

{answer?.title}

{/* eslint-disable */} avatar -
{answer?.author.username}
+
{answer?.author?.username}
{dayjs(answer?.created_at).format("MM-DD hh:mm")}
-
추천 {answer.likes}
+
추천 {data?.likes}

{nl2br(answer?.content)}

- {answer.isLikes ? ( + {data?.isLikes ? ( { - answerMutate((likes: any) => { - console.log(likes.results); - }); - // answerMutate( - // { - // ...answer, - // isLikes: false, - // likes: answer.likes - 1, - // }, - // false - // ); + mutate( + { + answer, + isLikes: false, + likes: data.likes - 1, + }, + false + ); await axios.delete( `${process.env.NEXT_PUBLIC_ENV_BASE_URL}posts/api/${id}/postComment/${answer?.id}/like/` ); @@ -76,29 +80,22 @@ function ArticleViewAnswer({ ) : ( { - answerMutate(async (likes: any) => { - console.log(likes.results); - return { - ...likes.results, - - } - }); - // answerMutate( - // { - // ...answer, - // isLikes: true, - // likes: answer.likes + 1, - // }, - // false - // ); + mutate( + { + answer, + isLikes: true, + likes: data.likes + 1, + }, + false + ); await axios.post( `${process.env.NEXT_PUBLIC_ENV_BASE_URL}posts/api/${id}/postComment/${answer?.id}/like/`, - { ...answer } + { ...data } ); }} /> )} - {answer.likes} + {data?.likes}
);