Skip to content

[10๊ธฐ Tami] TodoList with CRUD #217

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

Open
wants to merge 29 commits into
base: ink-0
Choose a base branch
from
Open

Conversation

ink-0
Copy link

@ink-0 ink-0 commented Jul 12, 2021

๐Ÿ“„ ํšŒ๊ณ 

๊ธฐํƒ€ ์‚ฌ์ •์œผ๋กœ ์ธํ•ด ์š”๊ตฌ์‚ฌํ•ญ์„ ๊ฑฐ์˜ ์™„๋ฃŒํ•˜์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค. ๐Ÿ˜ข
์ด๋ฒˆ์ฃผ ๋‚ด๋‚ด ์Šคํ”ผ๋“œ๋ฅผ ๋‚ด์„œ ์ด๋ฒˆ์ฃผ ๋ฏธ์…˜๊ณผ ์ €๋ฒˆ์ฃผ ๋ฏธ์…˜์„ ์ดํ–‰ํ•  ์˜ˆ์ •์ž…๋‹ˆ๋‹ค

๐Ÿ“Œ ์ง„ํ–‰ ์ƒํ™ฉ

  • html ๋ชจ๋“ˆํ™”
  • ์ฒดํฌ ๋ฐ•์Šค ๊ตฌํ˜„ ์ค‘์— ์ƒํƒœ๊ด€๋ฆฌ์— ์žˆ์–ด ํ—ท๊ฐˆ๋ฆฌ๋Š” ๋ถ€๋ถ„์ด ์žˆ์Šต๋‹ˆ๋‹ค.

๐ŸŽฏ ์š”๊ตฌ์‚ฌํ•ญ

  • todo list์— todoItem์„ ํ‚ค๋ณด๋“œ๋กœ ์ž…๋ ฅํ•˜์—ฌ ์ถ”๊ฐ€ํ•˜๊ธฐ
  • todo list์˜ ์ฒดํฌ๋ฐ•์Šค๋ฅผ ํด๋ฆญํ•˜์—ฌ complete ์ƒํƒœ๋กœ ๋ณ€๊ฒฝ. (li tag ์— completed class ์ถ”๊ฐ€, input ํƒœ๊ทธ์— checked ์†์„ฑ ์ถ”๊ฐ€)
  • todo list์˜ x๋ฒ„ํŠผ์„ ์ด์šฉํ•ด์„œ ํ•ด๋‹น ์—˜๋ฆฌ๋จผํŠธ๋ฅผ ์‚ญ์ œ
  • todo list๋ฅผ ๋”๋ธ”ํด๋ฆญํ–ˆ์„ ๋•Œ input ๋ชจ๋“œ๋กœ ๋ณ€๊ฒฝ. (li tag ์— editing class ์ถ”๊ฐ€) ๋‹จ ์ด๋•Œ ์ˆ˜์ •์„ ์™„๋ฃŒํ•˜์ง€ ์•Š์€ ์ƒํƒœ์—์„œ escํ‚ค๋ฅผ ๋ˆ„๋ฅด๋ฉด ์ˆ˜์ •๋˜์ง€ ์•Š์€ ์ฑ„๋กœ ๋‹ค์‹œ view ๋ชจ๋“œ๋กœ ๋ณต๊ท€
  • todo list์˜ item๊ฐฏ์ˆ˜๋ฅผ countํ•œ ๊ฐฏ์ˆ˜๋ฅผ ๋ฆฌ์ŠคํŠธ์˜ ํ•˜๋‹จ์— ๋ณด์—ฌ์ฃผ๊ธฐ
  • todo list์˜ ์ƒํƒœ๊ฐ’์„ ํ™•์ธํ•˜์—ฌ, ํ•ด์•ผํ•  ์ผ๊ณผ, ์™„๋ฃŒํ•œ ์ผ์„ ํด๋ฆญํ•˜๋ฉด ํ•ด๋‹น ์ƒํƒœ์˜ ์•„์ดํ…œ๋งŒ ๋ณด์—ฌ์ฃผ๊ธฐ

Copy link

@renee13wi renee13wi left a comment

Choose a reason for hiding this comment

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

Tami๋‹˜, 1์ฃผ์ฐจ ๊ณผ์ œ ๋„ˆ๋ฌด ์ˆ˜๊ณ ๋งŽ์œผ์…จ์Šต๋‹ˆ๋‹ค ๐Ÿ˜„
1์ฃผ์ฐจ์— PR ์˜ฌ๋ฆฌ์…จ๋‹จ ๊ฒƒ ๋งŒ์œผ๋กœ๋„ ๋Œ€๋‹จํ•˜์‹ญ๋‹ˆ๋‹ค! ๐Ÿ˜„

