Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
5 changes: 5 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/todo-frontend.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions static/src/component/board/card/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import Task from "../task";
import '../../../css/Card.css';

function Card(props) {
const {subject, tasks, move} = props;
const {subject, tasks, move, remove} = props;
return (
<div className='card'>
<div className='title'>{subject}</div>
{
tasks.map(task => {
return <Task key={task.id} title={task.title} subject={subject} id={task.id} move={move}/>
return <Task key={task.id} title={task.title} priority={task.priority} assignee={task.assignee}
subject={subject} id={task.id} created={task.created} move={move} remove={remove}/>
})
}

Expand Down
9 changes: 7 additions & 2 deletions static/src/component/board/task/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,27 @@ import {isDone, isTodo, toToggledValue} from "../../../utility/status";
import Button from "../../atom/Button";

function Task(props) {
const {title, subject, id, move} = props;
const {title, subject, id, priority, assignee, created, move, remove} = props;
const onClick = (event) => {
event.stopPropagation();
const toggledValue = toToggledValue(subject);
move(id, toggledValue);
};
function handle(event) {
remove(id);
}

return (
<div className='task'>
{
isTodo(subject) && <Button className='task-left-btn' onClick={onClick} value='>'/>
}
{title}
{title} {String(priority)+'순위'} <br/>
Copy link
Collaborator

Choose a reason for hiding this comment

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

String 타입으로 변경하지 않아도, '순위' 문자열이 추가되면서 string 타입으로 변경될 거 같아~

{assignee} {created}
{
isDone(subject) && <Button className='task-right-btn' onClick={onClick} value='<'/>
}
<Button className='task-remove-btn' onClick={handle} value='X'/>
</div>
);
}
Expand Down
48 changes: 47 additions & 1 deletion static/src/page/Board.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import '../css/Board.css';
import moveTo from "../service/moveTo";
import {Link} from "react-router-dom";
import {toName, toToggleName} from '../utility/status';
import deleteCard from "../service/deleteCard";

function Board() {
const [cards, updateCards] = useState({});
Expand All @@ -25,19 +26,64 @@ function Board() {
const changedStatus = toName(result.status);
cards[changedStatus].push(result);

// case 1:
// const changedCards = await getCards();
// updateCards({
// todo: changedCards.todo,
// done: changedCards.done
// });

// case 2:
cards.todo.sort(function (a, b) {
return a.priority-b.priority;
});
cards.done.sort(function (a, b) {
return a.priority-b.priority;
Copy link
Collaborator

Choose a reason for hiding this comment

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

sort() 함수 잘 사용했네 굿굿 👍 👍 👍

몇가지 추가로 살펴보면
Tasktodo 에서 done으로 이동한 경우에는 todo를 새로 정렬할 필요없고,
반대로 done 에서 todo로 이동한 경우에도 done을 새로 정렬할 필요없거든

그래서, Task가 이동한 Card 상태를 의미하는 changedStatus(todo or done) 를 이용해서,
변경된 Card 대해서만 정렬를 수행해주면 불필요한 작업은 줄일 수 있어~

});

updateCards({
todo: cards.todo,
done: cards.done
});
}
};
function remove(id) {
const todo = cards.todo;
const done = cards.done;

let index = todo.findIndex((value) => {
return value.id === id;
});
Comment on lines +54 to +56
Copy link
Collaborator

Choose a reason for hiding this comment

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

해당 코드가 65번 라인의 index = done.findIndex((value) => { return value.id === id;}); 코드하고 비슷한 형식으로 중복되는 것을 볼 수 있는데,

index = done.findIndex((value) => {
return value.id === id;
});

remove() 함수 인자로 status 값까지 받아온다면, 아래처럼 좀더 일반화된 방식으로 중복 코드를 제거할 수 있을 거 같아~

function remove(id, status) {
       ...
       const index = cards[originStatus].findIndex((task) => task.id === id);
       ...
}

if(index!==-1) {
todo.splice(index, 1);
const isSuccesses = deleteCard(id);
if (!isSuccesses) {
alert('NotFound(todo)');
}
Comment on lines +58 to +62
Copy link
Collaborator

Choose a reason for hiding this comment

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

해당 부분도 68~72 라인하고 중복되는 형식인거 같아

done.splice(index, 1);
const isSuccesses = deleteCard(id);
if (!isSuccesses) {
alert('NotFound(done)');
}

일반화하기 앞서서, 먼저 중복 코드를 별도의 함수로 분리해보는 것도 좋을거 같아~

}
else{
index = done.findIndex((value) => {
return value.id === id;
});
done.splice(index, 1);
const isSuccesses = deleteCard(id);
if (!isSuccesses) {
alert('NotFound(done)');
}
}

updateCards({
"todo": cards.todo,
"done": cards.done
});
}

return (
<div className='board'>
<div className='board-list'>
{
Object.entries(cards).map(([subject, tasks]) => {
return <Card key={subject} subject={subject} tasks={tasks} move={move}/>;
return <Card key={subject} subject={subject} tasks={tasks} move={move} remove={remove}/>;
})
}
</div>
Expand Down
31 changes: 28 additions & 3 deletions static/src/page/Enrollment.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,31 @@ import Input from "../component/atom/Input";

function Enrollment({history}) {
const [title, setTitle] = useState('');
const [assignee, setAssignee] = useState('');
const [priority, setPriority] = useState('2');
Copy link
Collaborator

Choose a reason for hiding this comment

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

초기화 굿굿 👍 👍


const onChange = (event) => {
const onChangeTitle = (event) => {
event.stopPropagation();
setTitle(event.target.value);
};

const onChangeAssignee = (event) => {
event.stopPropagation();
setAssignee(event.target.value);
}

const onChangePriority = (event) => {
event.stopPropagation();
setPriority(event.target.value);
}

const onPreviousClick = (event) => {
event.stopPropagation();
history.goBack();
};

const add = async () => {
const isSuccesses = await createCard(title);
const isSuccesses = await createCard(title, assignee, priority);
if (isSuccesses) {
history.goBack();
} else {
Expand All @@ -41,13 +53,26 @@ function Enrollment({history}) {
const onClearClick = (event) => {
event.stopPropagation();
setTitle('');
setAssignee('');
document.getElementById("priority").value = 2;
Copy link
Collaborator

Choose a reason for hiding this comment

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

리액트에서는 브라우저에서 지원하는 DOM에 직접 접근하는 방식보다 Ref 라는 방식
을 통해서 Element에 접근하는 것을 권장하고 있어.

아래 링크를 통해서도 자세한 이유를 확인할 수 있어
Ref가 document.getElementById 보다 나은 이유

(확실하진 않지만, DOM에 직접 접근하게 되면 React가 제공하는 가상 DOM의 장점을 잃게 되지 않을까..?)

Hooks API로는 useRef()를 사용할 수 있어~

const priorityEl = useRef(null);

const onClearClick = (event) => {
  ...
  priorityEl.current.value = 2;
  ....
}

return (
   ...
   <select id='priority' onChange={onChangePriority}" ref={el}>
      ....
    </select>
   ....
);

두 번째로, select Element에 접근하는 방법보다는 useState()로 priority 상태를 관리하면 어떨까?

버튼 클릭 이벤트 발생시에는 setXXX() 수정 메서드로 우선 순위 상태를 변경하는 방식도 해보면 좋을거 같아~

const [priority, setPriority] = useState(2);
...
const onClearClick = (event) => {
  ...
  setPriority(2);
  ....
}
...

return (
   ...
   <select id='priority' onChange={onChangePriority}" value={priority}>
      ....
    </select>
    ....
);

setPriority('2');
};

return (
<div className='enrollment'>
<div className='enrollment-title'>
<label htmlFor="title">Title</label>
<Input id='title' onChange={onChange} onKeyPress={onEnterPress} value={title}/>
<Input id='title' onChange={onChangeTitle} onKeyPress={onEnterPress} value={title}/> <br/>
<label htmlFor="assignee">담당자</label>
<Input id='assignee' onChange={onChangeAssignee} onKeyPress={onEnterPress} value={assignee}/> <br/>
<label>
우선순위
<select id='priority' onChange={onChangePriority}>
<option value="1">1순위</option>
<option selected value="2">2순위</option>
Copy link
Collaborator

Choose a reason for hiding this comment

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

selected 굿굿 💯

<option value="3">3순위</option>
Comment on lines +71 to +73
Copy link
Collaborator

@raccoonback raccoonback Aug 4, 2020

Choose a reason for hiding this comment

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

이런거 map() 함수 적용해봐도 좋을듯

Ex)

[1, 2, 3].map( ... );

</select>
</label>
</div>
<div className='enrollment-btn-grp'>
<Button className='enrollment-btn' onClick={onPreviousClick} value='이전'/>
Expand Down
4 changes: 2 additions & 2 deletions static/src/service/createCard.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
async function createCard(title) {
async function createCard(title, assignee, priority) {
try {
const response = await fetch('/todo/cards', {
method: 'POST',
Expand All @@ -7,7 +7,7 @@ async function createCard(title) {
headers: {
'Content-Type': 'application/json; charset=utf-8',
},
body: JSON.stringify({ title }),
body: JSON.stringify({ title, assignee, priority }),
});

return response.status === 201;
Expand Down
17 changes: 17 additions & 0 deletions static/src/service/deleteCard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
async function deleteCard(id) {
try {
const response = await fetch(`/todo/cards/${id}`, {
method: 'DELETE',
credentials: 'include',
mode: 'cors',
headers: {
'Content-Type': 'application/json; utf-8',
},
});
return response.status === 201;
Copy link
Collaborator

Choose a reason for hiding this comment

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

삭제 성공한 경우, status code => 204(No Content)
https://docs.google.com/document/d/18hPE1bP4o4xP9xIAbHOL5-baelotFG9_zz8uJUPPVzw/edit

} catch (e) {
return false;
}
}

export default deleteCard;