import React from 'react'; import ReactDOM from 'react-dom'; import '../src/index.css'; import EditableLabel from 'react-inline-editing'; import { v4 as uuidv4 } from 'uuid'; function TodoItem(props) { let checkbox = props.enabled ? props.updateBox(event)} checked /> : props.updateBox(event)} />; return (
{checkbox}
); } class App extends React.Component { constructor(props) { super(props); this.state = { todos: JSON.parse(localStorage.getItem('todos')), }; } render() { return (

facere cito

); } handleClearClick() { window.localStorage.setItem('todos', JSON.stringify([])); window.location.reload(); this.forceUpdate(); } handleResetClick() { window.localStorage.setItem('todos', JSON.stringify([ { id: uuidv4(), enabled: false, contents: "👋 Hello! Welcome to facere cito." }, { id: uuidv4(), enabled: false, contents: "📝 A sleek, minimal, and easy way to keep track of your tasks." }, { id: uuidv4(), enabled: false, contents: "✍ Click any of these tasks to edit their text. Click outside of the text box to save." }, { id: uuidv4(), enabled: false, contents: "🙂 Task text can include any Unicode, including emojis." }, { id: uuidv4(), enabled: false, contents: "❌ Delete tasks by shift-clicking the tick button, or by clearing the text." }, { id: uuidv4(), enabled: true, contents: "✅ Completed tasks go to the bottom." }, ])); window.location.reload(); this.forceUpdate(); } handleAddClick() { window.localStorage.setItem('todos', JSON.stringify(this.state.todos.concat([{ id: uuidv4(), enabled: false, contents: "Hello! Click me to edit!" }]))); window.location.reload(); this.forceUpdate(); } _handleFocusOut(text, id) { let newTodos = this.state.todos; let todoIndex = newTodos.findIndex(function (t) { return t.id === id; }); if (text === "") { newTodos.splice(todoIndex, 1); } else { newTodos[todoIndex].contents = text; } window.localStorage.setItem('todos', JSON.stringify(newTodos)); this.forceUpdate(); } updateBox(event, id) { let newTodos = this.state.todos; let todoIndex = newTodos.findIndex(function (t) { return t.id === id; }); if (event.shiftKey) { newTodos.splice(todoIndex, 1); } else { newTodos[todoIndex].enabled = !newTodos[todoIndex].enabled; } window.localStorage.setItem('todos', JSON.stringify(newTodos)); this.forceUpdate(); } } if (!window.localStorage.getItem('todos')) { window.localStorage.setItem('todos', JSON.stringify([ { id: uuidv4(), enabled: false, contents: "👋 Hello! Welcome to facere cito." }, { id: uuidv4(), enabled: false, contents: "📝 A sleek, minimal, and easy way to keep track of your tasks." }, { id: uuidv4(), enabled: false, contents: "✍ Click any of these tasks to edit their text. Click outside of the text box to save." }, { id: uuidv4(), enabled: false, contents: "🙂 Task text can include any Unicode, including emojis." }, { id: uuidv4(), enabled: false, contents: "❌ Delete tasks by shift-clicking the tick button, or by clearing the text." }, { id: uuidv4(), enabled: true, contents: "✅ Completed tasks go to the bottom." }, ])); } ReactDOM.render( , document.getElementById('root') );