Skip to content

Commit c2bd468

Browse files
author
Ju
committed
Feat/main #31 추가 후 main동작이 안 됨 수정
1 parent 2fca734 commit c2bd468

File tree

6 files changed

+39
-27
lines changed

6 files changed

+39
-27
lines changed

src/api/ScheduleApi.jsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,28 @@ import { instance } from "../shared/AxiosInstance";
22

33
export const ScheduleApi = {
44
getSccheduleApi: (payload) => {
5-
console.log(payload);
65
//const data = instance.get(`/v2-dto/users/${payload}/events`);
76
const data = instance.get(`/users/${payload}/events`);
87
return data;
98
},
9+
1010
getInfiniteScrollPage: (payload) => {
1111
console.log(payload.userId);
1212
const data = instance.get(
1313
`/v2-page/users/${payload.userId}/events?page=${payload.page}&size=${3}`
1414
);
1515
return data;
1616
},
17+
1718
postScheduleApi: (payload) => {
1819
const data = instance.post("/events", payload);
1920
return data;
2021
},
22+
23+
getPastScheduleApi: () => {
24+
const data = instance.get("/events/past");
25+
return data;
26+
},
2127
deleteScheduleApi: (payload) => {
2228
console.log(payload);
2329
const data = instance.delete(`/events/${payload}`);

src/components/Schedule/ScheduleAdd.jsx

-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ const ScheduleAdd = () => {
8686
__postSchedule({
8787
Schedule: newSchedule,
8888
userId: window.localStorage.getItem("userId"),
89-
dispatch,
9089
})
9190
);
9291
setSubject("");

src/components/layout/Layout.jsx

-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ const Layout = ({ children }) => {
6363
setHeader(null);
6464
break;
6565
}
66-
console.log(header);
6766
}, [pagePathName.pathname, id]);
6867

6968
return (

src/components/main/Main.jsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const Main = () => {
1414
const [email, setEmail] = useState("");
1515
const dispatch = useDispatch();
1616
const { schedules } = useSelector((state) => state.ScheduleSlice);
17+
const { isLoding } = useSelector((state) => state.ScheduleSlice);
1718
console.log(schedules);
1819

1920
useEffect(() => {
@@ -31,7 +32,7 @@ const Main = () => {
3132
} else {
3233
navigate(`/login`);
3334
}
34-
}, [navigate, email, dispatch]);
35+
}, [navigate, dispatch]);
3536

3637
return (
3738
<>

src/redux/modules/ScheduleSlice.jsx

+28-21
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export const __getSchedule = createAsyncThunk(
3333
try {
3434
console.log("연결");
3535
const { data } = await ScheduleApi.getSccheduleApi(payload);
36+
console.log(data.data);
3637
return thunkAPI.fulfillWithValue(data.data);
3738
} catch (error) {
3839
console.log(error);
@@ -46,6 +47,7 @@ export const __getScrollPage = createAsyncThunk(
4647
try {
4748
console.log("연결");
4849
const { data } = await ScheduleApi.getInfiniteScrollPage(payload);
50+
console.log(data.data);
4951
return thunkAPI.fulfillWithValue(data);
5052
} catch (error) {
5153
console.log(error);
@@ -58,23 +60,30 @@ export const __postSchedule = createAsyncThunk(
5860
async (payload, thunkAPI) => {
5961
try {
6062
const data = await ScheduleApi.postScheduleApi(payload.Schedule);
61-
thunkAPI.dispatch(__getSchedule(payload.userId));
62-
return thunkAPI.fulfillWithValue(data.data);
63+
console.log(payload.userId);
64+
payload.dispatch(__getSchedule(payload.userId));
65+
// return thunkAPI.fulfillWithValue(data.data);
6366
} catch (error) {
6467
return thunkAPI.rejectWithValue(error);
6568
}
6669
}
6770
);
6871

6972
export const __getPastSchedlue = createAsyncThunk(
70-
"schedule/getSchedules",
73+
"schedule/getPastSchedlue",
7174
async (payload, thunkAPI) => {
7275
try {
7376
console.log("연결");
7477
const { data } = await ScheduleApi.getPastScheduleApi();
78+
console.log(data);
7579
return thunkAPI.fulfillWithValue(data.data);
7680
} catch (error) {
77-
console.log(error);
81+
console.log(error.response.status);
82+
const errorStatus = error.response.status;
83+
84+
if (errorStatus === 500) {
85+
window.alert("서버에 문제가 생겼습니다.");
86+
}
7887
}
7988
}
8089
);
@@ -92,6 +101,7 @@ export const ScheduleSlice = createSlice({
92101
state.isLoading = true;
93102
},
94103
[__getSchedule.fulfilled]: (state, action) => {
104+
state.isLoading = false;
95105
console.log(action.payload);
96106
let schedules = action.payload;
97107
let tmp = 0;
@@ -101,13 +111,6 @@ export const ScheduleSlice = createSlice({
101111
tmp = schedules[i];
102112
schedules[i] = schedules[j];
103113
schedules[j] = tmp;
104-
// if (schedules[i].dday === 0) {
105-
// if (schedules[i].dday > schedules[j].dday) {
106-
// tmp = schedules[i];
107-
// schedules[i] = schedules[j];
108-
// schedules[j] = tmp;
109-
// }
110-
// }
111114
}
112115
}
113116
}
@@ -145,27 +148,31 @@ export const ScheduleSlice = createSlice({
145148
state.isLoading = false;
146149
state.error = action.payload;
147150
},
151+
148152
[__getPastSchedlue.pending]: (state) => {
149153
state.isLoading = true;
150154
},
151155
[__getPastSchedlue.fulfilled]: (state, action) => {
156+
console.log(action.payload);
152157
state.isLoading = false;
153158
state.pastSchedules = action.payload;
154159
},
160+
155161
[__getPastSchedlue.rejected]: (state, action) => {
156162
state.isLoading = false;
157163
state.error = action.payload;
158164
},
159-
[__deleteSchedule.pending]: (state) => {
160-
state.isLoading = true;
161-
},
162-
[__deleteSchedule.fulfilled]: (state, action) => {
163-
state.isLoading = false;
164-
},
165-
[__deleteSchedule.rejected]: (state, action) => {
166-
state.isLoading = false;
167-
state.error = action.error.message;
168-
},
165+
166+
// [__deleteSchedule.pending]: (state) => {
167+
// state.isLoading = true;
168+
// },
169+
// [__deleteSchedule.fulfilled]: (state, action) => {
170+
// state.isLoading = false;
171+
// },
172+
// [__deleteSchedule.rejected]: (state, action) => {
173+
// state.isLoading = false;
174+
// state.error = action.error.message;
175+
// },
169176
},
170177
});
171178

src/shared/Router.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ const Router = () => {
2828
<Layout>
2929
<Routes>
3030
{/* 메인과 디테일 페이지 */}
31-
{/* <Route path="/main" element={<MainPage />} /> */}
32-
<Route path="/main" element={<InfiniteScroll />} />
31+
<Route path="/main" element={<MainPage />} />
32+
{/* <Route path="/main" element={<InfiniteScroll />} /> */}
3333
{localStorage.getItem("nickname") ? (
3434
<Route path="/" element={<MainPage />} />
3535
) : (

0 commit comments

Comments
 (0)