Skip to content

Commit

Permalink
feat : ag-grid 설치 , ListModal, PostModal 컴포넌트 마이그레이션
Browse files Browse the repository at this point in the history
  • Loading branch information
teawon committed Oct 15, 2023
1 parent c01c829 commit 6d1981c
Show file tree
Hide file tree
Showing 11 changed files with 359 additions and 24 deletions.
4 changes: 2 additions & 2 deletions Mindspace_front_next/app/api/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const updatePost = async ({ id, title, content }: PostParams) => {
});
};

export const getPostListData = async (id: number) => {
export const getPostListData = async (id?: number) => {
const endpoint = `boards/all?node_id=${id}`;

const data = await csrFetch(endpoint, {
Expand All @@ -60,7 +60,7 @@ export const getPostListData = async (id: number) => {
return data;
};

export const getPostData = async (id: number) => {
export const getPostData = async (id?: number) => {
if (id !== null) {
const endpoint = `boards/${id}`;

Expand Down
4 changes: 2 additions & 2 deletions Mindspace_front_next/app/constants/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export type Context = CanvasRenderingContext2D;
export interface ModalProps {
isOpen: boolean;
onRequestClose: () => void;
updateNodeInfo: (id: number | string, isWritten: boolean) => void;
updateNodeInfo: (id: number | undefined, isWritten: boolean) => void;
}

// CustomModal
Expand All @@ -84,7 +84,7 @@ export interface CustomModalProps {
export interface WriteModalProps {
isOpen: boolean;
onRequestClose: () => void;
updateNodeInfo: (id: number | string, isWritten: boolean) => void;
updateNodeInfo: (id: number | undefined, isWritten: boolean) => void;
}

export interface BoardResponseDto {
Expand Down
12 changes: 8 additions & 4 deletions Mindspace_front_next/app/hooks/queries/board.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,14 @@ export const useUpdatePostMutation = (successAction: () => void) => {
});
};

export const usePostListGetQuery = (id: number) => {
return useQuery(["postList", id], () => getPostListData(id));
export const usePostListGetQuery = (id?: number) => {
return useQuery(["postList", id], () => getPostListData(id), {
enabled: id !== null,
});
};

export const usePostGetQuery = (id: number) => {
return useQuery(["postData", id], () => getPostData(id));
export const usePostGetQuery = (id?: number) => {
return useQuery(["postData", id], () => getPostData(id), {
enabled: id !== null,
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
.header {
&__button {
border: none;
background-color: transparent;
margin-left: 0.1rem;
cursor: pointer;
}

&__span {
color: white;
font-size: 2rem;
}
}

.post {
&__button {
font-size: 1.5rem;
color: white;
}

&__wrapper {
display: flex;
width: 100%;
height: 90%;

&__content {
padding: 2.5rem 2rem 0 2rem;
display: flex;
flex: 2;
background-color: white;
border-radius: 10px;

&__wrapper {
display: flex;
flex-direction: column;
width: 100%;

&__header {
display: flex;
flex-direction: row;

&__text {
display: flex;
flex-direction: column;
margin: 1rem;

&__title {
font-size: 1.7rem;
}
}
}

&__info {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
margin: 0 0 0 auto;
padding-right: 1rem;
height: 1rem;
width: 8rem;

&__box {
margin: 0 0 0.5rem 0;
align-self: flex-end;

&__button {
padding: 5px 10px;
font-size: 15px;
border: none;
border-radius: 4px;
background-color: navy;
color: white;
cursor: pointer;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
transition: transform 0.2s ease;

&:hover {
transform: translateY(-2px);
}

&:active {
transform: translateY(1px);
}
}
}

&__date {
margin-right: 0;
align-self: flex-end;
}

&__name {
margin-right: 0;
align-self: flex-end;
}
}

&__content {
&__span {
font-size: 1rem;
margin: 1rem;
}
}
}
}

&__viewer {
overflow-y: auto;
position: relative;
border-top: 1px #ebedf2 solid;
padding: 5px 0 0 10px;
background: white;
margin: 0.5rem;
}
}
}
152 changes: 152 additions & 0 deletions Mindspace_front_next/app/map/components/ListModal/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
import { useState, useEffect, useRef } from "react";
import PostTable from "../PostTable";
import styles from "./ListModal.module.scss";
import { ListModalProps } from "@/constants/types";
import { Viewer } from "@toast-ui/react-editor";
import CustomModal from "@/components/CustomModal";
import { usePostGetQuery } from "@/hooks/queries/board";

import { formatDateTime, DateTimeFormat } from "@/utils/dateTime";
// import CommentModal from "@/pages/NodeMap/components/CommentModal";

function ListModal({ listModalOpen, onListRequestClose }: ListModalProps) {
const [isSelectedTable, setIsSelectedTable] = useState<number>();
const viewerRef = useRef<Viewer>(null);
const { data: postData, isLoading } = usePostGetQuery(isSelectedTable);
// const [commentModalOpen, setCommentModalOpen] = useState(false);
// const commentData = [
// {
// id: 1,
// nickname: "작성자1",
// content: "댓글 내용1",
// date: "5분전",
// },
// {
// id: 2,
// nickname: "작성자2",
// content: "댓글 내용2",
// date: "10분전",
// },
// ];
// const toggleCommentModal = () => {
// setCommentModalOpen((prev) => !prev);
// };

const handleSelectBoard = (id: number) => {
setIsSelectedTable(id);
// setCommentModalOpen(false);
};

useEffect(() => {
if (viewerRef.current) {
viewerRef.current.getInstance().setMarkdown(postData?.content);
}
}, [postData?.content]);

return (
<CustomModal
isOpen={listModalOpen}
onRequestClose={onListRequestClose}
resizable
style={{
padding: "1rem",
}}
>
{!isSelectedTable ? (
<>
<button
className={styles.header__button}
onClick={onListRequestClose}
>
<span className={styles.header__span}>x</span>
</button>
<PostTable onClickedId={handleSelectBoard} />
</>
) : (
!isLoading && (
<>
<button
className={styles.header__button}
onClick={() => {
setIsSelectedTable(undefined);
}}
>
<span className={styles.post__button}>Back</span>
</button>
<div className={styles.post__wrapper}>
<div className={styles.post__wrapper__content}>
<div className={styles.post__wrapper__content__wrapper}>
<div
className={styles.post__wrapper__content__wrapper__header}
>
<div
className={
styles.post__wrapper__content__wrapper__header__text
}
>
<span
className={
styles.post__wrapper__content__wrapper__header__text__title
}
>
{postData?.title}
</span>
</div>
<div
className={styles.post__wrapper__content__wrapper__info}
>
<div
className={
styles.post__wrapper__content__wrapper__info__box
}
>
<button
// onClick={toggleCommentModal}
className={
styles.post__wrapper__content__wrapper__info__box__button
}
>
댓글
</button>
</div>
<span
className={
styles.post__wrapper__content__wrapper__info__name
}
>
{postData.userNickname}
</span>
<span
className={
styles.post__wrapper__content__wrapper__info__date
}
>
{formatDateTime(
postData.updatedAt,
DateTimeFormat.Date,
)}
</span>
</div>
</div>
<div className={styles.post__wrapper__viewer}>
<Viewer
ref={viewerRef}
initialValue={postData?.content}
usageStatistics={false}
/>
</div>
</div>
</div>
{/* <CommentModal
isOpen={commentModalOpen}
initialValue={commentData}
/> */}
</div>
</>
)
)}
</CustomModal>
);
}

export default ListModal;
6 changes: 3 additions & 3 deletions Mindspace_front_next/app/map/components/Modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import styles from "./Modal.module.scss";
import CustomModal from "@/components/CustomModal";
import WriteModal from "../WriteModal";
import { ModalProps } from "@/constants/types";
//import ListModal from '../ListModal';
import ListModal from "../ListModal";
import { useRecoilValue } from "recoil";
import { nodeAtom } from "@/recoil/state/nodeAtom";

Expand Down Expand Up @@ -55,10 +55,10 @@ function NodeModal({ isOpen, onRequestClose, updateNodeInfo }: ModalProps) {
onRequestClose={() => setWriteModalIsOpen(false)}
/>
{/* 글 목록 리스트 모달 */}
{/* <ListModal
<ListModal
listModalOpen={listModalIsOpen}
onListRequestClose={() => setListModalIsOpen(false)}
/> */}
/>
</>
);
}
Expand Down
Loading

0 comments on commit 6d1981c

Please sign in to comment.