Skip to content

Commit

Permalink
[FE]fix:add post answer like mutate
Browse files Browse the repository at this point in the history
  • Loading branch information
jundm committed Feb 23, 2022
1 parent c9171af commit 2eb5962
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 49 deletions.
2 changes: 1 addition & 1 deletion backend/backend/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions frontend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,내정보,댓글,대댓글
5 changes: 2 additions & 3 deletions frontend/components/Articles/ArticleList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,10 @@ function ArticleList({

useEffect(() => {
if (error) {
//! 중복이여도 없앨수가 없음 오류안나고 access토큰만 삭제되면 실행이 안됨
setVerifyToken();
console.error(error.message);
// console.error(error.message);
}
}, [error]);
}, [error, data]);

const columns = [
{
Expand Down
27 changes: 15 additions & 12 deletions frontend/components/Articles/ArticleView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]);

Expand Down Expand Up @@ -120,16 +120,19 @@ function ArticleView({ id }: ArticleViewProps) {
/>
)}

{answered?.results?.map((answer: AnswerProps, index: number) => {
return (
<ArticleViewAnswer
key={index}
id={id}
answer={answer}
answerMutate={answerMutate}
/>
);
})}
{answered?.results?.map(
(answer: AnswerProps, index: number, children: any) => {
return (
<ArticleViewAnswer
key={index}
index={index}
id={id}
answer={answer}
answerMutate={answerMutate}
/>
);
}
)}

<Divider className="border-[1px]" />
<Comment
Expand Down
63 changes: 30 additions & 33 deletions frontend/components/Articles/ArticleViewAnswer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import { LikeOutlined, LikeFilled, EditOutlined } from "@ant-design/icons";
import axios from "axios";
import dayjs from "dayjs";
import nl2br from "react-nl2br";
import { useSWRConfig } from "swr";

interface ArticleViewAnswerProps {
index: number;
id: number;
answer: {
id: number;
Expand All @@ -26,48 +28,50 @@ interface ArticleViewAnswerProps {
}
//* 답변 게시물
function ArticleViewAnswer({
index,
id,
answer,
answerMutate,
}: ArticleViewAnswerProps) {
const { data, mutate } = useFetch(
`posts/api/${id}/postComment/${answer?.id}/`
);
const { mutate: exMutate } = useSWRConfig();
return (
<>
<Divider className="mt-2 mb-7 border-2" />
<div className="flex items-center">
<h3 className="text-xl">{answer.title}</h3>
<h3 className="text-xl">{answer?.title}</h3>
{/* eslint-disable */}
<img
className="rounded-full w-5 h-5 mr-1 ml-auto"
src={answer?.author.avatar_url}
src={answer?.author?.avatar_url}
alt="avatar"
/>
<div className="mr-1">{answer?.author.username}</div>
<div className="mr-1">{answer?.author?.username}</div>
<div className="mr-1 ">
<Divider type="vertical" className="border-[1px]" />
</div>
<div className=" mr-1">
{dayjs(answer?.created_at).format("MM-DD hh:mm")}
</div>
<div>추천 {answer.likes}</div>
<div>추천 {data?.likes}</div>
</div>
<div className=" min-h-[35vh]">
<p>{nl2br(answer?.content)}</p>
</div>
<div className="flex items-center justify-center text-[24px]">
{answer.isLikes ? (
{data?.isLikes ? (
<LikeFilled
onClick={async () => {
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/`
);
Expand All @@ -76,29 +80,22 @@ function ArticleViewAnswer({
) : (
<LikeOutlined
onClick={async () => {
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}
</div>
</>
);
Expand Down

0 comments on commit 2eb5962

Please sign in to comment.