Skip to content
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

Open
wants to merge 46 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
8ff0d9c
chore: add prettierrc & apply formatter & update gitignore
psst54 Sep 16, 2024
24a4642
style: add reset.css file
psst54 Sep 16, 2024
a5edded
chore: support absolute path
psst54 Sep 16, 2024
0b78b9c
docs: add feature list
psst54 Sep 16, 2024
bc81d43
fix: fix no-line-at-the-end error
psst54 Sep 16, 2024
6766055
Merge pull request #1 from psst54/feature/setup
psst54 Sep 16, 2024
f1e2947
feature: make basic ui
psst54 Sep 16, 2024
4a68345
feature: add styled-components
psst54 Sep 16, 2024
3359b8b
feature: make board ui
psst54 Sep 17, 2024
4b18d9d
feat: make subject list
psst54 Sep 17, 2024
9be52ae
style: apply styles
psst54 Sep 17, 2024
d2b556f
Merge pull request #2 from psst54/feature/basic-layout
psst54 Sep 17, 2024
58ae455
feat: add useSubject hook
psst54 Sep 18, 2024
c99fea8
feat: split Subject component
psst54 Sep 18, 2024
aeb1253
feat: make subject input form
psst54 Sep 18, 2024
77820c5
Merge pull request #3 from psst54/feature/add-subject
psst54 Sep 18, 2024
2c8fc68
feat: add uuid for dependency
psst54 Sep 18, 2024
73c0a79
feat: make subject delete button
psst54 Sep 18, 2024
0c4b733
style: add icon color
psst54 Sep 18, 2024
9622e60
Merge pull request #4 from psst54/feature/remove-subject
psst54 Sep 18, 2024
7c2d63b
fix: move custom hook to parent component
psst54 Sep 18, 2024
088a3df
fix: fix svg prop names
psst54 Sep 18, 2024
24dedb9
feat: make hook/component for task
psst54 Sep 18, 2024
7d59b3d
feat: make Task component & addTask hook
psst54 Sep 18, 2024
7765b3b
Merge pull request #5 from psst54/feature/add-task
psst54 Sep 18, 2024
0b27b35
feat: remove task
psst54 Sep 18, 2024
1dddbd8
Merge pull request #6 from psst54/feature/remove-task
psst54 Sep 18, 2024
f20fd1e
feat: function to toggle task
psst54 Sep 18, 2024
b15d025
refactor: refactor task related function
psst54 Sep 18, 2024
467337a
feat: change state based on its taskList
psst54 Sep 18, 2024
4e03010
chore: rename function for detail
psst54 Sep 18, 2024
288d6d8
Merge pull request #7 from psst54/feature/toggle-task
psst54 Sep 18, 2024
0680b3b
feat: handle empty input submit
psst54 Sep 18, 2024
f11b891
feat: add column counter
psst54 Sep 18, 2024
2cd1232
chore: fix color constants
psst54 Sep 18, 2024
c26da25
feat: add task counter
psst54 Sep 18, 2024
12ab354
Merge pull request #8 from psst54/feature/error-handle
psst54 Sep 18, 2024
263ecbe
chore: add pretendard font
psst54 Sep 18, 2024
51a2fb4
feat: load/save local storage
psst54 Sep 18, 2024
dc8de48
fix: add key to task
psst54 Sep 18, 2024
6dacefe
fix: edit return form of subject hook
psst54 Sep 21, 2024
9c40838
fix: remove state property in subject
psst54 Sep 21, 2024
80da612
fix: split state toggle function
psst54 Sep 21, 2024
cb94281
Merge pull request #9 from psst54/feature/use-local-storage
psst54 Sep 21, 2024
0ef65f2
Merge pull request #10 from psst54/refactor/codebase
psst54 Sep 21, 2024
6232a9a
docs: update readme
psst54 Sep 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 18 additions & 93 deletions src/hooks/useSubject.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Collaborator

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
);

이런식으로 수정해야할 것 같습니다!

}

function deleteTaskFromSubject(state, subjectId, taskId) {
Expand All @@ -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);
Copy link
Collaborator

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); 

이런식으로 수정이 필요할 것 같습니다!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

헉 디버깅 하시느라 너무고생하셨어요...!🥹🥹🥹

}

function toggleTaskInSubject(state, subjectId, taskId) {
Expand All @@ -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],
};

Expand All @@ -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);
Expand Down