Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
WebFront
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
websystem
WebFront
Commits
eab6aed7
Commit
eab6aed7
authored
6 months ago
by
석찬 윤
Browse files
Options
Downloads
Patches
Plain Diff
feat: 스케줄 페이지 api 적용 (
#8
)
parent
6349e1e5
No related branches found
No related tags found
1 merge request
!6
[#8] 스케줄 페이지 개발
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/pages/SchedulePage.jsx
+91
-84
91 additions, 84 deletions
src/pages/SchedulePage.jsx
with
91 additions
and
84 deletions
src/pages/SchedulePage.jsx
+
91
−
84
View file @
eab6aed7
import
React
,
{
useEffect
,
useState
}
from
"
react
"
;
import
React
,
{
useEffect
,
useState
}
from
"
react
"
;
import
Label
from
"
../components/Label
"
;
import
Label
from
"
../components/Label
"
;
// import { createSchedule, deleteSchedule, fetchAllSchedules } from "./api"; // API 호출 주석 유지
import
{
createSchedule
,
deleteSchedule
,
fetchScheduleByTimeIndex
,
fetchAllSchedules
,
updateSchedule
,
}
from
"
../api/schedule
"
;
const
generateTimeSlots
=
()
=>
{
const
generateTimeSlots
=
()
=>
{
const
timeSlots
=
[];
const
timeSlots
=
[];
...
@@ -16,26 +22,26 @@ const generateTimeSlots = () => {
...
@@ -16,26 +22,26 @@ const generateTimeSlots = () => {
const
days
=
[
"
월
"
,
"
화
"
,
"
수
"
,
"
목
"
,
"
금
"
,
"
토
"
,
"
일
"
];
const
days
=
[
"
월
"
,
"
화
"
,
"
수
"
,
"
목
"
,
"
금
"
,
"
토
"
,
"
일
"
];
const
dummySchedules
=
[
//
const dummySchedules = [
{
//
{
id
:
1
,
//
id: 1,
user_id
:
1
,
//
user_id: 1,
title
:
"
알고리즘 스터디
"
,
//
title: "알고리즘 스터디",
is_fixed
:
true
,
//
is_fixed: true,
time_indices
:
[
36
,
37
,
38
,
39
],
//
time_indices: [36, 37, 38, 39],
createdAt
:
"
2024-12-02T09:52:00.000Z
"
,
//
createdAt: "2024-12-02T09:52:00.000Z",
updatedAt
:
"
2024-12-02T09:52:00.000Z
"
,
//
updatedAt: "2024-12-02T09:52:00.000Z",
},
//
},
{
//
{
id
:
5
,
//
id: 5,
user_id
:
1
,
//
user_id: 1,
title
:
"
웹시설 팀플
"
,
//
title: "웹시설 팀플",
is_fixed
:
true
,
//
is_fixed: true,
time_indices
:
[
165
,
166
,
167
,
255
,
256
,
257
],
//
time_indices: [165, 166, 167, 255, 256, 257],
createdAt
:
"
2024-12-02T09:54:53.000Z
"
,
//
createdAt: "2024-12-02T09:54:53.000Z",
updatedAt
:
"
2024-12-02T09:54:53.000Z
"
,
//
updatedAt: "2024-12-02T09:54:53.000Z",
},
//
},
];
//
];
const
SchedulePage
=
()
=>
{
const
SchedulePage
=
()
=>
{
const
timeSlots
=
generateTimeSlots
();
const
timeSlots
=
generateTimeSlots
();
...
@@ -48,53 +54,54 @@ const SchedulePage = () => {
...
@@ -48,53 +54,54 @@ const SchedulePage = () => {
const
[
isFixed
,
setIsFixed
]
=
useState
(
true
);
const
[
isFixed
,
setIsFixed
]
=
useState
(
true
);
useEffect
(()
=>
{
useEffect
(()
=>
{
// const initializeSchedules = async () => {
// API
// try {
const
initializeSchedules
=
async
()
=>
{
// const data = await fetchAllSchedules();
try
{
// setSchedules(data);
const
data
=
await
fetchAllSchedules
();
// } catch (error) {
setSchedules
(
data
);
// console.error("Failed to load schedules", error);
}
catch
(
error
)
{
// }
console
.
error
(
"
Failed to load schedules
"
,
error
);
// };
}
};
//
initializeSchedules();
initializeSchedules
();
//
현재는 더미 데이터로 초기화
//
임시 코드
setSchedules
(
dummySchedules
);
//
setSchedules(dummySchedules);
},
[]);
},
[]);
const
handleSlotClick
=
async
(
timeIdx
)
=>
{
const
handleSlotClick
=
async
(
timeIdx
)
=>
{
if
(
!
isEditMode
)
return
;
if
(
!
isEditMode
)
return
;
// API
호출 준비가 되었을 때 사용:
// API
//
try {
try
{
//
const response = await fetchScheduleByTimeIndex(timeIdx);
const
response
=
await
fetchScheduleByTimeIndex
(
timeIdx
);
//
if (response && response.data && response.data.schedule) {
if
(
response
&&
response
.
data
&&
response
.
data
.
schedule
)
{
//
setSelectedSchedule(response.data.schedule); // API로 가져온 스케줄 설정
setSelectedSchedule
(
response
.
data
.
schedule
);
// API로 가져온 스케줄 설정
//
} else {
}
else
{
//
console.error("No schedule found for time index:", timeIdx);
console
.
error
(
"
No schedule found for time index:
"
,
timeIdx
);
//
}
}
//
} catch (error) {
}
catch
(
error
)
{
//
console.error("Failed to fetch schedule for time index:", timeIdx, error);
console
.
error
(
"
Failed to fetch schedule for time index:
"
,
timeIdx
,
error
);
//
}
}
// 임시 코드
// 임시 코드
const
slotInSchedule
=
schedules
.
find
((
s
)
=>
//
const slotInSchedule = schedules.find((s) =>
s
.
time_indices
.
includes
(
timeIdx
)
//
s.time_indices.includes(timeIdx)
);
//
);
if
(
slotInSchedule
)
{
//
if (slotInSchedule) {
if
(
selectedSlots
.
length
===
0
)
{
//
if (selectedSlots.length === 0) {
setSelectedSchedule
(
slotInSchedule
);
//
setSelectedSchedule(slotInSchedule);
}
//
}
return
;
//
return;
}
//
}
if
(
selectedSlots
.
includes
(
timeIdx
))
{
//
if (selectedSlots.includes(timeIdx)) {
setSelectedSlots
((
prev
)
=>
prev
.
filter
((
idx
)
=>
idx
!==
timeIdx
));
//
setSelectedSlots((prev) => prev.filter((idx) => idx !== timeIdx));
}
else
{
//
} else {
setSelectedSlots
((
prev
)
=>
[...
prev
,
timeIdx
]);
//
setSelectedSlots((prev) => [...prev, timeIdx]);
}
//
}
};
};
const
handleCancelSchedule
=
()
=>
{
const
handleCancelSchedule
=
()
=>
{
...
@@ -122,16 +129,16 @@ const SchedulePage = () => {
...
@@ -122,16 +129,16 @@ const SchedulePage = () => {
is_fixed
:
isFixed
,
is_fixed
:
isFixed
,
time_indices
:
selectedSlots
,
time_indices
:
selectedSlots
,
};
};
// API
호출 부분 (주석 처리)
// API
//
const newSchedule = await updateSchedule(scheduleData);
const
newSchedule
=
await
updateSchedule
(
scheduleData
);
// 임시
로 더미 데이터에 추가
// 임시
코드
const
newSchedule
=
{
//
const newSchedule = {
...
scheduleData
,
//
...scheduleData,
id
:
Date
.
now
(),
//
id: Date.now(),
createdAt
:
new
Date
().
toISOString
(),
//
createdAt: new Date().toISOString(),
updatedAt
:
new
Date
().
toISOString
(),
//
updatedAt: new Date().toISOString(),
};
//
};
setSchedules
((
prev
)
=>
[...
prev
,
newSchedule
]);
setSchedules
((
prev
)
=>
[...
prev
,
newSchedule
]);
setSelectedSchedule
(
newSchedule
);
setSelectedSchedule
(
newSchedule
);
...
@@ -155,16 +162,16 @@ const SchedulePage = () => {
...
@@ -155,16 +162,16 @@ const SchedulePage = () => {
time_indices
:
selectedSlots
,
time_indices
:
selectedSlots
,
};
};
// API
호출 부분 (주석 처리)
// API
//
const newSchedule = await createSchedule(scheduleData);
const
newSchedule
=
await
createSchedule
(
scheduleData
);
// 임시
로 더미 데이터에 추가
// 임시
코드
const
newSchedule
=
{
//
const newSchedule = {
...
scheduleData
,
//
...scheduleData,
id
:
Date
.
now
(),
//
id: Date.now(),
createdAt
:
new
Date
().
toISOString
(),
//
createdAt: new Date().toISOString(),
updatedAt
:
new
Date
().
toISOString
(),
//
updatedAt: new Date().toISOString(),
};
//
};
setSchedules
((
prev
)
=>
[...
prev
,
newSchedule
]);
setSchedules
((
prev
)
=>
[...
prev
,
newSchedule
]);
setSelectedSlots
([]);
setSelectedSlots
([]);
...
@@ -184,15 +191,15 @@ const SchedulePage = () => {
...
@@ -184,15 +191,15 @@ const SchedulePage = () => {
const
body
=
{
title
:
selectedSchedule
.
title
};
const
body
=
{
title
:
selectedSchedule
.
title
};
// API 호출 준비가 되었을 때 사용:
// API 호출 준비가 되었을 때 사용:
//
await deleteSchedule(body);
await
deleteSchedule
(
body
);
//
const updatedSchedules = await fetchAllSchedules();
const
updatedSchedules
=
await
fetchAllSchedules
();
//
setSchedules(updatedSchedules);
setSchedules
(
updatedSchedules
);
// 임시
로 삭제 처리
// 임시
코드
setSchedules
((
prev
)
=>
//
setSchedules((prev) =>
prev
.
filter
((
s
)
=>
s
.
title
!==
selectedSchedule
.
title
)
//
prev.filter((s) => s.title !== selectedSchedule.title)
);
//
);
setSelectedSchedule
(
null
);
setSelectedSchedule
(
null
);
alert
(
"
스케줄이 삭제되었습니다.
"
);
alert
(
"
스케줄이 삭제되었습니다.
"
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment