diff --git a/README.md b/README.md index b44a8f6..e924db6 100644 --- a/README.md +++ b/README.md @@ -12,24 +12,24 @@ Try it out on your own account via this link: 1. Clone down the repository - ``` - git clone + ```bash + git clone git@github.com:netlify/netlify-faunadb-example.git ``` 2. Install the dependencies - ``` + ```bash npm install ``` 3. Bootstrap your FaunaDB table - ``` + ```bash npm run bootstrap ``` 4. Run project locally - ``` + ```bash npm start ``` diff --git a/package.json b/package.json index abd9485..8babef4 100644 --- a/package.json +++ b/package.json @@ -9,16 +9,15 @@ "react-scripts": "1.1.4" }, "scripts": { - "bootstrap": "node ./_init-fauna-database.js", - "checkForFaunaKey": "node ./_check-for-fauna-key.js", + "bootstrap": "node ./scripts/bootstrap-fauna-database.js", + "checkForFaunaKey": "node ./scripts/check-for-fauna-key.js", "start": "npm-run-all --parallel checkForFaunaKey startApp startServer", "startApp": "react-scripts start", "startServer": "netlify-lambda serve functions -c ./webpack.config.js", "build": "npm-run-all --parallel build:**", "build:app": "react-scripts build", "build:functions": "netlify-lambda build functions -c ./webpack.config.js", - "test": "react-scripts test --env=jsdom", - "eject": "react-scripts eject" + "test": "react-scripts test --env=jsdom" }, "devDependencies": { "netlify-lambda": "^0.4.0", diff --git a/_init-fauna-database.js b/scripts/bootstrap-fauna-database.js similarity index 100% rename from _init-fauna-database.js rename to scripts/bootstrap-fauna-database.js diff --git a/_check-for-fauna-key.js b/scripts/check-for-fauna-key.js similarity index 100% rename from _check-for-fauna-key.js rename to scripts/check-for-fauna-key.js diff --git a/src/App.js b/src/App.js index 15703a0..55a3bef 100644 --- a/src/App.js +++ b/src/App.js @@ -1,10 +1,11 @@ import React, { Component } from 'react' -import api from './utils/api' import ContentEditable from './components/ContentEditable' import AppHeader from './components/AppHeader' +import api from './utils/api' +import sortByDate from './utils/sortByDate' import './App.css' -class App extends Component { +export default class App extends Component { state = { todos: [] } @@ -159,16 +160,15 @@ class App extends Component { const { todos } = this.state if (!todos || !todos.length) { + // Loading State here return null } - const sortOrder = sortDate('ts') + const timeStampKey = 'ts' + const orderBy = 'desc' // or `asc` + const sortOrder = sortByDate(timeStampKey, orderBy) const todosByDate = todos.sort(sortOrder) - todosByDate.forEach((item) => { - console.log(item) - }) - return todosByDate.map((todo, i) => { const { data, ref } = todo const id = getTodoId(todo) @@ -181,10 +181,9 @@ class App extends Component { ) } - const completedClass = (data.completed) ? 'todo-completed' : '' - const icon = (data.completed) ? '#todo__box__done' : '#todo__box' + const boxIcon = (data.completed) ? '#todo__box__done' : '#todo__box' return ( -
+
- {deleteButton}
) @@ -216,6 +214,7 @@ class App extends Component { render() { return (
+
@@ -240,18 +239,6 @@ class App extends Component { } } -function sortDate(dateKey, order) { - return function (a, b) { - const timeA = new Date(a[dateKey]).getTime() - const timeB = new Date(b[dateKey]).getTime() - if (order === 'asc') { - return timeA - timeB - } - // default 'desc' descending order - return timeB - timeA - } -} - function removeOptimisticTodo(todos) { // return all 'real' todos return todos.filter((todo) => { @@ -265,5 +252,3 @@ function getTodoId(todo) { } return todo.ref['@ref'].split('/').pop() } - -export default App diff --git a/src/utils/sortByDate.js b/src/utils/sortByDate.js new file mode 100644 index 0000000..6ddbdb7 --- /dev/null +++ b/src/utils/sortByDate.js @@ -0,0 +1,11 @@ +export default function sortDate(dateKey, order) { + return function (a, b) { + const timeA = new Date(a[dateKey]).getTime() + const timeB = new Date(b[dateKey]).getTime() + if (order === 'asc') { + return timeA - timeB + } + // default 'desc' descending order + return timeB - timeA + } +}