-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[2주차] 강다혜 미션 제출합니다. #9
base: master
Are you sure you want to change the base?
Changes from 1 commit
8ff0d9c
24a4642
a5edded
0b78b9c
bc81d43
6766055
f1e2947
4a68345
3359b8b
4b18d9d
9be52ae
d2b556f
58ae455
c99fea8
aeb1253
77820c5
2c8fc68
73c0a79
0c4b733
9622e60
7c2d63b
088a3df
24dedb9
7d59b3d
7765b3b
0b27b35
1dddbd8
f20fd1e
b15d025
467337a
4e03010
288d6d8
0680b3b
f11b891
2cd1232
c26da25
12ab354
263ecbe
51a2fb4
dc8de48
6dacefe
9c40838
80da612
cb94281
0ef65f2
6232a9a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,42 +71,7 @@ export default function useSubject() { | |
}; | ||
const newState = getStateByTaskList(newSubject.taskList); | ||
|
||
if (state !== newState) { | ||
// Case #1: subject is moved to another column | ||
const newSubjectList = { | ||
...subjectList, | ||
[state]: currentSubjectList.filter( | ||
(subject) => subject.id !== subjectId | ||
), | ||
[newState]: [...subjectList[newState], newSubject], | ||
}; | ||
|
||
setSubjectList(newSubjectList); | ||
localStorage.setItem(KEY, JSON.stringify(newSubjectList)); | ||
|
||
return; | ||
} | ||
|
||
// Case #2: subject remains in same column | ||
const newSubjectList = { | ||
...subjectList, | ||
[state]: subjectList[state].map((subject) => { | ||
if (subject.id !== subjectId) { | ||
return subject; | ||
} | ||
|
||
const newTaskList = [...subject.taskList, newTask]; | ||
|
||
return { | ||
...subject, | ||
taskList: newTaskList, | ||
state: getStateByTaskList(newTaskList), | ||
}; | ||
}), | ||
}; | ||
|
||
setSubjectList(newSubjectList); | ||
localStorage.setItem(KEY, JSON.stringify(newSubjectList)); | ||
toggleSubjectState(state, newState, currentSubjectList, newSubject); | ||
} | ||
|
||
function deleteTaskFromSubject(state, subjectId, taskId) { | ||
|
@@ -121,44 +86,7 @@ export default function useSubject() { | |
}; | ||
const newState = getStateByTaskList(newSubject.taskList); | ||
|
||
if (state !== newState) { | ||
// Case #1: subject is moved to another column | ||
const newSubjectList = { | ||
...subjectList, | ||
[state]: currentSubjectList.filter( | ||
(subject) => subject.id !== subjectId | ||
), | ||
[newState]: [...subjectList[newState], newSubject], | ||
}; | ||
|
||
setSubjectList(newSubjectList); | ||
localStorage.setItem(KEY, JSON.stringify(newSubjectList)); | ||
|
||
return; | ||
} | ||
|
||
// Case #2: subject remains in same column | ||
const newSubjectList = { | ||
...subjectList, | ||
[state]: subjectList[state].map((subject) => { | ||
if (subject.id !== subjectId) { | ||
return subject; | ||
} | ||
|
||
const newTaskList = subject.taskList.filter( | ||
(task) => task.id !== taskId | ||
); | ||
|
||
return { | ||
...subject, | ||
taskList: newTaskList, | ||
state: getStateByTaskList(newTaskList), | ||
}; | ||
}), | ||
}; | ||
|
||
setSubjectList(newSubjectList); | ||
localStorage.setItem(KEY, JSON.stringify(newSubjectList)); | ||
toggleSubjectState(state, newState, currentSubjectList, newSubject); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 부분에서, subjectId를 전달하지 않아서 상태 업데이트가 제대로 이루어지지 않는 것 같습니다!! 이 부분이 누락되어 있으면,
이런식으로 수정이 필요할 것 같습니다! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 헉 디버깅 하시느라 너무고생하셨어요...!🥹🥹🥹 |
||
} | ||
|
||
function toggleTaskInSubject(state, subjectId, taskId) { | ||
|
@@ -175,13 +103,24 @@ export default function useSubject() { | |
}; | ||
const newState = getStateByTaskList(newSubject.taskList); | ||
|
||
toggleSubjectState(state, newState, currentSubjectList, newSubject); | ||
} | ||
|
||
function toggleSubjectState( | ||
state, | ||
newState, | ||
currentSubjectList, | ||
newSubject, | ||
subjectId | ||
) { | ||
if (state !== newState) { | ||
// Case #1: subject is moved to another column | ||
const newSubjectList = { | ||
...subjectList, | ||
// remove target subject | ||
[state]: currentSubjectList.filter( | ||
(subject) => subject.id !== subjectId | ||
), | ||
(subject) => subject.id !== newSubject.id | ||
), // add target subject | ||
[newState]: [...subjectList[newState], newSubject], | ||
}; | ||
|
||
|
@@ -194,23 +133,9 @@ export default function useSubject() { | |
// Case #2: subject remains in same column | ||
const newSubjectList = { | ||
...subjectList, | ||
[state]: subjectList[state].map((subject) => { | ||
if (subject.id !== subjectId) { | ||
return subject; | ||
} | ||
|
||
const newTaskList = subject.taskList.map((task) => | ||
task.id === taskId | ||
? { ...task, isCompleted: !task.isCompleted } | ||
: task | ||
); | ||
|
||
return { | ||
...subject, | ||
taskList: newTaskList, | ||
state: getStateByTaskList(newTaskList), | ||
}; | ||
}), | ||
[state]: subjectList[state].map((subject) => | ||
subject.id !== subjectId ? { ...subject } : newSubject | ||
), | ||
}; | ||
|
||
setSubjectList(newSubjectList); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
할일 삭제와 마찬가지로 이부분에서도 subjectid가 전달이 안되어서 할일을 추가해도 반영이 안되는 것 같습니다!!
toggleSubjectState(
state,
newState,
currentSubjectList,
newSubject,
subjectId
);
이런식으로 수정해야할 것 같습니다!