Skip to content

Commit 9fbeb4c

Browse files
authored
Merge pull request #58 from harigari/fix/정진
이것저것 수정
2 parents 4cf153a + a1490b1 commit 9fbeb4c

File tree

21 files changed

+257
-126
lines changed

21 files changed

+257
-126
lines changed

atoms/atoms.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { DashBoardData } from "@/types/api.type";
2+
import { atom } from "jotai";
3+
4+
export const dashboardListAtom = atom<DashBoardData[]>([]);

components/Buttons/InviteButton/InviteButton.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import HeaderButton from "@/components/Header/HeaderButton/HeaderButton";
99
import headerButtonStyles from "@/components/Header/Header.module.css";
1010
import { Member, InvitationData } from "@/types/api.type";
1111
import { useRouter } from "next/router";
12+
import Head from "next/head";
1213

1314
type Usage = "header" | "edit_page";
1415

components/Header/Header.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import Members from "../Members/Members";
99
import ProfileIcon from "../Members/ProfileIcon";
1010
import styles from "./Header.module.css";
1111
import HeaderButton from "./HeaderButton/HeaderButton";
12+
import { useAtom, useAtomValue } from "jotai";
13+
import { dashboardListAtom } from "@/atoms/atoms";
1214

1315
const WELCOME_MESSAGE = [
1416
"우리가 하는 일은 큰 일이죠. 큰일나기 전까지는요.",
@@ -21,11 +23,17 @@ interface HeaderProps {
2123
dashboard?: DashBoardData;
2224
}
2325

24-
const Header = ({ dashboard }: HeaderProps) => {
26+
const Header = () => {
2527
const router = useRouter();
2628
const boardId = router?.query.boardId;
2729
const [memberList, setMemberList] = useState<Member[]>([]);
2830
const [myData, setMyData] = useState<ExtendedUserType>();
31+
32+
const dashboardList = useAtomValue(dashboardListAtom);
33+
const dashboard = dashboardList.find((item) => {
34+
return item.id === Number(boardId);
35+
});
36+
2937
const isOwner = memberList?.find((v) => v.userId === myData?.id)?.isOwner;
3038
const [title, setTitle] = useState(dashboard?.title);
3139

components/MenuLayout/MenuLayout.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ import useDragScroll from "@/hooks/useDragScroll";
77

88
interface Props {
99
children: ReactNode;
10-
dashboard?: DashBoardData;
1110
}
1211

13-
const MenuLayout = ({ dashboard, children }: Props) => {
12+
const MenuLayout = ({ children }: Props) => {
1413
const dragRef = useRef<HTMLDivElement>(null);
1514
useDragScroll(dragRef);
1615

@@ -20,10 +19,10 @@ const MenuLayout = ({ dashboard, children }: Props) => {
2019
<Sidemenu />
2120
</div>
2221
<div className={styles.grid__header}>
23-
<Header dashboard={dashboard} />
24-
</div>
25-
<div className={styles.grid__main} ref={dragRef}>
26-
{children}
22+
<Header />
23+
<div className={styles.grid__main} ref={dragRef}>
24+
{children}
25+
</div>
2726
</div>
2827
</div>
2928
);

components/Sidemenu/Sidemenu.tsx

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,55 +15,51 @@ import Link from "next/link";
1515
import { useRouter } from "next/router";
1616
import { FormEvent, useEffect, useState } from "react";
1717
import styles from "./Sidemenu.module.css";
18-
19-
type Pagination = {
20-
size: number;
21-
page?: number;
22-
cursorId?: number;
23-
};
18+
import { useAtomValue } from "jotai";
19+
import { dashboardListAtom } from "@/atoms/atoms";
2420

2521
const Sidemenu = () => {
2622
const router = useRouter();
2723
const [isOpen, setIsOpen] = useState(false);
2824
const [selectedColor, setSelectedColor] = useState<ColorType>("#7ac555");
2925

30-
const [list, setList] = useState<DashBoardData[]>([]);
26+
const dashboardList = useAtomValue(dashboardListAtom);
3127

32-
const { isVisible, setIsVisible, myRef } = useInfScroll();
28+
// const { isVisible, setIsVisible, myRef } = useInfScroll();
3329

34-
const [pagination, setPagination] = useState<Pagination>({
35-
size: 100,
36-
});
30+
// const [pagination, setPagination] = useState<Pagination>({
31+
// size: 100,
32+
// });
3733

38-
const getDashboardList = async () => {
39-
const accessToken = getAccessTokenFromDocument("accessToken");
34+
// const getDashboardList = async () => {
35+
// const accessToken = getAccessTokenFromDocument("accessToken");
4036

41-
const { size, cursorId } = pagination;
37+
// const { size, cursorId } = pagination;
4238

43-
let res;
44-
if (cursorId) {
45-
res = await sender.get({ path: "dashboards", method: "infiniteScroll", size, cursorId, accessToken });
46-
} else {
47-
res = await sender.get({ path: "dashboards", method: "infiniteScroll", size, accessToken });
48-
}
49-
if (res.status !== 200) return;
39+
// let res;
40+
// if (cursorId) {
41+
// res = await sender.get({ path: "dashboards", method: "infiniteScroll", size, cursorId, accessToken });
42+
// } else {
43+
// res = await sender.get({ path: "dashboards", method: "infiniteScroll", size, accessToken });
44+
// }
45+
// if (res.status !== 200) return;
5046

51-
const { dashboards, cursorId: cursor } = res.data;
47+
// const { dashboards, cursorId: cursor } = res.data;
5248

53-
setPagination((prev) => {
54-
return { ...prev, cursorId: cursor };
55-
});
49+
// setPagination((prev) => {
50+
// return { ...prev, cursorId: cursor };
51+
// });
5652

57-
setList((prev) => [...prev, ...dashboards]);
58-
setIsVisible(false);
59-
};
53+
// setList((prev) => [...prev, ...dashboards]);
54+
// setIsVisible(false);
55+
// };
6056

61-
useEffect(() => {
62-
if (pagination.cursorId === null) return;
63-
if (isVisible) {
64-
getDashboardList();
65-
}
66-
}, [isVisible]);
57+
// useEffect(() => {
58+
// if (pagination.cursorId === null) return;
59+
// if (isVisible) {
60+
// getDashboardList();
61+
// }
62+
// }, [isVisible]);
6763

6864
const column = useInputController({
6965
inputConfig: {
@@ -125,8 +121,8 @@ const Sidemenu = () => {
125121
</button>
126122
</div>
127123
<ul className={styles.list}>
128-
{list?.map((board) => (
129-
<li key={board.id}>
124+
{dashboardList?.map((board, i) => (
125+
<li key={i}>
130126
<Link
131127
href={`/dashboard/${board.id}`}
132128
className={clsx(styles.item__button, { [styles.selected]: board.id === Number(router.query.boardId) })}
@@ -145,7 +141,7 @@ const Sidemenu = () => {
145141
</Link>
146142
</li>
147143
))}
148-
<p ref={myRef}></p>
144+
{/* <p ref={myRef}></p> */}
149145
</ul>
150146

151147
{isOpen && (

components/Table/TableList/TableList.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { Dispatch, SetStateAction, useState, FormEvent, RefObject, Fragment } fr
1111
import styles from "./TableList.module.css";
1212
import Image from "next/image";
1313
import clsx from "clsx";
14+
import { useAtom } from "jotai";
15+
import { dashboardListAtom } from "@/atoms/atoms";
1416
type TableIndexType = {
1517
[a: string]: "nickname" | "dashboard" | "inviter" | "email" | "deleteButton" | "acceptButton" | "cancelButton";
1618
};
@@ -35,6 +37,8 @@ const TableList = ({ data, tableIndex, setData, myRef }: TableListProps) => {
3537
setIsMemberDeleteModalOpen((prev) => !prev);
3638
};
3739

40+
const [dashboardList, setDashboardList] = useAtom(dashboardListAtom);
41+
3842
return (
3943
<ul className={clsx(styles.list, { [styles.list__mobile]: isAccept })}>
4044
{data.map((data, idx) => {
@@ -91,6 +95,34 @@ const TableList = ({ data, tableIndex, setData, myRef }: TableListProps) => {
9195
accessToken,
9296
});
9397

98+
if (res.status === 200 && res.data.inviteAccepted === true) {
99+
const { data } = await sender.get({ path: "dashboard", id: res.data.dashboard.id, accessToken });
100+
101+
setDashboardList((prevList) => {
102+
prevList.push(data);
103+
prevList.sort((a, b) => {
104+
if (a.createdByMe !== b.createdByMe) {
105+
// createdByMe가 다른 경우 true를 우선하여 정렬
106+
return a.createdByMe ? -1 : 1;
107+
} else if (a.createdByMe && b.createdByMe) {
108+
// createdByMe가 둘 다 true인 경우 createdAt으로 최신 순으로 정렬
109+
return Number(b.createdAt) - Number(a.createdAt);
110+
} else if (!a.createdByMe && !b.createdByMe) {
111+
// createdByMe가 둘 다 false인 경우 userId로 정렬
112+
if (b.userId !== a.userId) {
113+
return b.userId - a.userId;
114+
} else {
115+
// userId가 같으면 createdAt으로 최신 순으로 정렬
116+
return Number(b.createdAt) - Number(a.createdAt);
117+
}
118+
}
119+
return 0;
120+
});
121+
122+
return prevList;
123+
});
124+
}
125+
94126
if (res.status < 300) {
95127
setData((prev) => prev.filter((v) => v.id !== data.id));
96128
router.push("/mydashboard");

components/Table/TableScroll/TableScroll.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const TableScroll = ({ title, type, tableIndex, invite = false, search = false }
4141
size: 5,
4242
});
4343
const [data, setData] = useState<(Member | InvitationData)[]>([]);
44+
4445
const getScrollData = async () => {
4546
const accessToken = getAccessTokenFromDocument("accessToken");
4647
const { id, size, cursorId } = pagination;

modals/components/Comment/Comment.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ interface CommentProps {
2020
}
2121

2222
const Comment = ({ data, setCommentList, setEditingId, usage, handleEditCancel }: CommentProps) => {
23-
// console.log(data);
2423
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
2524
const accessToken = getAccessTokenFromDocument("accessToken");
2625

package-lock.json

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"dependencies": {
2626
"@hello-pangea/dnd": "^16.5.0",
2727
"clsx": "^2.0.0",
28+
"jotai": "^2.6.1",
2829
"next": "14.0.4",
2930
"react": "^18",
3031
"react-datepicker": "^4.25.0",

0 commit comments

Comments
 (0)