Skip to content

Commit

Permalink
fix: commnet create;
Browse files Browse the repository at this point in the history
  • Loading branch information
jundm committed Mar 25, 2022
1 parent 915c16f commit 2fc1acf
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 20 deletions.
1 change: 1 addition & 0 deletions frontend/components/Articles/ArticleAnswerCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ function ArticleAnswerCreate({
`${process.env.NEXT_PUBLIC_ENV_BASE_URL}posts/api/${router.query.id}/postComment/`,
NewAnswer
);
answerMutate();
setAnswer((answer) => !answer);
} else {
setLoading(false);
Expand Down
1 change: 0 additions & 1 deletion frontend/components/Articles/ArticleViewAnswer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ function ArticleViewAnswer({
),
});
}, false);

await axios.delete(
`${process.env.NEXT_PUBLIC_ENV_BASE_URL}posts/api/${id}/postComment/${answer.id}/like/`
);
Expand Down
4 changes: 1 addition & 3 deletions frontend/components/Comments/ArticleComment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ function ArticleComment({}: ArticleCommentProps) {
const { data, error, mutate } = useFetch(
`posts/api/${router.query.id}/comments/`
);
if (error) {
console.error(error.message);
}

return (
<>
{data?.results?.map((comments: CommentProps, key: number) => {
Expand Down
20 changes: 10 additions & 10 deletions frontend/components/Comments/ArticleCommentComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { LikeOutlined, LikeFilled } from "@ant-design/icons";
import { Avatar, Comment } from "antd";
import { useRouter } from "next/router";
import dayjs from "dayjs";
import CommentCreate from "./CommentCreates";
import ArticleReplyComponent from "./ArticleReplyComponent";
import { KeyedMutator } from "swr";
import Cookies from "universal-cookie";
import { parseJwt, setVerifyToken } from "@utils/Cookies/TokenManager";
import CommentCreates from "./CommentCreates";

interface ArticleCommentComponentProps {
comments: CommentProps;
Expand Down Expand Up @@ -130,29 +130,29 @@ function ArticleCommentComponent({
</div>
</>,
]}
author={<a>{comments?.author.username}</a>}
author={<a>{comments.author.username}</a>}
avatar={
<Avatar
src={comments?.author.avatar_url}
alt={comments?.author.username}
src={comments.author.avatar_url}
alt={comments.author.username}
/>
}
content={<p>{comments?.content}</p>}
content={<p>{comments.content}</p>}
datetime={
<span>
{dayjs(comments?.updated_at).format("MM-DD hh:mm")} 추천:
{comments?.likes}
{dayjs(comments.updated_at).format("MM-DD hh:mm")} 추천:
{comments.likes}
</span>
}
>
{replyCreate && (
<CommentCreate
api={`posts/api/${comments?.id}/commentsReply/`}
<CommentCreates
api={`posts/api/${comments.id}/commentsReply/`}
setReplyCreate={setReplyCreate}
/>
)}

<ArticleReplyComponent id={comments?.id} />
<ArticleReplyComponent id={comments.id} />
</Comment>
</>
);
Expand Down
7 changes: 4 additions & 3 deletions frontend/components/Comments/CommentCreates.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface ArticleAnswerCreateProps {
setReplyCreate?: Dispatch<SetStateAction<boolean>>;
}
// *validate 일단 사용 안함
function CommentCreate({ api, setReplyCreate }: ArticleAnswerCreateProps) {
function ReplyCreate({ api, setReplyCreate }: ArticleAnswerCreateProps) {
const [isLoading, setLoading] = useState(false);
const accountUser = useSelector(userName);
const accountUserName = accountUser.payload.auth.username;
Expand Down Expand Up @@ -56,13 +56,14 @@ function CommentCreate({ api, setReplyCreate }: ArticleAnswerCreateProps) {
...data,
results: [
{
id: data.results.id + 1,
id: data.results[0].id + 1,
author: {
username: accountUserName,
name: accountName,
avatar_url: `${process.env.NEXT_PUBLIC_ENV_BASE_URL}avatar/image/${accountUserName}.png`,
},
likes: 0,
isLikes: false,
created_at: Date.now(),
updated_at: Date.now(),
...values,
Expand Down Expand Up @@ -133,4 +134,4 @@ function CommentCreate({ api, setReplyCreate }: ArticleAnswerCreateProps) {
);
}

export default CommentCreate;
export default ReplyCreate;
6 changes: 3 additions & 3 deletions frontend/utils/Cookies/TokenManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function parseJwt(token: string) {
}

function setAccessToken(accessToken: string) {
const expires = new Date(Date.now() + 1000 * 60 * 1);
const expires = new Date(Date.now() + 1000 * 60 * 30);
axios.defaults.headers.common.Authorization = `JWT ${accessToken}`;
cookies.set("accessToken", accessToken, {
path: "/",
Expand All @@ -32,7 +32,7 @@ function setAccessToken(accessToken: string) {
});
}
function setRefreshToken(refreshToken: string) {
const expires = new Date(Date.now() + 1000 * 60 * 60 * 23.5);
const expires = new Date(Date.now() + 1000 * 60 * 60 * 24);
cookies.set("refreshToken", refreshToken, {
path: "/",
expires,
Expand Down Expand Up @@ -73,7 +73,7 @@ function setVerifyToken(expireAccessTokenTime?: number) {
}
if (!expireAccessTokenTime) return;
// 사용중에 마감시간에 임박하면 재발급
if (currentTime + 1000 * 60 * 5 > expireAccessTokenTime) {
if (currentTime + 1000 * 60 * 5 >= expireAccessTokenTime) {
NewAccessToken;
console.log("마감임박-재발급");
}
Expand Down
3 changes: 3 additions & 0 deletions frontend/utils/Hook/useFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export const fetcher = function (url: string) {

export default function useFetch(url: string) {
return useSWR(url, fetcher, {
revalidateOnFocus: false,
revalidateOnReconnect: true,
dedupingInterval: 2000,
onErrorRetry: (error, key, config, revalidate, { retryCount }) => {
if (retryCount >= 10) return;
if (
Expand Down

0 comments on commit 2fc1acf

Please sign in to comment.