๋‚จ์€ ๊ณผ์ œ๋„ ํ•จ๊ป˜ ์—ด์‹ฌํžˆ ํ•ด๋ด…์‹œ๋‹ค! ํ™”์ดํŒ… !!

Comment on lines 32 to 45
const prevIdx = this.state.todoes[this.state.todoes.length - 1].idx;

const newTodo = {
idx: prevIdx + 1,
content: contents,
state: '',
edit: '',
};
this.state.todoes.push(newTodo);

this.setState({
...this.state,
});
},

Choose a reason for hiding this comment

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

์ด ๋ถ€๋ถ„์€ ๋”ฐ๋กœ ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค์–ด ์ฃผ๋Š”๊ฒŒ ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”! :)
ex) handleAdd

Copy link
Author

Choose a reason for hiding this comment

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

๋„ค์ด๋ฐ๊นŒ์ง€ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค ใ…Žใ…Ž

todoCount.setState(this.state.todoes);
};

new TodoInput({

Choose a reason for hiding this comment

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

const todoList = new TodoList({
    $app,
    initialState: this.state.todoes,
  });
  const todoCount = new TodoCount({
    $app,
    initialState: this.state.count,
  });

TodoList, TodoCount์™€ ๋‹ค๋ฅด๊ฒŒ ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑ ํ•  ๋•Œ const์— ํ• ๋‹น์„ ์•ˆํ•ด์ค€ ์ด์œ ๊ฐ€ ์žˆ์„๊นŒ์š”?!

Copy link
Author

Choose a reason for hiding this comment

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

์ผ๋‹จ์€ ํ• ๋‹นํ•œ ํ›„์— ๋”ฐ๋กœ setStateํ•  ํ•„์š”๊ฐ€ ์—†๋‹ค๊ณ  ์ƒ๊ฐํ•ด ๊ทธ๋ ‡๊ฒŒ ํ–ˆ๋Š”๋ฐ์š”, ์•ž์œผ๋กœ ์ถ”๊ฐ€ ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•˜๋ฉด์„œ ์–ด๋–ป๊ฒŒ ๋ ์ง€๋Š” ๋ชจ๋ฅด๊ฒ ๋„ค์š” ..^^


this.render = () => {
const todoCountTemplate = `
<span class="todo-count">์ด <strong>${this.state}</strong> ๊ฐœ</span><ul class="filters">

Choose a reason for hiding this comment

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

<ul class="filters">
๊ฐ€๋…์„ฑ์„ ์œ„ํ•ด ๊ฐœํ–‰ํ•ด์ฃผ๋Š”๊ฒŒ ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”! ๐Ÿ˜„

Copy link
Author

Choose a reason for hiding this comment

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

๊ผผ๊ผผํ•œ ๋ฆฌ๋ทฐ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค

Copy link

@jeleedev jeleedev left a comment

Choose a reason for hiding this comment

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

์•ˆ๋…•ํ•˜์„ธ์š” ์ด์ง€์€์ž…๋‹ˆ๋‹ค.
์ฝ”๋“œ๋ฆฌ๋ทฐ๊ฐ€ ์ฒ˜์Œ์ด๋ผ ๋‹ค๋ฅธ์‚ฌ๋žŒ ์ฝ”๋“œ๋ณด๋Š”๊ฒŒ ์ต์ˆ™ํ•˜์ง€๊ฐ€ ์•Š๋„ค์š” ๐Ÿ˜‚
๊ธฐ๋Šฅ๊ตฌํ˜„์€ ์•„์ง ๋‹ค ์•ˆ๋์–ด๋„ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์ž˜ ๋‚˜๋ˆ ์ ธ์žˆ์–ด์„œ ๋ฆฌ๋ทฐํ•˜๋ฉด์„œ ๋งŽ์ด ๋ฐฐ์› ์Šต๋‹ˆ๋‹ค

@@ -0,0 +1,2 @@
import TodoApp from './src/js/TodoApp.js';
new TodoApp(document.querySelector('.App'));

Choose a reason for hiding this comment

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

main ์ „์ฒด๋ฅผ ๋„˜๊ฒจ์ฃผ๋Š” ๊ฑด ์ƒ๊ฐ ๋ชปํ•ด๋ดค๋Š”๋ฐ HTML์ด ํ•œ๊ฒฐ ๋” ๊น”๋”ํ•ด์ง€๋„ค์š”! ํ•˜๋‚˜ ๋ฐฐ์›Œ๊ฐ‘๋‹ˆ๋‹ค ๐Ÿ‘

this.state = nextState;
this.render();
};
this.render = () => {

Choose a reason for hiding this comment

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

์ปดํฌ๋„ŒํŠธ๋งˆ๋‹ค render๋ฅผ ๋”ฐ๋กœ ๋‘” ์ด์œ ๊ฐ€ ์žˆ์œผ์‹ ๊ฐ€์š”? ๊ทธ๋ ‡๊ฒŒ๋Š” ์•„์ง ๋ชปํ•ด๋ด์„œ ใ…Žใ…Žใ…Ž ๊ถ๊ธˆํ•˜๋„ค์š”

Copy link
Author

Choose a reason for hiding this comment

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

์‚ฌ์‹ค ์ œ๊ฐ€ ๋‹ค๋ฅธ ์ƒํƒœ๊ด€๋ฆฌ ๋ธ”๋กœ๊ทธ๋ฅผ ๋งŽ์ด ์ฐธ๊ณ ํ•ด์„œ ๋งŒ๋“œ๋А๋ผ ๋น„์Šทํ•ด ์กŒ๋Š”๋ฐ eazisilver ๋‹˜์˜ ์ฝ”๋“œ๋„ ํ•œ๋ฒˆ ๋ณด๊ณ  ๋‹ค๋ฅธ์ ์„ ์ฐพ์•„๋ณด๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค ใ…Žใ…Ž

Copy link

@nerdyinu nerdyinu left a comment

Choose a reason for hiding this comment

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

์ž˜ ์ฝ์—ˆ์Šต๋‹ˆ๋‹ค! ์ „์ฒด์ ์œผ๋กœ ์ดํ•ดํ•˜๊ธฐ ์‰ฝ๊ฒŒ ์ž˜ ์งœ์—ฌ์ ธ ์žˆ๋Š” ๊ฒƒ ๊ฐ™์€๋ฐ templated์„ ๊ฐ ์ปดํฌ๋„ŒํŠธ์—์„œ ๋”ฐ๋กœ๋”ฐ๋กœ ์ƒ์„ฑํ•˜๋Š” ๋ฐฉ์‹๋ณด๋‹ค๋Š” TodoApp์—์„œ ๊ฐ ์ปดํฌ๋„ŒํŠธ์˜ target์— ํ•ด๋‹นํ•˜๋Š” ์—˜๋ฆฌ๋จผํŠธ๋ฅผ template์œผ๋กœ renderํ•˜๊ณ  ๊ฐ ์ปดํฌ๋„ŒํŠธ ๊ฐ์ฒด ์ƒ์„ฑ๊ณผ ํ•จ๊ป˜ target๊ฐ’์„ ๋„˜๊ฒจ์ฃผ๋Š” ๋ฐฉ์‹์€ ์–ด๋–จ๊นŒ์š”? ์ฝ”๋“œ ์ถ”์ƒํ™”์— ์‹ ๊ฒฝ์„ ์ข€ ๋” ์“ฐ์‹  ๋‹ค๋ฉด ๋” ์ข‹์€ ์ฝ”๋“œ๊ฐ€ ๋‚˜์˜ฌ ๊ฒƒ ๊ฐ™์•„์š”!

this.state = initialState;

this.$target = document.createElement('div');
this.$target.className = 'count-container';

Choose a reason for hiding this comment

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

์ด๋ ‡๊ฒŒ ์ƒˆ๋กœ createElement๋ฅผ ํ•˜๋Š” ๋ฐฉ์‹๋ณด๋‹จ TodoApp์˜ template์—์„œ ํ•˜์œ„ component๋“ค์— ํ•ด๋‹นํ•˜๋Š” target์„ ๋ฐฐ๋ถ„ํ•ด์ฃผ๋Š” ๋ฐฉ์‹์€ ์–ด๋–จ๊นŒ์š”?

const todoCount = new TodoCount({
$app,
initialState: this.state.count,
});
Copy link

@nerdyinu nerdyinu Jul 12, 2021

Choose a reason for hiding this comment

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

TodoList๋‚˜ TodoCount์— ์‚ฌ์šฉํ•˜์‹ค ํ•จ์ˆ˜๋“ค๋„ OnAdd์ฒ˜๋Ÿผ ๊ฐ์ฒด์— ํ™”์‚ดํ‘œ ํ•จ์ˆ˜ ํ˜•์‹์œผ๋กœ ๋„˜๊ฒจ์ฃผ๊ฑฐ๋‚˜, ์•„๋‹ˆ๋ฉด bind(this)๋ฅผ ํ•ด์„œ ๋„˜๊ฒจ์ฃผ๋ฉด ๊ฐ์ฒด์—์„œ state ์ถฉ๋Œ์—†์ด ์‚ฌ์šฉ๊ฐ€๋Šฅํ•ด์š”!

ink-0 added 17 commits July 13, 2021 03:48
-ink-0/js-todo-list-step1/#3
[week1] checkBox ๊ตฌํ˜„
- ink-0/js-todo-list-step1/#6
[week1] TodoList Delete ๊ตฌํ˜„
- ink-0/js-todo-list-step1/#8
- ์ƒํƒœ ์ถ”๊ฐ€ filterTodoes, isFilter, todoesCount
- component ๋„ค์ด๋ฐ ๋ณ€๊ฒฝ  TodoCount ->  TodoFilter
- ink-0/js-todo-list-step1/#10
- const ์ƒ์„ฑ: ๋ฉ”์„ธ์ง€, class data ๋ถ„๋ฆฌ
- ๊ฐ์ฒด ๋ฆฌํ„ฐ๋Ÿด ์ ์šฉ
- ink-0/js-todo-list-step1/#10
- ๊ทธ์™ธ const ๋Œ€์น˜ ์•ˆํ•œ ๊ฒƒ ์ˆ˜์ •
- ink-0/js-todo-list-step1/#12
-ink-0/js-todo-list-step1/#12
-ink-0/js-todo-list-step1/#14
]
-ink-0/js-todo-list-step1/#17
@ink-0 ink-0 closed this Jul 19, 2021
@ink-0 ink-0 reopened this Jul 26, 2021
Copy link
Author

@ink-0 ink-0 left a comment

Choose a reason for hiding this comment

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

1์ฐจ TodoList ๋ณธ์ธ ๋ฆฌ๋ทฐ

Comment on lines +10 to +27
const initialData = {
todoes: [
{
idx: 0,
content: 'hiEvery One',
state: '',
},
{
idx: 1,
content: 'Im Tami',
state: '',
},
],
todoesFiltered: [],
filterState: FILTER_TYPES.ALL,
todoesCount: '0',
users: [],
};
Copy link
Author

Choose a reason for hiding this comment

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

์ดˆ๊ธฐ ๋ฐ์ดํ„ฐ๋ฅผ ๋”ฐ๋กœ ๋ณด๊ด€ํ•˜๋Š” ๊ฒƒ์ด ์ข‹์•˜์„ ๊ฒƒ์ด๋‹ค.

Comment on lines +108 to +115
this.state['todoes'] = resetTodoes;
localStorage.clear();
localStorage.setItem('state', JSON.stringify({ ...this.state }));
this.state = JSON.parse(localStorage.getItem('state'));
this.setState({
...this.state,
});
};
Copy link
Author

Choose a reason for hiding this comment

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

์ƒ์„ฑ ์‚ญ์ œ ์‹œ clear ํ›„ setํ•˜๋Š” ๋ฐฉ์‹๋ฐ–์— ์—†์—ˆ๋Š”์ง€ ๊ณ ๋ฏผํ•  ํ•„์š”๊ฐ€ ์žˆ๋‹ค.

Comment on lines +139 to +167
const filterTodo = (filterType) => {
const { todoes } = this.state;
if (filterType === FILTER_TYPES.ALL) {
this.setState({
...this.state,
filterState: FILTER_TYPES.ALL,
todoesCount: todoes.length,
});
} else if (filterType === FILTER_TYPES.COMPLETE) {
const completedTodoes = todoes.filter(
(todo) => todo.state === FILTER_TYPES.COMPLETE
);

this.setState({
...this.state,
todoesFiltered: completedTodoes,
filterState: FILTER_TYPES.COMPLETE,
todoesCount: completedTodoes.length,
});
} else if (filterType === FILTER_TYPES.ACTIVE) {
const activeTodoes = todoes.filter(
(todo) => todo.state !== FILTER_TYPES.COMPLETE
);
this.setState({
...this.state,
todoesFiltered: activeTodoes,
filterState: FILTER_TYPES.ACTIVE,
todoesCount: activeTodoes.length,
});
Copy link
Author

Choose a reason for hiding this comment

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

์ฝ”๋“œ ์ค‘๋ณต์ด ๋งŽ๋‹ค.
setState๋ฅผ ํ•˜๋Š” ๋ถ€๋ถ„์—์„œ ์ค‘๋ณต์„ ํ•ด๊ฒฐํ•  ๋ฐฉ์•ˆ์ด ํ•„์š”ํ•˜๋‹ค

Comment on lines +23 to +35
$nodeTodoList.addEventListener('click', (e) => {
const $node = e.target;

if ($node.className === TODO_ITEM_CLASS.TOGGLE) {
this.toggleTodoItem($node);
}
if ($node.className === TODO_ITEM_CLASS.DESTROY) {
this.deleteTodoItem($node);
}

if ($node.className === TODO_ITEM_CLASS.EDIT) {
this.editTodoItem($node);
}
Copy link
Author

Choose a reason for hiding this comment

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

์ด๋ฒคํŠธ early return ์ด ํ•„์š”ํ•˜๋‹ค

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants