-
Notifications
You must be signed in to change notification settings - Fork 2
Ahyoon #2
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: ahyoon-dev
Are you sure you want to change the base?
Ahyoon #2
Changes from all commits
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 |
|---|---|---|
|
|
@@ -15,5 +15,4 @@ function Button(props) { | |
| </button> | ||
| ); | ||
| } | ||
|
|
||
| export default Button; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,4 +31,8 @@ label { | |
| display: inline-block; | ||
| } | ||
|
|
||
| select { | ||
| padding: 12px 12px 12px 0; | ||
| width:950px; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -1,14 +1,15 @@ | ||||||||
| import React, {useEffect, useState} from 'react'; | ||||||||
| import Card from '../component/board/card'; | ||||||||
| import getCards from "../service/getCards"; | ||||||||
| import getCards from '../service/getCards'; | ||||||||
| import '../css/Board.css'; | ||||||||
| import moveTo from "../service/moveTo"; | ||||||||
| import {Link} from "react-router-dom"; | ||||||||
| import moveTo from '../service/moveTo'; | ||||||||
| import {Link} from 'react-router-dom'; | ||||||||
| import {toName, toToggleName} from '../utility/status'; | ||||||||
| import removeCard from "../service/removeCard"; | ||||||||
|
|
||||||||
| function Board() { | ||||||||
| const [cards, updateCards] = useState({}); | ||||||||
| useEffect(() => { | ||||||||
| useEffect(() => { // 실행했을 때 딱 한번만 실행 | ||||||||
| (async () => { | ||||||||
| const cards = await getCards(); | ||||||||
| updateCards(cards); | ||||||||
|
|
@@ -17,32 +18,79 @@ function Board() { | |||||||
|
|
||||||||
| const move = async (id, targetStatus) => { | ||||||||
| const result = await moveTo(id, targetStatus); | ||||||||
| if (!!result) { | ||||||||
| if (result) { | ||||||||
| const originStatus = toToggleName(targetStatus); | ||||||||
| const index = cards[originStatus].findIndex(task => task.id === id); | ||||||||
| const index = cards[originStatus].findIndex((task) => task.id === id); | ||||||||
| cards[originStatus].splice(index, 1); | ||||||||
|
|
||||||||
| const changedStatus = toName(result.status); | ||||||||
| cards[changedStatus].push(result); | ||||||||
|
|
||||||||
| updateCards({ | ||||||||
| todo: cards.todo, | ||||||||
| done: cards.done | ||||||||
| todo: cards.todo.sort(function(a,b){ | ||||||||
| return a.priority<b.priority?-1:a.priority>b.priority?1:0; | ||||||||
|
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. 아래 33~35번 라인에 function(a,b){
return a.priority<b.priority?-1:a.priority>b.priority?1:0;
}함수하고 중복됬는데, 별도의 함수로 분리하는게 좋을 거 같아~ function compare(a,b){
return a.priority<b.priority?-1:a.priority>b.priority?1:0;
}
...
updateCards({
todo: cards.todo.sort(compare),
done: cards.done.sort(compare)
}); |
||||||||
| }), | ||||||||
| done: cards.done.sort(function(a,b){ | ||||||||
| return a.priority<b.priority?-1:a.priority>b.priority?1:0; | ||||||||
| }), | ||||||||
| }); | ||||||||
| } | ||||||||
| }; | ||||||||
|
|
||||||||
| function remove(id) { | ||||||||
| const isSuccesses = removeCard(id); | ||||||||
| if (isSuccesses) { | ||||||||
| console.log(id); | ||||||||
|
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 todo = cards.todo; | ||||||||
| const done = cards.done; | ||||||||
| console.log(todo); | ||||||||
| console.log(done); | ||||||||
|
|
||||||||
| let index = todo.findIndex((value) => { //index 알아내기 | ||||||||
| return value.id === id; | ||||||||
|
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. 해당 코드가 56번 라인의 todo-frontend/static/src/page/Board.jsx Lines 56 to 58 in 54e1f7e
function remove(id, status) {
...
const index = cards[originStatus].findIndex((task) => task.id === id);
...
} |
||||||||
| }) | ||||||||
|
|
||||||||
| if (index !== -1) { //todod에서 찾았을 경우 | ||||||||
| todo.splice(index,1); //(삭제 시작할 index, 삭제할 개수) | ||||||||
| }else{ //todo에서 못찾았을 경우 done에서 찾는다. | ||||||||
| index = done.findIndex((value) => { //index 알아내기 | ||||||||
| return value.id === id; | ||||||||
| }); | ||||||||
| done.splice(index,1); | ||||||||
| } | ||||||||
|
|
||||||||
| console.log(todo); | ||||||||
| console.log(done); | ||||||||
|
|
||||||||
| //변경된 상태를 react에게 알려주어야한다. 아래 코드 안쓰면 x눌러도 화면에서 안사라짐. | ||||||||
| updateCards({ | ||||||||
| "todo" : todo, | ||||||||
| "done":done | ||||||||
| //todo, done | ||||||||
| //이렇게 한줄로만 써도 된다. 똑같은것이다. | ||||||||
| }); | ||||||||
|
|
||||||||
| //updateCards 호출 | ||||||||
| // react 해당 데이터가 변경이 됐구나! | ||||||||
| // react 해당 데이터를 사용하는 모든 컴포넌트를 부라우저에서 다시 그려준다. | ||||||||
| } else { | ||||||||
| alert('카드 삭제에 실패했습니다.'); | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| return ( | ||||||||
| <div className='board'> | ||||||||
| <div className='board-list'> | ||||||||
| <div className="board"> | ||||||||
| <div className="board-list"> | ||||||||
| { | ||||||||
| Object.entries(cards).map(([subject, tasks]) => { | ||||||||
| return <Card key={subject} subject={subject} tasks={tasks} move={move}/>; | ||||||||
| }) | ||||||||
| Object.entries(cards).map(([subject, tasks]) => | ||||||||
| // Object.entries(cards) : ㅏkey에 done, value에 해당값들. 즉 [todo,[{},{}]]로 만들어준다. | ||||||||
| <Card remove={remove} key={subject} subject={subject} tasks={tasks} move={move}/>, // map(function) : function를 적용시켜서 변환 | ||||||||
| //remove={remove} : 자식한테 props로 전달해준다. | ||||||||
| ) | ||||||||
| } | ||||||||
| </div> | ||||||||
|
|
||||||||
| <Link className='board-link' to="/enrollment">ADD</Link> | ||||||||
| <Link className="board-link" to="/enrollment">ADD</Link> | ||||||||
| </div> | ||||||||
| ); | ||||||||
| } | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,19 +6,35 @@ 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) => { | ||
| event.stopPropagation(); | ||
| setTitle(event.target.value); | ||
| }; | ||
|
|
||
| const onChangeAssignee = (event) => { | ||
| event.stopPropagation(); | ||
| setAssignee(event.target.value); | ||
| }; | ||
|
|
||
| const onChangePriority = (event) => { | ||
| event.stopPropagation(); | ||
| setPriority(event.target.value); | ||
| }; | ||
|
|
||
| function onDisplayPriority(){ | ||
| document.getElementById("priority").selectedIndex="1"; | ||
|
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);
function onDisplayPriority() {
priorityEl.current. selectedIndex = "1";
}
return (
...
<select name="priority" id="priority" onChange={onChangePriority} ref={el}>
....
</select>
....
);
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 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 +57,29 @@ function Enrollment({history}) { | |
| const onClearClick = (event) => { | ||
| event.stopPropagation(); | ||
| setTitle(''); | ||
| setAssignee(''); | ||
| setPriority(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 [priority, setPriority] = useState(2);
...
const onClearClick = (event) => {
...
setPriority(2);
....
}
...
return (
...
<select name="priority" id="priority" onChange={onChangePriority} value={priority}>
....
</select>
....
); |
||
| onDisplayPriority(); | ||
|
|
||
| }; | ||
|
|
||
|
|
||
| return ( | ||
| <div className='enrollment'> | ||
| <div className='enrollment-title'> | ||
| <label htmlFor="title">Title</label> | ||
| <Input id='title' onChange={onChange} onKeyPress={onEnterPress} value={title}/> | ||
| <br/> | ||
| <label htmlFor="title">Assignee</label> | ||
| <Input id='assignee' onChange={onChangeAssignee} value={assignee}/> | ||
| <br/> | ||
| <label htmlFor="title">Priority</label> | ||
| <select name="priority" id="priority" onChange={onChangePriority}> | ||
| <option value="1">1순위</option> | ||
| <option value="2" selected="selected">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. selected 속성 잘사용했네 굿굿 👍 |
||
| <option value="3">3순위</option> | ||
| </select> | ||
|
|
||
| </div> | ||
| <div className='enrollment-btn-grp'> | ||
| <Button className='enrollment-btn' onClick={onPreviousClick} value='이전'/> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,9 +10,12 @@ async function getCards() { | |
| }); | ||
|
|
||
| const cards = await response.json(); | ||
| //console.log(cards); //todo done 상관없이 출력 | ||
|
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 todo = cards.filter((card) => card.status === 'TODO'); | ||
| const done = cards.filter((card) => card.status === 'DONE'); | ||
| return { | ||
| //console.log(todo,done); | ||
|
|
||
| return { //객체로 반환, ㅅtodo:[{},{}] | ||
| todo, done, | ||
| }; | ||
| } catch (e) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| async function removeCard(id) { | ||
| try { | ||
| const response = await fetch('/todo/cards/${id}', { | ||
| method: 'DELETE', | ||
| credentials: 'include', | ||
| mode: 'cors', | ||
| headers: { | ||
| 'Content-Type': 'application/json; charset=utf-8', | ||
| }, | ||
| body: JSON.stringify({ id }), | ||
| }); | ||
|
|
||
| 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 removeCard; | ||
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.
{}로 감싸지 않아도 될 거 같아