From e0b98193b5735b028d6a84c6fbef32ddaacb1365 Mon Sep 17 00:00:00 2001 From: ink-0 <71919983+ink-0@users.noreply.github.com> Date: Mon, 12 Jul 2021 01:23:22 +0900 Subject: [PATCH 01/20] =?UTF-8?q?[week1]=20TodoUI=20UI=20component=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -ink-0/js-todo-list-step1/#1 --- src/js/TodoApp.js | 22 ++++++++++++++++++++++ src/js/TodoCount.js | 0 src/js/TodoInput.js | 0 src/js/TodoList.js | 21 +++++++++++++++++++++ 4 files changed, 43 insertions(+) create mode 100644 src/js/TodoApp.js create mode 100644 src/js/TodoCount.js create mode 100644 src/js/TodoInput.js create mode 100644 src/js/TodoList.js diff --git a/src/js/TodoApp.js b/src/js/TodoApp.js new file mode 100644 index 00000000..2a1289ca --- /dev/null +++ b/src/js/TodoApp.js @@ -0,0 +1,22 @@ +import TodoList from './TodoList.js'; + +export default function TodoApp($app) { + this.state = ['hi', 'hello']; + + this.setState = (nextState) => { + this.state = nextState; + todoList.setState(this.state); + }; + + const todoList = new TodoList({ + $app, + initialState: this.state, + }); + + const init = () => { + this.setState({ + ...this.state, + }); + }; + init(); +} diff --git a/src/js/TodoCount.js b/src/js/TodoCount.js new file mode 100644 index 00000000..e69de29b diff --git a/src/js/TodoInput.js b/src/js/TodoInput.js new file mode 100644 index 00000000..e69de29b diff --git a/src/js/TodoList.js b/src/js/TodoList.js new file mode 100644 index 00000000..f93e61c2 --- /dev/null +++ b/src/js/TodoList.js @@ -0,0 +1,21 @@ +export default function TodoList({ $app, initialState }) { + //렌더링할 DOM 생성 + + this.state = initialState; + + this.$target = document.createElement('ul'); + this.$target.className = 'todo-list'; + $app.appendChild(this.$target); + + this.setState = (nextState) => { + this.state = nextState; + this.render(); + }; + + this.render = () => { + // this.$target.innerHTML = `${this.state + // .map((todo, idx) => `
  • ${todo}`) + // .join('')}`; + this.$target.innerHTML = `
    hi
    `; + }; +} From 0060f4b255fb1587977e941b860a338a186dc5ee Mon Sep 17 00:00:00 2001 From: ink-0 <71919983+ink-0@users.noreply.github.com> Date: Mon, 12 Jul 2021 02:02:15 +0900 Subject: [PATCH 02/20] =?UTF-8?q?[week1]=20favicon=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -ink-0/js-todo-list-step1/#1 --- src/js/TodoApp.js | 8 +++++--- src/js/TodoInput.js | 8 ++++++++ src/js/TodoList.js | 8 ++++---- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/js/TodoApp.js b/src/js/TodoApp.js index 2a1289ca..dde1fd9f 100644 --- a/src/js/TodoApp.js +++ b/src/js/TodoApp.js @@ -1,16 +1,18 @@ import TodoList from './TodoList.js'; export default function TodoApp($app) { - this.state = ['hi', 'hello']; + this.state = { + todoes: ['hi', 'hello'], + }; this.setState = (nextState) => { this.state = nextState; - todoList.setState(this.state); + todoList.setState(this.state.todoes); }; const todoList = new TodoList({ $app, - initialState: this.state, + initialState: this.state.todoes, }); const init = () => { diff --git a/src/js/TodoInput.js b/src/js/TodoInput.js index e69de29b..0f79dc16 100644 --- a/src/js/TodoInput.js +++ b/src/js/TodoInput.js @@ -0,0 +1,8 @@ +export default function TodoInput() { + this.state = initialState; + + this.setState = (nextState) => { + this.setState = nextState; + this.render(); + }; +} diff --git a/src/js/TodoList.js b/src/js/TodoList.js index f93e61c2..75216102 100644 --- a/src/js/TodoList.js +++ b/src/js/TodoList.js @@ -13,9 +13,9 @@ export default function TodoList({ $app, initialState }) { }; this.render = () => { - // this.$target.innerHTML = `${this.state - // .map((todo, idx) => `
  • ${todo}`) - // .join('')}`; - this.$target.innerHTML = `
    hi
    `; + const todoTemplate = `${this.state + .map((todo, idx) => `
  • ${todo}`) + .join('')}`; + this.$target.innerHTML = todoTemplate; }; } From a484359924477b0338de3dc59c89ab6d75861f49 Mon Sep 17 00:00:00 2001 From: ink-0 <71919983+ink-0@users.noreply.github.com> Date: Mon, 12 Jul 2021 03:27:34 +0900 Subject: [PATCH 03/20] =?UTF-8?q?[Week1]=20TodoInput=20=EA=B8=B0=EB=8A=A5?= =?UTF-8?q?=20=EA=B5=AC=ED=98=84=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ink-0/js-todo-list-step1/#1 --- src/js/TodoApp.js | 9 +++++++++ src/js/TodoInput.js | 23 +++++++++++++++++++++-- src/js/TodoItem.js | 12 ++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 src/js/TodoItem.js diff --git a/src/js/TodoApp.js b/src/js/TodoApp.js index dde1fd9f..18757cfc 100644 --- a/src/js/TodoApp.js +++ b/src/js/TodoApp.js @@ -1,3 +1,4 @@ +import TodoInput from './TodoInput.js'; import TodoList from './TodoList.js'; export default function TodoApp($app) { @@ -15,6 +16,14 @@ export default function TodoApp($app) { initialState: this.state.todoes, }); + new TodoInput({ + $app, + onAdd: (contents) => { + this.state.todoes.push(contents); + this.setState(this.state); + }, + }); + const init = () => { this.setState({ ...this.state, diff --git a/src/js/TodoInput.js b/src/js/TodoInput.js index 0f79dc16..1dc85350 100644 --- a/src/js/TodoInput.js +++ b/src/js/TodoInput.js @@ -1,8 +1,27 @@ -export default function TodoInput() { - this.state = initialState; +export default function TodoInput({ $app, onAdd }) { + this.$target = document.createElement('input'); + this.$target.id = 'new-todo-title'; + this.$target.className = 'new-todo'; + this.$target.placeholder = '할일 추가하기'; + this.$target.autofocus; + $app.appendChild(this.$target); + this.$target.addEventListener('keydown', (e) => { + this.addTodoItem(e); + }); + + this.addTodoItem = (e) => { + const $newTodoTarget = e.target; + + if (e.code === 'Enter') { + onAdd($newTodoTarget.value); + $newTodoTarget.value = ''; + } + }; this.setState = (nextState) => { this.setState = nextState; this.render(); }; + + this.render = () => {}; } diff --git a/src/js/TodoItem.js b/src/js/TodoItem.js new file mode 100644 index 00000000..3bde0a6b --- /dev/null +++ b/src/js/TodoItem.js @@ -0,0 +1,12 @@ +// export default TodoItem = ({ $app, content }) => { +// this.state = content +// this.$target = document.createElement('li') + +// this.setState = (nextState) => { +// this.state = nextState; +// this.render() +// } +// this.render = () => { +// const todoItemTemplate = `
  • ${this.state
  • ` +// } +// } From 8836ea4f8bc80c7ce9d9c042ba23dda241953a1a Mon Sep 17 00:00:00 2001 From: ink-0 <71919983+ink-0@users.noreply.github.com> Date: Mon, 12 Jul 2021 11:52:17 +0900 Subject: [PATCH 04/20] =?UTF-8?q?TodoCount=20UI=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ink-0/js-todo-list-step1/#1 --- index.html | 51 +++++- index.js | 2 + src/css/style.css | 376 ++++++++++++++++++++--------------------- src/images/tamicon.ico | Bin 0 -> 318 bytes src/js/TodoApp.js | 18 +- src/js/TodoCount.js | 28 +++ src/js/TodoList.js | 7 +- 7 files changed, 277 insertions(+), 205 deletions(-) create mode 100644 index.js create mode 100644 src/images/tamicon.ico diff --git a/index.html b/index.html index 13a02fdb..93db2800 100644 --- a/index.html +++ b/index.html @@ -3,24 +3,31 @@ - 이벤트 - TODOS + Tami's Todo + +

    TODOS

    - -
    + /> --> +
    -
      -
      - 0 -
        + + + +
      +
      diff --git a/index.js b/index.js new file mode 100644 index 00000000..fbb77074 --- /dev/null +++ b/index.js @@ -0,0 +1,2 @@ +import TodoApp from './src/js/TodoApp.js'; +new TodoApp(document.querySelector('.App')); diff --git a/src/css/style.css b/src/css/style.css index 7dcbc6db..2dc26b33 100644 --- a/src/css/style.css +++ b/src/css/style.css @@ -1,334 +1,332 @@ html, body { - margin: 0; - padding: 10px; + margin: 0; + padding: 10px; } button { - margin: 0; - padding: 0; - border: 0; - background: none; - font-size: 100%; - vertical-align: baseline; - font-family: inherit; - font-weight: inherit; - color: inherit; - -webkit-appearance: none; - appearance: none; - -webkit-font-smoothing: antialiased; - -moz-osx-font-smoothing: grayscale; + margin: 0; + padding: 0; + border: 0; + background: none; + font-size: 100%; + vertical-align: baseline; + font-family: inherit; + font-weight: inherit; + color: inherit; + -webkit-appearance: none; + appearance: none; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; } body { - font: 14px 'Helvetica Neue', Helvetica, Arial, sans-serif; - line-height: 1.4em; - background: #f5f5f5; - color: #4d4d4d; - min-width: 230px; - max-width: 550px; - margin: 0 auto; - -webkit-font-smoothing: antialiased; - -moz-osx-font-smoothing: grayscale; - font-weight: 300; + font: 14px 'Helvetica Neue', Helvetica, Arial, sans-serif; + line-height: 1.4em; + background: #f5f5f5; + color: #4d4d4d; + min-width: 230px; + max-width: 550px; + margin: 0 auto; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; + font-weight: 300; } :focus { - outline: 0; + outline: 0; } .hidden { - display: none; + display: none; } .todoapp { - background: #fff; - margin: 130px 0 40px 0; - position: relative; - box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2), - 0 25px 50px 0 rgba(0, 0, 0, 0.1); + background: #fff; + margin: 130px 0 40px 0; + position: relative; + box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2), 0 25px 50px 0 rgba(0, 0, 0, 0.1); } .todoapp input::-webkit-input-placeholder { - font-style: italic; - font-weight: 300; - color: #e6e6e6; + font-style: italic; + font-weight: 300; + color: #e6e6e6; } .todoapp h1 { - position: absolute; - top: -125px; - width: 100%; - font-size: 60px; - text-align: center; - color: dimgray; - font-weight: 100; - font-family: Helvetica Neue, Helvetica, Arial, sans-serif; + position: absolute; + top: -125px; + width: 100%; + font-size: 60px; + text-align: center; + color: dimgray; + font-weight: 100; + font-family: Helvetica Neue, Helvetica, Arial, sans-serif; } .new-todo, .edit { - position: relative; - margin: 0; - width: 100%; - font-size: 24px; - font-family: inherit; - font-weight: inherit; - line-height: 1.4em; - border: 0; - color: inherit; - padding: 6px; - box-shadow: inset 0 -1px 5px 0 rgba(0, 0, 0, 0.2); - box-sizing: border-box; - -webkit-font-smoothing: antialiased; - -moz-osx-font-smoothing: grayscale; + position: relative; + margin: 0; + width: 100%; + font-size: 24px; + font-family: inherit; + font-weight: inherit; + line-height: 1.4em; + border: 0; + color: inherit; + padding: 6px; + box-shadow: inset 0 -1px 5px 0 rgba(0, 0, 0, 0.2); + box-sizing: border-box; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; } .new-todo { - padding: 16px 16px 16px 60px; - border: none; - background: rgba(0, 0, 0, 0.003); - box-shadow: inset 0 -2px 1px rgba(0,0,0,0.03); + padding: 16px 16px 16px 60px; + border: none; + background: rgba(0, 0, 0, 0.003); + box-shadow: inset 0 -2px 1px rgba(0, 0, 0, 0.03); } main { - position: relative; - z-index: 2; - border-top: 1px solid #e6e6e6; + position: relative; + z-index: 2; + border-top: 1px solid #e6e6e6; } .toggle-all { - width: 1px; - height: 1px; - border: none; - opacity: 0; - position: absolute; - right: 100%; - bottom: 100%; + width: 1px; + height: 1px; + border: none; + opacity: 0; + position: absolute; + right: 100%; + bottom: 100%; } .toggle-all + label { - width: 60px; - height: 34px; - font-size: 0; - position: absolute; - top: -52px; - left: -13px; - -webkit-transform: rotate(90deg); - transform: rotate(90deg); + width: 60px; + height: 34px; + font-size: 0; + position: absolute; + top: -52px; + left: -13px; + -webkit-transform: rotate(90deg); + transform: rotate(90deg); } .toggle-all + label:before { - content: '❯'; - font-size: 22px; - color: #e6e6e6; - padding: 10px 27px 10px 27px; + content: '❯'; + font-size: 22px; + color: #e6e6e6; + padding: 10px 27px 10px 27px; } .toggle-all:checked + label:before { - color: #737373; + color: #737373; } .todo-list { - margin: 0; - padding: 0; - list-style: none; + margin: 0; + padding: 0; + list-style: none; } .todo-list li { - position: relative; - font-size: 24px; - border-bottom: 1px solid #ededed; + position: relative; + font-size: 24px; + border-bottom: 1px solid #ededed; } .todo-list li:last-child { - border-bottom: none; + border-bottom: none; } .todo-list li.editing { - border-bottom: none; - padding: 0; + border-bottom: none; + padding: 0; } .todo-list li.editing .edit { - display: block; - width: calc(100% - 43px); - padding: 12px 16px; - margin: 0 0 0 43px; + display: block; + width: calc(100% - 43px); + padding: 12px 16px; + margin: 0 0 0 43px; } .todo-list li.editing .view { - display: none; + display: none; } .todo-list li .toggle { - text-align: center; - width: 40px; - height: auto; - position: absolute; - top: 0; - bottom: 0; - margin: auto 0; - border: none; - -webkit-appearance: none; - appearance: none; + text-align: center; + width: 40px; + height: auto; + position: absolute; + top: 0; + bottom: 0; + margin: auto 0; + border: none; + -webkit-appearance: none; + appearance: none; } .todo-list li .toggle { - opacity: 0; + opacity: 0; } .todo-list li .toggle + label { - background-image: url('data:image/svg+xml;utf8,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%2240%22%20height%3D%2240%22%20viewBox%3D%22-10%20-18%20100%20135%22%3E%3Ccircle%20cx%3D%2250%22%20cy%3D%2250%22%20r%3D%2250%22%20fill%3D%22none%22%20stroke%3D%22%23ededed%22%20stroke-width%3D%223%22/%3E%3C/svg%3E'); - background-repeat: no-repeat; - background-position: center left; + background-image: url('data:image/svg+xml;utf8,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%2240%22%20height%3D%2240%22%20viewBox%3D%22-10%20-18%20100%20135%22%3E%3Ccircle%20cx%3D%2250%22%20cy%3D%2250%22%20r%3D%2250%22%20fill%3D%22none%22%20stroke%3D%22%23ededed%22%20stroke-width%3D%223%22/%3E%3C/svg%3E'); + background-repeat: no-repeat; + background-position: center left; } .todo-list li .toggle:checked + label { - background-image: url('data:image/svg+xml;utf8,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%2240%22%20height%3D%2240%22%20viewBox%3D%22-10%20-18%20100%20135%22%3E%3Ccircle%20cx%3D%2250%22%20cy%3D%2250%22%20r%3D%2250%22%20fill%3D%22none%22%20stroke%3D%22%23bddad5%22%20stroke-width%3D%223%22/%3E%3Cpath%20fill%3D%22%235dc2af%22%20d%3D%22M72%2025L42%2071%2027%2056l-4%204%2020%2020%2034-52z%22/%3E%3C/svg%3E'); + background-image: url('data:image/svg+xml;utf8,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%2240%22%20height%3D%2240%22%20viewBox%3D%22-10%20-18%20100%20135%22%3E%3Ccircle%20cx%3D%2250%22%20cy%3D%2250%22%20r%3D%2250%22%20fill%3D%22none%22%20stroke%3D%22%23bddad5%22%20stroke-width%3D%223%22/%3E%3Cpath%20fill%3D%22%235dc2af%22%20d%3D%22M72%2025L42%2071%2027%2056l-4%204%2020%2020%2034-52z%22/%3E%3C/svg%3E'); } .todo-list li label { - word-break: break-all; - padding: 15px 15px 15px 60px; - display: block; - line-height: 1.2; - transition: color 0.4s; + word-break: break-all; + padding: 15px 15px 15px 60px; + display: block; + line-height: 1.2; + transition: color 0.4s; } .todo-list li.completed label { - color: #d9d9d9; - text-decoration: line-through; + color: #d9d9d9; + text-decoration: line-through; } .todo-list li .destroy { - display: none; - position: absolute; - top: 0; - right: 10px; - bottom: 0; - width: 40px; - height: 40px; - margin: auto 0; - font-size: 30px; - color: #cc9a9a; - margin-bottom: 11px; - transition: color 0.2s ease-out; - cursor: pointer; + display: none; + position: absolute; + top: 0; + right: 10px; + bottom: 0; + width: 40px; + height: 40px; + margin: auto 0; + font-size: 30px; + color: #cc9a9a; + margin-bottom: 11px; + transition: color 0.2s ease-out; + cursor: pointer; } .todo-list li .destroy:hover { - color: #af5b5e; + color: #af5b5e; } .todo-list li .destroy:after { - content: '×'; + content: '×'; } .todo-list li:hover .destroy { - display: block; + display: block; } .todo-list li .edit { - display: none; + display: none; } .todo-list li.editing:last-child { - margin-bottom: -1px; + margin-bottom: -1px; } .count-container { - color: #777; - padding: 10px 15px; - height: 20px; - text-align: center; - border-top: 1px solid #e6e6e6; + color: #777; + padding: 10px 15px; + height: 20px; + text-align: center; + border-top: 1px solid #e6e6e6; } .count-container:before { - content: ''; - position: absolute; - right: 0; - bottom: 0; - left: 0; - height: 50px; - overflow: hidden; - box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2), - 0 8px 0 -3px #f6f6f6, - 0 9px 1px -3px rgba(0, 0, 0, 0.2), - 0 16px 0 -6px #f6f6f6, + content: ''; + position: absolute; + right: 0; + bottom: 0; + left: 0; + height: 50px; + overflow: hidden; + box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2), 0 8px 0 -3px #f6f6f6, + 0 9px 1px -3px rgba(0, 0, 0, 0.2), 0 16px 0 -6px #f6f6f6, 0 17px 2px -6px rgba(0, 0, 0, 0.2); } .todo-count { - float: left; - text-align: left; + float: left; + text-align: left; } .todo-count strong { - font-weight: 300; + font-weight: 300; } .filters { - margin: 0; - padding: 0; - list-style: none; - position: absolute; - right: 0; - left: 0; + margin: 0; + padding: 0; + list-style: none; + position: absolute; + right: 0; + left: 0; } .filters li { - display: inline; + display: inline; } .filters li a { - color: inherit; - margin: 3px; - padding: 3px 7px; - text-decoration: none; - border: 1px solid transparent; - border-radius: 3px; + color: inherit; + margin: 3px; + padding: 3px 7px; + text-decoration: none; + border: 1px solid transparent; + border-radius: 3px; } .filters li a:hover { - border-color: rgba(175, 47, 47, 0.1); + border-color: rgba(175, 47, 47, 0.1); } .filters li a.selected { - border-color: rgba(175, 47, 47, 0.2); + border-color: rgba(175, 47, 47, 0.2); } -.clear-completed, html .clear-completed:active { - float: right; - position: relative; - line-height: 20px; - text-decoration: none; - cursor: pointer; +.clear-completed, +html .clear-completed:active { + float: right; + position: relative; + line-height: 20px; + text-decoration: none; + cursor: pointer; } .clear-completed:hover { - text-decoration: underline; + text-decoration: underline; } .info { - margin: 65px auto 0; - color: #bfbfbf; - font-size: 10px; - text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5); - text-align: center; + margin: 65px auto 0; + color: #bfbfbf; + font-size: 10px; + text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5); + text-align: center; } .info p { - line-height: 1; + line-height: 1; } .info a { - color: inherit; - text-decoration: none; - font-weight: 400; + color: inherit; + text-decoration: none; + font-weight: 400; } .info a:hover { - text-decoration: underline; + text-decoration: underline; } diff --git a/src/images/tamicon.ico b/src/images/tamicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..e528ec9d87f4dd1e07c54e77e8d115b29795f64a GIT binary patch literal 318 zcmZQzU<5(|0RbS%!l1#(z#zuJz@P!d0zj+)#2|4HXaJKC0wf0m{Kx+@e9vQL;P?N} z;I~5$CQKB~;=tmdq@=`vOfx7kFtE6|IH1$W>fnYm8!!k0Ap<^I5F!usC4(^#FbYCw kkhYo3P<)<&p%I3mV*md$Fg!O#!$7&`+kv*X12IrN0Mni#BLDyZ literal 0 HcmV?d00001 diff --git a/src/js/TodoApp.js b/src/js/TodoApp.js index 18757cfc..8f27f120 100644 --- a/src/js/TodoApp.js +++ b/src/js/TodoApp.js @@ -1,21 +1,19 @@ +import TodoCount from './TodoCount.js'; import TodoInput from './TodoInput.js'; import TodoList from './TodoList.js'; export default function TodoApp($app) { this.state = { - todoes: ['hi', 'hello'], + todoes: ["hi I'm Tami"], + count: 0, }; this.setState = (nextState) => { this.state = nextState; todoList.setState(this.state.todoes); + todoCount.setState(this.state.count); }; - const todoList = new TodoList({ - $app, - initialState: this.state.todoes, - }); - new TodoInput({ $app, onAdd: (contents) => { @@ -23,6 +21,14 @@ export default function TodoApp($app) { this.setState(this.state); }, }); + const todoList = new TodoList({ + $app, + initialState: this.state.todoes, + }); + const todoCount = new TodoCount({ + $app, + initialState: this.state.count, + }); const init = () => { this.setState({ diff --git a/src/js/TodoCount.js b/src/js/TodoCount.js index e69de29b..464744b3 100644 --- a/src/js/TodoCount.js +++ b/src/js/TodoCount.js @@ -0,0 +1,28 @@ +export default function TodoCount({ $app, initialState }) { + this.state = initialState; + + this.$target = document.createElement('div'); + this.$target.className = 'count-container'; + $app.appendChild(this.$target); + + this.setState = (nextState) => { + this.state = nextState; + this.render(); + }; + + this.render = () => { + const todoCountTemplate = ` + ${this.state}`; + this.$target.innerHTML = todoCountTemplate; + }; +} diff --git a/src/js/TodoList.js b/src/js/TodoList.js index 75216102..3b41263d 100644 --- a/src/js/TodoList.js +++ b/src/js/TodoList.js @@ -14,7 +14,12 @@ export default function TodoList({ $app, initialState }) { this.render = () => { const todoTemplate = `${this.state - .map((todo, idx) => `
    • ${todo}`) + .map( + (todo, idx) => + `
    • + ${todo} +
    • ` + ) .join('')}`; this.$target.innerHTML = todoTemplate; }; From c4d0353e51067a489c7fd6cb2e90aae4f1fe522c Mon Sep 17 00:00:00 2001 From: ink-0 <71919983+ink-0@users.noreply.github.com> Date: Mon, 12 Jul 2021 12:09:04 +0900 Subject: [PATCH 05/20] =?UTF-8?q?TodoList=20UI=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ink-0/js-todo-list-step1/#1 --- src/js/TodoList.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/js/TodoList.js b/src/js/TodoList.js index 3b41263d..11790164 100644 --- a/src/js/TodoList.js +++ b/src/js/TodoList.js @@ -5,6 +5,7 @@ export default function TodoList({ $app, initialState }) { this.$target = document.createElement('ul'); this.$target.className = 'todo-list'; + this.$target.id = 'todo-list'; $app.appendChild(this.$target); this.setState = (nextState) => { @@ -16,9 +17,14 @@ export default function TodoList({ $app, initialState }) { const todoTemplate = `${this.state .map( (todo, idx) => - `
    • - ${todo} -
    • ` + `
    • +
      + + + +
      + +
    • ` ) .join('')}`; this.$target.innerHTML = todoTemplate; From e7ffe4a39430eb8af0fd6c71d08b3441940061e1 Mon Sep 17 00:00:00 2001 From: ink-0 <71919983+ink-0@users.noreply.github.com> Date: Mon, 12 Jul 2021 19:17:32 +0900 Subject: [PATCH 06/20] =?UTF-8?q?[week1]=20todoes=20data=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20(idx,content=20=EC=B6=94=EA=B0=80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -ink-0/js-todo-list-step1/#3 --- src/css/style.css | 1 + src/js/TodoApp.js | 34 +++++++++++++++++++++++++++++----- src/js/TodoInput.js | 9 +++++---- src/js/TodoItem.js | 29 +++++++++++++++++++---------- src/js/TodoList.js | 26 ++++++++++++++++++++++---- 5 files changed, 76 insertions(+), 23 deletions(-) diff --git a/src/css/style.css b/src/css/style.css index 2dc26b33..58655d96 100644 --- a/src/css/style.css +++ b/src/css/style.css @@ -171,6 +171,7 @@ main { border: none; -webkit-appearance: none; appearance: none; + cursor: pointer; } .todo-list li .toggle { diff --git a/src/js/TodoApp.js b/src/js/TodoApp.js index 8f27f120..d8581625 100644 --- a/src/js/TodoApp.js +++ b/src/js/TodoApp.js @@ -4,23 +4,47 @@ import TodoList from './TodoList.js'; export default function TodoApp($app) { this.state = { - todoes: ["hi I'm Tami"], - count: 0, + todoes: [ + { + idx: 0, + content: 'hi EveryOne', + state: '', + edit: '', + }, + { + idx: 2, + content: "I'm Tami", + state: '', + edit: '', + }, + ], }; this.setState = (nextState) => { this.state = nextState; todoList.setState(this.state.todoes); - todoCount.setState(this.state.count); + todoCount.setState(this.state.todoes); }; new TodoInput({ $app, onAdd: (contents) => { - this.state.todoes.push(contents); - this.setState(this.state); + 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, + }); }, }); + const todoList = new TodoList({ $app, initialState: this.state.todoes, diff --git a/src/js/TodoInput.js b/src/js/TodoInput.js index 1dc85350..da421335 100644 --- a/src/js/TodoInput.js +++ b/src/js/TodoInput.js @@ -6,6 +6,11 @@ export default function TodoInput({ $app, onAdd }) { this.$target.autofocus; $app.appendChild(this.$target); + this.setState = (nextState) => { + this.setState = nextState; + this.render(); + }; + this.$target.addEventListener('keydown', (e) => { this.addTodoItem(e); }); @@ -18,10 +23,6 @@ export default function TodoInput({ $app, onAdd }) { $newTodoTarget.value = ''; } }; - this.setState = (nextState) => { - this.setState = nextState; - this.render(); - }; this.render = () => {}; } diff --git a/src/js/TodoItem.js b/src/js/TodoItem.js index 3bde0a6b..39a7c9e2 100644 --- a/src/js/TodoItem.js +++ b/src/js/TodoItem.js @@ -1,12 +1,21 @@ // export default TodoItem = ({ $app, content }) => { -// this.state = content -// this.$target = document.createElement('li') +// this.state = content; +// this.$target = document.createElement('li'); +// $app.appendChild(this.$target); +// this.setState = (nextState) => { +// this.state = nextState; +// this.render(); +// }; +// this.render = () => { +// const todoItemTemplate = ` +//
      +// +// +// +//
      +// +// `; -// this.setState = (nextState) => { -// this.state = nextState; -// this.render() -// } -// this.render = () => { -// const todoItemTemplate = `
    • ${this.state
    • ` -// } -// } +// this.$target.innerHTML = todoItemTemplate; +// }; +// }; diff --git a/src/js/TodoList.js b/src/js/TodoList.js index 11790164..fcd0179b 100644 --- a/src/js/TodoList.js +++ b/src/js/TodoList.js @@ -12,18 +12,36 @@ export default function TodoList({ $app, initialState }) { this.state = nextState; this.render(); }; + this.$target.addEventListener('click', (e) => {}); + + this.$target.addEventListener('click', (e) => { + // const $toggleBox = e + // console.log($toggleBox); + console.log(e.target.className); + console.log(e.target); + // if ($toggleBox) { + // const { nodeId } = $toggleBox.dataset; + // console.log('nodeid', nodeId); + // const selectNode = this.state.nodes.find((node) => node.id === nodeId); + + // if (selectNode) { + // this.onClick(selectNode); + // } + // } + }); + this.toggleTodo = (e) => {}; this.render = () => { const todoTemplate = `${this.state .map( (todo, idx) => - `
    • + `
    • - - + +
      - +
    • ` ) .join('')}`; From 3544be9cbc28f68dab657951e02de0b7e3ccb1b6 Mon Sep 17 00:00:00 2001 From: ink-0 <71919983+ink-0@users.noreply.github.com> Date: Mon, 12 Jul 2021 19:24:01 +0900 Subject: [PATCH 07/20] =?UTF-8?q?[week1]=20checkBox=20=EA=B8=B0=EB=8A=A5?= =?UTF-8?q?=EC=83=9D=EC=84=B1=EC=A4=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -ink-0/js-todo-list-step1/#3 --- src/js/TodoItem.js | 40 ++++++++++++++++++++-------------------- src/js/TodoList.js | 18 +++++------------- 2 files changed, 25 insertions(+), 33 deletions(-) diff --git a/src/js/TodoItem.js b/src/js/TodoItem.js index 39a7c9e2..7bdb727d 100644 --- a/src/js/TodoItem.js +++ b/src/js/TodoItem.js @@ -1,21 +1,21 @@ -// export default TodoItem = ({ $app, content }) => { -// this.state = content; -// this.$target = document.createElement('li'); -// $app.appendChild(this.$target); -// this.setState = (nextState) => { -// this.state = nextState; -// this.render(); -// }; -// this.render = () => { -// const todoItemTemplate = ` -//
      -// -// -// -//
      -// -// `; +export default TodoItem = ({ $app, content }) => { + this.state = content; + this.$target = document.createElement('li'); + $app.appendChild(this.$target); + this.setState = (nextState) => { + this.state = nextState; + this.render(); + }; + this.render = () => { + const todoItemTemplate = ` +
      + + + +
      + + `; -// this.$target.innerHTML = todoItemTemplate; -// }; -// }; + this.$target.innerHTML = todoItemTemplate; + }; +}; diff --git a/src/js/TodoList.js b/src/js/TodoList.js index fcd0179b..3660c441 100644 --- a/src/js/TodoList.js +++ b/src/js/TodoList.js @@ -15,19 +15,11 @@ export default function TodoList({ $app, initialState }) { this.$target.addEventListener('click', (e) => {}); this.$target.addEventListener('click', (e) => { - // const $toggleBox = e - // console.log($toggleBox); console.log(e.target.className); - console.log(e.target); - // if ($toggleBox) { - // const { nodeId } = $toggleBox.dataset; - // console.log('nodeid', nodeId); - // const selectNode = this.state.nodes.find((node) => node.id === nodeId); - - // if (selectNode) { - // this.onClick(selectNode); - // } - // } + console.log(e); + const $node = e; + const { nodeId } = $node.dataset; + console.log('nodeid', nodeId); }); this.toggleTodo = (e) => {}; @@ -37,7 +29,7 @@ export default function TodoList({ $app, initialState }) { (todo, idx) => `
    • - +
      From 510f9ca9827661786b0a0c2354d9491f70658ae7 Mon Sep 17 00:00:00 2001 From: ink-0 <71919983+ink-0@users.noreply.github.com> Date: Tue, 13 Jul 2021 03:48:43 +0900 Subject: [PATCH 08/20] =?UTF-8?q?[week1]=20checkBox=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -ink-0/js-todo-list-step1/#3 --- src/js/TodoApp.js | 49 ++++++++++++++++++++++++++++++--------------- src/js/TodoCount.js | 3 ++- src/js/TodoList.js | 17 ++++++++-------- 3 files changed, 44 insertions(+), 25 deletions(-) diff --git a/src/js/TodoApp.js b/src/js/TodoApp.js index d8581625..107bc320 100644 --- a/src/js/TodoApp.js +++ b/src/js/TodoApp.js @@ -12,7 +12,7 @@ export default function TodoApp($app) { edit: '', }, { - idx: 2, + idx: 1, content: "I'm Tami", state: '', edit: '', @@ -28,26 +28,13 @@ export default function TodoApp($app) { new TodoInput({ $app, - onAdd: (contents) => { - 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, - }); - }, + onAdd: (contents) => addTodo(contents), }); const todoList = new TodoList({ $app, initialState: this.state.todoes, + onToggle: (idx) => toggleTodo(idx), }); const todoCount = new TodoCount({ $app, @@ -60,4 +47,34 @@ export default function TodoApp($app) { }); }; init(); + + const addTodo = (contents) => { + const todos = this.state.todoes; + const nextIdx = Math.max(0, ...todos.map((todo) => todo.idx)) + 1; + console.log('next', nextIdx); + const newTodo = { + idx: nextIdx, + content: contents, + state: '', + edit: '', + }; + this.state.todoes.push(newTodo); + + this.setState({ + ...this.state, + }); + }; + + const toggleTodo = (idx) => { + const todos = this.state.todoes; + + todos.map((todo) => { + if (todo.idx === parseInt(idx)) { + todo.state = todo.state === '' ? 'complete' : ''; + } + }); + this.setState({ + ...this.state, + }); + }; } diff --git a/src/js/TodoCount.js b/src/js/TodoCount.js index 464744b3..b6b48c75 100644 --- a/src/js/TodoCount.js +++ b/src/js/TodoCount.js @@ -12,7 +12,8 @@ export default function TodoCount({ $app, initialState }) { this.render = () => { const todoCountTemplate = ` - ${this.state}