Skip to content

Commit 7b998f9

Browse files
committed
feat(#141): 메인 홈 행성 고정 기능 구현
1 parent 6c41c34 commit 7b998f9

2 files changed

Lines changed: 26 additions & 12 deletions

File tree

src/api/planet/space/space.tsx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { authClient } from "@/api/client";
1+
import { authClient } from '@/api/client';
22

33
// 메인 스페이스 아이디 조회
44
export const getMainId = async () => {
@@ -7,6 +7,13 @@ export const getMainId = async () => {
77
return response;
88
};
99

10+
// 메인 스페이스 변경
11+
export const putMainSpace = async (spaceId: string) => {
12+
const response = await authClient.put(`/api/v1/spaces/${spaceId}/main`);
13+
14+
return response;
15+
};
16+
1017
// 특정 스페이스 조회
1118
export const getSpaceInfo = async (spaceId: string) => {
1219
const response = await authClient.get(`/api/v1/spaces/${spaceId}`);
@@ -21,14 +28,14 @@ export const getSpaceList = async () => {
2128
// 스페이스 생성
2229
export const postNewSpace = async ({
2330
spaceName,
24-
templateType,
31+
templateType
2532
}: {
2633
spaceName: string;
2734
templateType: number;
2835
}) => {
2936
return await authClient.post(`/api/v1/spaces`, {
3037
spaceName: spaceName,
31-
templateType: templateType,
38+
templateType: templateType
3239
});
3340
};
3441

@@ -40,30 +47,30 @@ export const deleteSpace = async ({ spaceId }: { spaceId: string }) => {
4047
// 여러 스페이스 삭제
4148
export const deleteSpaces = async ({ spaceIds }: { spaceIds: string[] }) => {
4249
return await authClient.delete(`/api/v1/spaces`, {
43-
data: { spaceIds },
50+
data: { spaceIds }
4451
});
4552
};
4653

4754
// 스페이스 이름 수정
4855
export const putSpace = async ({
4956
spaceId,
50-
spaceName,
57+
spaceName
5158
}: {
5259
spaceId: string;
5360
spaceName: string;
5461
}) => {
5562
return await authClient.put(`/api/v1/spaces/${spaceId}/name`, {
56-
spaceName,
63+
spaceName
5764
});
5865
};
5966

6067
// 스페이스 순서 변경
6168
export const putSpacesOrder = async ({
62-
orders,
69+
orders
6370
}: {
6471
orders: { spaceId: string; index: number }[];
6572
}) => {
6673
return await authClient.put(`/api/v1/spaces/order`, {
67-
orders,
74+
orders
6875
});
6976
};

src/app/planet/manage/page.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { DragDropContext, Droppable, Draggable } from 'react-beautiful-dnd';
1111
import {
1212
deleteSpaces,
1313
getSpaceList,
14+
putMainSpace,
1415
putSpacesOrder
1516
} from '@/api/planet/space/space';
1617
import { useToast } from '@/hooks/useToast';
@@ -104,13 +105,19 @@ const PlanetManagePage = () => {
104105
};
105106

106107
/* 홈(메인) 행성 고정 */
107-
const handleFixMainPlanet = () => {
108+
const handleFixMainPlanet = async () => {
108109
const selectedPlanet = planets?.filter((planet) =>
109110
selectedId.includes(planet.spaceId)
110111
);
111-
112-
/* TODO: 선택 행성 (selectedId) 메인 행성으로 변경 API 연동 */
113-
112+
await putMainSpace(selectedId);
113+
setPlanets(
114+
planets.map((planet) =>
115+
planet.spaceId === selectedId
116+
? { ...planet, isMainSpace: true }
117+
: { ...planet, isMainSpace: false }
118+
)
119+
);
120+
setViewSpaceId(null);
114121
setIsBottomUp(false);
115122
showToast(`${selectedPlanet[0]?.spaceName} 행성을 홈으로 고정했어요`, {
116123
icon: false,

0 commit comments

Comments
 (0)