Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post 답글 기능 구현 #76

Merged
merged 13 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/apis/httpClient/httpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ export default {
user: new HttpClient("api/user", axiosConfig),
timetable: new HttpClient("api/timetable", axiosConfig),
post: new HttpClient("api/post/", axiosConfig),
recomment: new HttpClient("api/recomment", axiosConfig),
comment: new HttpClient("api/comment", axiosConfig),
refresh: new HttpClient("api/auth/refresh/access", axiosConfig),
auth: new HttpClient("api/auth/", axiosConfig),
Expand Down
1 change: 1 addition & 0 deletions src/constants/key.constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const KEY = {
TIMETABLE: "useTimetable",
POST: "usePost",
COMMENT: "useComment",
RECOMMENT: "useRecomment",
BAMBOO: "useBamboo",
BAMBOO_ADMIN: "useBambooAdmin",
} as const;
Expand Down
12 changes: 12 additions & 0 deletions src/helpers/checkTextOverflow.helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const checkTextOverflow = (content: string) => {
const sentences = content.split("\n");
const depth = sentences.length;

if (depth > 4) {
const summaryContent = sentences.slice(0, 4).join("\n");
return `${summaryContent}...`;
}
return content;
};

export default checkTextOverflow;
6 changes: 6 additions & 0 deletions src/helpers/getTextDepth.helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const getTextDepth = (content: string) => {
const depth = content.split("\n").length;
return depth;
};

export default getTextDepth;
2 changes: 2 additions & 0 deletions src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ export { default as isAdmin } from "./isAdmin.helper";
export { default as filterInputPost } from "./filterInputPost.helper";
export { default as getWriteContentLabel } from "./getWriteContentLabel.helper";
export { default as checkPostValid } from "./checkPostValid.helper";
export { default as checkTextOverflow } from "./checkTextOverflow.helper";
export { default as getTextDepth } from "./getTextDepth.helper";
48 changes: 48 additions & 0 deletions src/hooks/useTextarea.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React from "react";

const useTextarea = (defaultContent?: string) => {
const [content, setContent] = React.useState(defaultContent || "");
const [textareaHeight, setTextareaHeight] = React.useState({
row: 2,
lineBreak: [] as Array<boolean>,
});

const onInput = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
const { scrollHeight, clientHeight, value } = e.target;

if (scrollHeight > clientHeight) {
setTextareaHeight((prev) => ({
row: prev.row + 1,
lineBreak: { ...prev.lineBreak, [value.length - 1]: true },
}));
}
if (textareaHeight.lineBreak[value.length]) {
setTextareaHeight((prev) => ({
row: prev.row - 1,
lineBreak: { ...prev.lineBreak, [value.length]: false },
}));
}
};

const onKeyEnter = (
e: KeyboardEvent & React.ChangeEvent<HTMLTextAreaElement>,
) => {
if (e.code === "Enter") {
setTextareaHeight((prev) => ({
row: prev.row + 1,
lineBreak: { ...prev.lineBreak, [e.target.value.length]: true },
}));
}
};

return {
content,
setContent,
row: textareaHeight.row,
handleResizeTextAreaOnInput: onInput,
handleResizeTextareaKeyEnter:
onKeyEnter as unknown as React.KeyboardEventHandler<HTMLTextAreaElement>,
};
};

export default useTextarea;
1 change: 1 addition & 0 deletions src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ export type { default as IBambooPost } from "./bambooPost.interface";
export type { default as IPostInfiniteList } from "./postInfiniteList.interface";
export type { default as IInfiniteResult } from "./infiniteResult.interface";
export type { default as IInputPost } from "./inputPost.interface";
export type { default as IRecomment } from "./recomment.interface";
5 changes: 5 additions & 0 deletions src/interfaces/recomment.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import IComment from "./comment.interface";

export default interface IRecomment extends Omit<IComment, "postId"> {
commentId: number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import InfiniteScroll from "react-infinite-scroll-component";
import { PuffLoader } from "react-spinners";
import { IComment } from "@/interfaces";
import CommentListItem from "./CommentListItem";
import { useCommentListQuery } from "../../services/query.service";
import { useCommentListQuery } from "../../../services/query.service";

interface ICommentListBoxProps {
postId: string;
Expand Down
Loading