-
Notifications
You must be signed in to change notification settings - Fork 2
Kwon ye kyeong #1
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
base: KwonYeKyeong-Dev
Are you sure you want to change the base?
Changes from 5 commits
9b51ca5
a8e3386
c9fa10b
4668511
3c9bb13
4e58a77
37b07af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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({}); | ||||||||||||
|
|
@@ -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; | ||||||||||||
|
Collaborator
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. 오 몇가지 추가로 살펴보면 그래서, |
||||||||||||
| }); | ||||||||||||
|
|
||||||||||||
| 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
Collaborator
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. 해당 코드가 65번 라인의 todo-frontend/static/src/page/Board.jsx Lines 65 to 67 in 3c9bb13
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
Collaborator
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. 해당 부분도 68~72 라인하고 중복되는 형식인거 같아 todo-frontend/static/src/page/Board.jsx Lines 68 to 72 in 3c9bb13
일반화하기 앞서서, 먼저 중복 코드를 별도의 함수로 분리해보는 것도 좋을거 같아~ |
||||||||||||
| } | ||||||||||||
| 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> | ||||||||||||
|
|
||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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'); | ||
|
Collaborator
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. 초기화 굿굿 👍 👍 |
||
|
|
||
| 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 { | ||
|
|
@@ -41,13 +53,26 @@ function Enrollment({history}) { | |
| const onClearClick = (event) => { | ||
| event.stopPropagation(); | ||
| setTitle(''); | ||
| setAssignee(''); | ||
| document.getElementById("priority").value = 2; | ||
|
Collaborator
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. 리액트에서는 브라우저에서 지원하는 DOM에 직접 접근하는 방식보다 아래 링크를 통해서도 자세한 이유를 확인할 수 있어 (확실하진 않지만, 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>
....
);두 번째로, 버튼 클릭 이벤트 발생시에는 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> | ||
|
Collaborator
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.
|
||
| <option value="3">3순위</option> | ||
|
Comment on lines
+71
to
+73
Collaborator
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. 이런거 Ex) [1, 2, 3].map( ... ); |
||
| </select> | ||
| </label> | ||
| </div> | ||
| <div className='enrollment-btn-grp'> | ||
| <Button className='enrollment-btn' onClick={onPreviousClick} value='이전'/> | ||
|
|
||
| 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; | ||
|
Collaborator
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. 삭제 성공한 경우, |
||
| } catch (e) { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| export default deleteCard; | ||
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.
String 타입으로 변경하지 않아도, '순위' 문자열이 추가되면서 string 타입으로 변경될 거 같아~