From 5331ef1bf79b0841d30dc88d9e5baed15d7667dd Mon Sep 17 00:00:00 2001 From: DavidWells Date: Wed, 20 Jun 2018 12:01:29 -0700 Subject: [PATCH] add date sort order --- public/index.html | 7 ++++- src/App.css | 9 ++++--- src/App.js | 37 +++++++++++++++++++++----- src/components/AppHeader/AppHeader.css | 8 +++--- 4 files changed, 48 insertions(+), 13 deletions(-) diff --git a/public/index.html b/public/index.html index 7e8ddd0..bd7f5ba 100644 --- a/public/index.html +++ b/public/index.html @@ -21,7 +21,12 @@ - + + + + + + diff --git a/src/App.css b/src/App.css index 201df7b..85ff81c 100644 --- a/src/App.css +++ b/src/App.css @@ -129,7 +129,7 @@ .todo__box, .todo__check { - transition: stroke-dashoffset 0.5s cubic-bezier(0.9, 0, 0.5, 1); + /*transition: stroke-dashoffset 0.5s cubic-bezier(0.9, 0, 0.5, 1);*/ } .todo__state:checked ~ .todo-list-title { text-decoration: line-through; @@ -140,7 +140,7 @@ stroke-width: 0; transform-origin: 13.5px 12.5px; transform: scale(0.4) rotate(0deg); - animation: none 0.5s linear; + /*animation: none 0.5s linear;*/ } @keyframes explode { @@ -175,6 +175,9 @@ .todo__state:checked ~ .todo__icon .todo__box { stroke-dashoffset: 56.1053; transition-delay: 0s; + stroke-dasharray: 56.1053, 56.1053; + stroke-dashoffset: 0; + stroke: red; } .todo__state:checked ~ .todo__icon .todo__check { @@ -182,7 +185,7 @@ transition-delay: 0.48s; } .todo__state:checked ~ .todo__icon .todo__circle { - animation-name: explode; + /*animation-name: explode;*/ } /* .todo-completed .todo__state:checked ~ .todo__icon .todo__circle { animation-name: none; diff --git a/src/App.js b/src/App.js index 1488b4d..a7fa853 100644 --- a/src/App.js +++ b/src/App.js @@ -12,6 +12,7 @@ class App extends Component { // Fetch all todos api.readAll().then((response) => { console.log('all todos', response) + this.setState({ todos: response }) @@ -33,12 +34,16 @@ class App extends Component { const todoInfo = { title: todoValue, - completed: false + completed: false, } // Optimistically add todo to UI - const optimisticTodoState = todos.concat({ - data: todoInfo - }) + const newTodoArray = [{ + data: todoInfo, + ts: new Date().getTime() * 10000 + }] + + const optimisticTodoState = newTodoArray.concat(todos) + this.setState({ todos: optimisticTodoState }) @@ -157,7 +162,14 @@ class App extends Component { return null } - return todos.map((todo, i) => { + const sortOrder = sortDate('ts') + const todosByDate = todos.sort(sortOrder) + + todosByDate.forEach((item) => { + console.log(item) + }) + + return todosByDate.map((todo, i) => { const { data, ref } = todo const id = getTodoId(todo) // only show delete button after create API response returns @@ -170,6 +182,7 @@ class App extends Component { ) } const completedClass = (data.completed) ? 'todo-completed' : '' + const icon = (data.completed) ? '#todo__box__done' : '#todo__box' return (