Skip to content

Commit bbd1098

Browse files
authored
Merge pull request #139 from codeit-sprint-part3-6team/#135_할-일-수정-Redu로-업데이트
#135 할 일 수정 redu로 업데이트
2 parents de2b0ac + 1a08bef commit bbd1098

File tree

7 files changed

+41
-88
lines changed

7 files changed

+41
-88
lines changed

src/components/dashboard/column/Column.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ import deleteColumns from '@/lib/dashboard/deleteColumns';
1212
import { Column as ColumnType } from '@/type/column';
1313
import DeleteCardsModal from '@/components/common/modal/delete-cards/DeleteCardsModal';
1414
import CreateCard from '@/components/product/dashboard/create-card/CreateCard';
15+
import { useDispatch, useSelector } from 'react-redux';
16+
import { toggleState } from '@/redux/renderSlice';
17+
import { RootState } from '@/redux/store';
1518

1619
interface ColumnProp {
1720
columnId: number;
@@ -29,6 +32,13 @@ function Column({
2932
const [editedTitle, setEditedTitle] = useState(columnTitle);
3033
const [modal, setModal] = useState(false); // 카드 생성 모달 띄우기 위한 state
3134

35+
const dispatch = useDispatch();
36+
const toggle = useSelector((state: RootState) => state.render.toggle); // Redux 상태 구독
37+
38+
const handleUpdate = () => {
39+
dispatch(toggleState()); // Redux 상태 변경
40+
};
41+
3242
const handleClick = () => {
3343
// 카드 생성 모달 띄우기 위한 함수
3444
setModal(true);
@@ -93,8 +103,8 @@ function Column({
93103
const endPoint = useIntersectionObserver(handleObserver);
94104

95105
useEffect(() => {
96-
fetchCards();
97-
}, [fetchCards]);
106+
fetchCards({ reset: true });
107+
}, [fetchCards, toggle]);
98108

99109
return (
100110
<div className={styles.column}>
@@ -134,9 +144,7 @@ function Column({
134144
columnTitle={columnTitle}
135145
columnId={columnId}
136146
setColumnData={setColumnData}
137-
onUpdate={() =>
138-
fetchCards({ size: columnData.totalCount + 1, reset: true })
139-
}
147+
onUpdate={handleUpdate}
140148
/>
141149
),
142150
)}

src/components/product/dashboard/modify-card/ModifyCard.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import clsx from 'clsx';
1212
import getColumns from '@/lib/dashboard/getColumns';
1313
import useColumnData from '@/hooks/useColumnData';
1414
import useButtonState from '@/hooks/useModifyButtonState';
15-
import { setCardList } from '@/redux/cardListSlice';
1615
import { GetColumnsResponse } from '@/type/column';
1716
import TagManager from '../create-card/TagManager';
1817
import DescriptionInput from '../create-card/DescriptionInput';
@@ -77,7 +76,7 @@ export default function ModifyCard({
7776
handleToggle,
7877
handleOptionClick,
7978
} = useAssigneeSelector(cardInfo?.assignee || null);
80-
const { columnData, fetchCards } = useColumnData(columnId);
79+
const { fetchCards } = useColumnData(columnId);
8180

8281
// 컬럼 정보 가져오기
8382
useEffect(() => {
@@ -155,10 +154,6 @@ export default function ModifyCard({
155154
}
156155
}, [selectedColumnId]);
157156

158-
useEffect(() => {
159-
dispatch(setCardList(columnData));
160-
}, [columnData]);
161-
162157
const handleSubmit = () => {
163158
putCardSubmit({
164159
image,
@@ -174,7 +169,6 @@ export default function ModifyCard({
174169
dashboardId,
175170
onUpdate,
176171
closeModal,
177-
columnData,
178172
dispatch,
179173
initialData,
180174
setInitialData,

src/components/product/mypage/Main.module.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.container {
2-
width: 672px;
2+
width: 712px;
33
@media screen and (max-width: 1199px) {
44
width: 100%;
55
}

src/lib/dashboard/putCardSubmit.ts

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import cardImageUpload from '@/lib/dashboard/cardImageUpload';
22
import putCard from '@/lib/dashboard/putCard';
33
import { setCardInfo } from '@/redux/cardSlice';
4-
import axios from '@/lib/instance';
5-
import { setCardList } from '@/redux/cardListSlice';
64

75
const putCardSubmit = async ({
86
image,
@@ -18,7 +16,6 @@ const putCardSubmit = async ({
1816
dashboardId,
1917
onUpdate,
2018
closeModal,
21-
columnData,
2219
dispatch,
2320
initialData,
2421
setInitialData,
@@ -49,31 +46,10 @@ const putCardSubmit = async ({
4946
};
5047
const result = await putCard(putData, cardInfo.id);
5148
dispatch(setCardInfo(result)); // 수정한 카드의 데이터 리덕스에 담아
52-
53-
// 수정 전 컬럼의 카드 리스트 가져와
54-
const prevResponse = await axios.get(`/11-6/cards/`, {
55-
params: {
56-
size: 4,
57-
cursorId: null,
58-
columnId: cardInfo.columnId,
59-
},
60-
});
61-
console.log('prevResponse:', prevResponse.data);
62-
// 수정 후 컬럼의 카드 리스트 가져와
63-
const response = await axios.get(`/11-6/cards/`, {
64-
params: {
65-
size: columnData.totalCount + 1,
66-
cursorId: null,
67-
columnId: selectedColumn.id,
68-
},
69-
});
70-
71-
dispatch(setCardList(response.data)); // 수정 후 컬럼의 카드 리스트 리덕스에 담아
7249
setInitialData(initialData);
73-
// await onUpdate(); // fetchCards({ size: columnData.totalCount + 1, reset: true }); 로 카드 리스트 초기화인데 새로고침 하면 필요없어
50+
await onUpdate();
7451
await closeModal();
7552
alert('카드가 수정되었습니다.');
76-
window.location.reload(); // 일단 새로고침
7753
} catch (error) {
7854
console.error('handleSubmit Error:', error);
7955
}

src/redux/cardListSlice.ts

Lines changed: 0 additions & 46 deletions
This file was deleted.

src/redux/renderSlice.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { createSlice } from '@reduxjs/toolkit';
2+
3+
type RenderState = {
4+
toggle: boolean;
5+
};
6+
7+
const initialState: RenderState = {
8+
toggle: false,
9+
};
10+
11+
const renderSlice = createSlice({
12+
name: 'render',
13+
initialState,
14+
reducers: {
15+
toggleState: (state) => {
16+
state.toggle = !state.toggle;
17+
},
18+
},
19+
});
20+
21+
export const { toggleState } = renderSlice.actions;
22+
export default renderSlice.reducer;

src/redux/store.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ import { configureStore } from '@reduxjs/toolkit';
22
import { UserInfoState } from '@/type/userInfo';
33
import { DashboardState } from '@/type/dashboard';
44
import { CardInfoState } from '@/type/card';
5-
import { ColumnState } from '@/type/card';
65
import userInfoReducer from './settingSlice';
76
import dashboardReducer from './dashboardSlice';
87
import cardInfoReducer from './cardSlice';
9-
import cardListReducer from './cardListSlice';
8+
import renderReducer from './renderSlice';
109

1110
// 스토리지 선택 함수 (localStorage 또는 sessionStorage)
1211
const getStorage = () => {
@@ -40,17 +39,17 @@ const store = configureStore({
4039
userInfo: userInfoReducer,
4140
dashboard: dashboardReducer,
4241
cardInfo: cardInfoReducer,
43-
cardList: cardListReducer,
42+
render: renderReducer,
4443
} as any,
4544
preloadedState: loadState() as { userInfo: UserInfoState }, // 새로 고침 되어도 이전 상태 유지
4645
});
4746

4847
// 상태와 디스패치 타입 정의
4948
export type RootState = {
49+
render: any;
5050
userInfo: UserInfoState;
5151
dashboard: DashboardState;
5252
cardInfo: CardInfoState;
53-
cardList: ColumnState;
5453
};
5554
export type AppDispatch = typeof store.dispatch;
5655

0 commit comments

Comments
 (0)