├── .gitignore ├── LICENSE ├── README.md ├── package.json ├── public ├── favicon.ico ├── index.html └── manifest.json └── src ├── App.css ├── App.js ├── App.test.js ├── ColumnList.css ├── ColumnList.js ├── ConfirmDialog.js ├── If.js ├── MobileTearSheet.js ├── index.css ├── index.js ├── logo.svg └── registerServiceWorker.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | yarn.lock 3 | .DS_Store 4 | .idea/ 5 | npm-debug.log* 6 | yarn-debug.log* 7 | yarn-error.log* 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Vin Busquet 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # React To-Do List 2 | 3 | This is a simple To-Do list app done with React. All tasks are saved into browser's local storage only. The app development 4 | was inspired by the first brazilian live coding of the [React Nanodegree Program](https://udacity.com/course/react-nanodegree--nd019). 5 | 6 | Todo List 7 | 8 | ## Demo 9 | 10 | [computationalcore.github.io/react-to-do-list](https://computationalcore.github.io/react-to-do-list) 11 | 12 | ## Getting Started 13 | 14 | These instructions will get you a copy of the project up and running on your local machine for development and testing 15 | purposes. 16 | 17 | ### Prerequisites 18 | 19 | The project can be built with npm or yarn, so choose one of the approach bellow in case you don't 20 | have any installed on your system. 21 | 22 | * npm is distributed with Node.js which means that when you download Node.js, 23 | you automatically get npm installed on your computer. [Download Node.js](https://nodejs.org/en/download/) 24 | 25 | or 26 | 27 | * Yarn is a package manager built by Facebook Team and seems to be faster than npm in general. [Download Yarn](https://yarnpkg.com/en/docs/install) 28 | 29 | ### Installing 30 | 31 | To download the project follow the instructions bellow 32 | 33 | ``` 34 | git clone https://github.com/computationalcore/react-to-do-list 35 | cd myreads 36 | ``` 37 | 38 | Install dependencies and run with: 39 | 40 | npm 41 | ``` 42 | npm install 43 | npm start 44 | ``` 45 | or 46 | 47 | yarn 48 | ``` 49 | yarn install 50 | yarn start 51 | ``` 52 | 53 | ## Versions 54 | 55 | v1.0 56 | * Default project implementation 57 | 58 | v1.1 59 | * Change to material UI based interface 60 | * Task transitions animations 61 | * Remove tasks capabilities 62 | 63 | ## Authors 64 | Vin Busquet 65 | * [https://github.com/computationalcore](https://github.com/computationalcore) 66 | 67 | ## License 68 | 69 | This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details 70 | 71 | 72 | ## Acknowledgments 73 | * [Udacity](https://www.udacity.com/) 74 | * [Matheus Marsiglio](https://github.com/mtmr0x) 75 | * [Thales Moreira Carvalho](https://github.com/thalescomp) -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "to-do-list", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "material-ui": "^0.19.4", 7 | "prop-types": "^15.5.8", 8 | "react": "^15.6.1", 9 | "react-dom": "^15.6.1", 10 | "react-scripts": "1.0.14", 11 | "react-swipeable-views": "^0.12.10", 12 | "react-transition-group": "^1.2.1", 13 | "sort-by": "^1.2.0" 14 | }, 15 | "scripts": { 16 | "start": "react-scripts start", 17 | "build": "react-scripts build", 18 | "test": "react-scripts test --env=jsdom", 19 | "eject": "react-scripts eject" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/computationalcore/react-to-do-list/9c19e5954b82d1420bc75f4300f650a6269b1142/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 11 | 12 | 13 | 22 | React App 23 | 24 | 25 | 28 |
29 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | } 10 | ], 11 | "start_url": "./index.html", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | animation: App-logo-spin infinite 20s linear; 7 | height: 80px; 8 | } 9 | 10 | .App-header { 11 | background-color: #222; 12 | height: 150px; 13 | padding: 20px; 14 | color: white; 15 | } 16 | 17 | .App-title { 18 | font-size: 1.5em; 19 | } 20 | 21 | .App-intro { 22 | font-size: large; 23 | } 24 | 25 | @keyframes App-logo-spin { 26 | from { transform: rotate(0deg); } 27 | to { transform: rotate(360deg); } 28 | } 29 | 30 | .app-separator { 31 | position: static; 32 | height: 228px; 33 | } 34 | 35 | .enable-remove-mode { 36 | position: fixed; 37 | right: 25px; 38 | bottom: 25px; 39 | } 40 | .remove-mode { 41 | padding-top: 10px; 42 | } 43 | 44 | .swipeable-views { 45 | padding: 10px; 46 | } 47 | 48 | /* task transition animations */ 49 | 50 | .task-animation-enter { 51 | opacity: 0.01; 52 | height: 0; 53 | } 54 | 55 | .task-animation-enter.task-animation-enter-active { 56 | opacity: 1; 57 | height: 56px; 58 | transition: 500ms; 59 | } 60 | 61 | .task-animation-leave { 62 | opacity: 1; 63 | height: 56px; 64 | } 65 | 66 | .task-animation-leave.task-animation-leave-active { 67 | opacity: 0.01; 68 | height: 0; 69 | transition: 300ms; 70 | } 71 | 72 | /* remove mode transition animations */ 73 | 74 | .remove-mode-animation-enter { 75 | opacity: 0.01; 76 | height: 0; 77 | } 78 | 79 | .remove-mode-animation-enter.remove-mode-animation-enter-active { 80 | opacity: 1; 81 | height: 36px; 82 | transition: 300ms; 83 | } 84 | 85 | .remove-mode-animation-leave { 86 | opacity: 1; 87 | height: 36px; 88 | } 89 | 90 | .remove-mode-animation-leave.remove-mode-animation-leave-active { 91 | opacity: 0.01; 92 | height: 0; 93 | transition: 300ms; 94 | } -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import React, {Component} from 'react'; 2 | import sortBy from 'sort-by'; 3 | import {CSSTransitionGroup} from 'react-transition-group'; 4 | import SwipeableViews from 'react-swipeable-views'; 5 | import AppBar from 'material-ui/AppBar'; 6 | import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider'; 7 | import TextField from 'material-ui/TextField'; 8 | import RaisedButton from 'material-ui/RaisedButton'; 9 | import {Tabs, Tab} from 'material-ui/Tabs'; 10 | import FloatingActionButton from 'material-ui/FloatingActionButton'; 11 | import CheckIcon from 'material-ui/svg-icons/action/check-circle'; 12 | import ListIcon from 'material-ui/svg-icons/action/list'; 13 | import TodoIcon from 'material-ui/svg-icons/action/today'; 14 | import EditIcon from 'material-ui/svg-icons/action/delete'; 15 | import CloseIcon from 'material-ui/svg-icons/content/delete-sweep'; 16 | import ColumnList from './ColumnList'; 17 | import ConfirmDialog from './ConfirmDialog'; 18 | import If from './If'; 19 | import './App.css'; 20 | 21 | /** 22 | * @description Main App component. 23 | * @constructor 24 | * @param {Object} props - The props that were defined by the caller of this component. 25 | */ 26 | class App extends Component { 27 | constructor(props) { 28 | super(props); 29 | 30 | /** 31 | * @typedef {Object} ComponentState 32 | * @property {Object[]} items - All list items of the app. 33 | * @property {number} taskIdCounter - The index of the last task added. 34 | * @property {boolean} submitDisabled - Indicates whether submit is disabled. 35 | * @property {number} slideIndex - The index of the tab component. 36 | * @property {boolean} dialogOpen - Visibility of the clear tasks dialog. 37 | * @property {boolean} removeMode - Indicates if the remove mode is active. 38 | */ 39 | 40 | /** @type {ComponentState} */ 41 | this.state = { 42 | items: [], 43 | taskIdCounter: 0, 44 | submitDisabled: true, 45 | slideIndex: 0, 46 | dialogOpen: false, 47 | removeMode: false, 48 | }; 49 | } 50 | 51 | /** 52 | * Lifecycle event handler called just after the App loads into the DOM. 53 | * Get any saved items and taskIdCounter from the local storage and setup state with it. 54 | */ 55 | componentWillMount() { 56 | const toDoListItems = window.localStorage.getItem('toDoListItems') || '[]'; 57 | const taskIdCounter = window.localStorage.getItem('taskIdCounter') || 0; 58 | //Get 59 | this.setState( 60 | { 61 | items: JSON.parse(toDoListItems), 62 | taskIdCounter: taskIdCounter, 63 | } 64 | ); 65 | } 66 | 67 | /** 68 | * @description Add task to the To Do list. 69 | */ 70 | addTask = () => { 71 | const input = this.taskInput.input || {}; 72 | const { value = '' } = input; 73 | 74 | if (value === '') return; 75 | 76 | this.setState(previousState => { 77 | const { items = [] } = previousState; 78 | const { taskIdCounter = 0 } = previousState; 79 | const taskId = taskIdCounter+1; 80 | const newTask = { 81 | id: taskId, 82 | title: value, 83 | status: 'To Do' 84 | }; 85 | items.push(newTask); 86 | return { 87 | items: items.sort(sortBy('id')), 88 | submitDisabled: true, 89 | taskIdCounter: taskId, 90 | } 91 | }, function stateUpdateComplete() { 92 | this.taskInput.input.value = ''; 93 | this.updateLocalStorageItems(this.state.items); 94 | this.updateTaskCounter(this.state.taskIdCounter); 95 | }.bind(this)); 96 | }; 97 | 98 | /** 99 | * @description Update task toggling between To Do/Done status. 100 | * @param {Object} task - The task to be updated 101 | */ 102 | handleUpdateTask = (task) => { 103 | this.setState(previousState => { 104 | const { items } = previousState; 105 | const filteredItems = items.filter( item => item.id !== task.id); 106 | task.status = (task.status === 'To Do') ? 'Done' : 'To Do'; 107 | filteredItems.push(task); 108 | return { 109 | items: filteredItems.sort(sortBy('id')) 110 | } 111 | }, function stateUpdateComplete() { 112 | this.updateLocalStorageItems(this.state.items); 113 | }.bind(this)); 114 | }; 115 | 116 | /** 117 | * @description Remove task. 118 | * @param {Object} task - The task to be removed. 119 | */ 120 | handleRemoveTask = (task) => { 121 | this.setState(previousState => { 122 | const { items } = previousState; 123 | const filteredItems = items.filter( item => item.id !== task.id); 124 | return { 125 | items: filteredItems.sort(sortBy('id')) 126 | } 127 | }, function stateUpdateComplete() { 128 | this.updateLocalStorageItems(this.state.items); 129 | }.bind(this)); 130 | }; 131 | 132 | /** 133 | * @description Handle the Account Key TextField input change. It enable the submit button if field is not empty or 134 | * disable it otherwise. 135 | * @param {Object} event - On click event object 136 | * @param {value} value - The task description 137 | */ 138 | handleTextFieldChange = (event, value) => { 139 | if((value.length > 0) && this.state.submitDisabled){ 140 | this.setState({submitDisabled: false}); 141 | } 142 | else if((value.length === 0) && !this.state.submitDisabled){ 143 | this.setState({submitDisabled: true}); 144 | } 145 | }; 146 | 147 | /** 148 | * @description Save items to local storage. 149 | * @param {Object[]} items - Array of items/tasks to be saved. 150 | */ 151 | updateLocalStorageItems = (items) => { 152 | window.localStorage.setItem('toDoListItems', JSON.stringify(items)); 153 | }; 154 | 155 | /** 156 | * @description Update current taskId into local storage. 157 | * @param {number} taskCounter - Id of the task to be saved at local storage. 158 | */ 159 | updateTaskCounter = (taskCounter) => { 160 | window.localStorage.setItem('taskIdCounter', taskCounter); 161 | }; 162 | 163 | /** 164 | * @description Handle the tab change. 165 | * @param {number} value - The index of the Tab. 166 | */ 167 | handleChange = (value) => { 168 | this.setState({ 169 | slideIndex: value, 170 | }, function stateUpdateComplete() { 171 | // Fix scroll in swipe transitions 172 | window.scrollTo(0, 0); 173 | }); 174 | }; 175 | 176 | 177 | /** 178 | * @description Enable the remove task mode. 179 | */ 180 | enableRemoveMode = () => { 181 | if (!this.state.removeMode) { 182 | this.setState({removeMode: true}); 183 | } 184 | }; 185 | 186 | /** 187 | * @description Disable the remove task mode. 188 | */ 189 | disableRemoveMode = () => { 190 | if (this.state.removeMode) { 191 | this.setState({removeMode: false}); 192 | } 193 | }; 194 | 195 | /** 196 | * @description Remove all tasks from the App. 197 | */ 198 | clearTasks = () => { 199 | this.handleDialogClose(); 200 | this.setState({removeMode: false, items: []}, function stateUpdateComplete() { 201 | // Update local storage 202 | this.updateLocalStorageItems(this.state.items); 203 | }); 204 | }; 205 | 206 | /** 207 | * @description Open the clear tasks dialog. 208 | */ 209 | handleDialogOpen = () => { 210 | this.setState({dialogOpen: true}); 211 | }; 212 | 213 | /** 214 | * @description Close the clear task dialog. 215 | */ 216 | handleDialogClose = () => { 217 | this.setState({dialogOpen: false}); 218 | }; 219 | 220 | /** 221 | * @description Handle the enter key pressed under the add task input. 222 | * @param {Object} e - Key press event 223 | */ 224 | keyPress = (e) => { 225 | // If Enter key 226 | if(e.keyCode === 13){ 227 | // Call method to add the task if not empty 228 | this.addTask(); 229 | // put the login here 230 | } 231 | }; 232 | 233 | render() { 234 | const { items = [] } = this.state; 235 | const columns = [ 236 | { title: 'To Do', items: items.filter( item => item.status === 'To Do'), icon: }, 237 | { title: 'Done', items: items.filter( item => item.status === 'Done'), icon: }, 238 | { title: 'All', items, icon: }, 239 | ]; 240 | return ( 241 | 242 |
243 | {/* Clear Tasks Confirmation Dialog */} 244 | 251 | To-Do List} 253 | showMenuIconButton={false} 254 | style={{backgroundColor: 'rgb(0, 151, 167)', position: 'fixed', zIndex: 9999,}} 255 | /> 256 |
257 |
258 | { 262 | this.taskInput = taskInput; 263 | }} 264 | disabled={this.state.removeMode} 265 | style={{margin: 10, width: '60%', maxWidth: 300}} 266 | onChange={this.handleTextFieldChange} 267 | onKeyDown={this.keyPress} 268 | /> 269 | 274 | 278 | {columns.map((column,index) => ( 279 | 285 | {column.title} ({(column.title !== 'All') ? column.items.filter(item => item.status === column.title).length: items.length}) 286 |
287 | } 288 | /> 289 | ))} 290 | 291 |
292 |
-
293 | 297 | {this.state.removeMode && 298 |
299 | 304 |
305 | } 306 |
307 | 312 | {columns.map((column,index) => ( 313 |
316 | 323 |
324 | ))} 325 |
326 |
327 |
328 |
329 |
330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 |
341 | 342 |
343 | ); 344 | } 345 | } 346 | 347 | export default App; 348 | -------------------------------------------------------------------------------- /src/App.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import App from './App'; 4 | 5 | it('renders without crashing', () => { 6 | const div = document.createElement('div'); 7 | ReactDOM.render(, div); 8 | }); 9 | -------------------------------------------------------------------------------- /src/ColumnList.css: -------------------------------------------------------------------------------- 1 | .app-lists { 2 | display: flex; 3 | } 4 | 5 | .app-lists .column-list { 6 | width: 100%; 7 | } 8 | 9 | .app-lists .column-list .list-items { 10 | list-style: none; 11 | margin: 0; 12 | padding: 20px 0; 13 | } 14 | 15 | .app-lists .column-list .list-items li { 16 | position: relative; 17 | width: 80%; 18 | padding: 10px 0; 19 | border-radius: 3px; 20 | background-color: #f4fdfe; 21 | margin-bottom: 10px; 22 | } 23 | 24 | .app-lists .column-list .list-items li input { 25 | margin: 0 10px; 26 | } 27 | 28 | .task-done { 29 | text-decoration: line-through; 30 | } 31 | 32 | -------------------------------------------------------------------------------- /src/ColumnList.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import PropTypes from 'prop-types'; 3 | import {CSSTransitionGroup} from 'react-transition-group'; 4 | import Checkbox from 'material-ui/Checkbox'; 5 | import {List, ListItem} from 'material-ui/List'; 6 | import MobileTearSheet from './MobileTearSheet'; 7 | import DeleteIcon from 'material-ui/svg-icons/action/delete'; 8 | import './ColumnList.css'; 9 | 10 | /** 11 | * This object is used for type checking the props of the component. 12 | */ 13 | const propTypes = { 14 | title: PropTypes.string.isRequired, 15 | items: PropTypes.array, 16 | updateTask: PropTypes.func.isRequired, 17 | removeTask: PropTypes.func.isRequired, 18 | removeMode: PropTypes.bool, 19 | }; 20 | 21 | /** 22 | * This object sets default values to the optional props. 23 | */ 24 | const defaultProps = { 25 | items: [], 26 | removeMode: [], 27 | }; 28 | 29 | /** 30 | * This callback type is called `removeTask` and is displayed as a global symbol. 31 | * 32 | * @callback removeTask 33 | * @param {Object} event - The event generate by remove click. 34 | */ 35 | 36 | /** 37 | * This callback type is called `updateTask` and is displayed as a global symbol. 38 | * 39 | * @callback updateTask 40 | * @param {Object} target - The event generate by onChange. 41 | * @param {Object} item - The item to be updated. 42 | */ 43 | 44 | /** 45 | * @description Represents the column list element. 46 | * @param {Object} props - The props that were defined by the caller of this component. 47 | * @param {string} props.title - The title of this column list. 48 | * @param {Object[]} [props.items=[]] - The array of tasks/items of the list. 49 | * @param {removeTask} props.removeTask - Callback executed when user click to remove the task. 50 | * @param {updateTask} props.updateTask - Callback executed when when user the done checkbox. 51 | * @param {boolean} [props.removeMode=false] - Indicates whether the app is in remove mode. 52 | * @returns {XML} Return the stateless component markup 53 | * @constructor 54 | */ 55 | const ColumnList = (props) => { 56 | return ( 57 |
58 | 59 | 60 | 64 | {props.items.map(item => ( 65 | (props.removeMode ? props.removeTask(item) : props.updateTask(item))} 68 | rightIcon={props.removeMode ? : 69 | } 70 | > 71 | 77 | 78 | ))} 79 | 80 | 81 | 82 |
83 | ) 84 | }; 85 | 86 | // Type checking the props of the component 87 | ColumnList.propTypes = propTypes; 88 | 89 | // Assign default values to the optional props 90 | ColumnList.defaultProps = defaultProps; 91 | 92 | export default ColumnList; 93 | -------------------------------------------------------------------------------- /src/ConfirmDialog.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import PropTypes from 'prop-types'; 3 | import Dialog from 'material-ui/Dialog'; 4 | import FlatButton from 'material-ui/FlatButton'; 5 | import './App.css'; 6 | 7 | /** 8 | * This object is used for type checking the props of the component. 9 | */ 10 | const propTypes = { 11 | title: PropTypes.string.isRequired, 12 | message: PropTypes.string.isRequired, 13 | open: PropTypes.bool.isRequired, 14 | onCancel: PropTypes.func.isRequired, 15 | onConfirm: PropTypes.func.isRequired, 16 | }; 17 | 18 | /** 19 | * This callback type is called `cancelCallback` and is displayed as a global symbol. 20 | * 21 | * @callback cancelCallback 22 | */ 23 | 24 | /** 25 | * This callback type is called `confirmCallback` and is displayed as a global symbol. 26 | * 27 | * @callback confirmCallback 28 | */ 29 | 30 | /** 31 | * @description Represents a material UI based Confirm Dialog. 32 | * @constructor 33 | * @param {Object} props - The props that were defined by the caller of this component. 34 | * @param {string} props.title - The message to be displayed by the dialog. 35 | * @param {boolean} props.open - The visibility of the dialog. 36 | * @param {cancelCallback} props.onCancel - The callback to execute when the user hits the cancel button. 37 | * @param {confirmCallback} props.onConfirm - The callback to execute when the user hits the confirm button. 38 | */ 39 | function ConfirmDialog(props) { 40 | 41 | // Confirm Dialog buttons 42 | const dialogActions = [ 43 | , 48 | , 55 | ]; 56 | 57 | return ( 58 |
59 | 65 | {props.message} 66 | 67 |
68 | ); 69 | } 70 | 71 | // Type checking the props of the component 72 | ConfirmDialog.propTypes = propTypes; 73 | 74 | export default ConfirmDialog; -------------------------------------------------------------------------------- /src/If.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Evaluate expression and return object or false. 3 | * It is used to replace ternary operations to make the JSX more readable and debuggable. 4 | * @param {boolean} test 5 | * @param {Object|boolean} children 6 | * @constructor 7 | */ 8 | const If = ({ test, children}) => test ? children: false; 9 | 10 | export default If; 11 | -------------------------------------------------------------------------------- /src/MobileTearSheet.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import PropTypes from 'prop-types'; 3 | 4 | /** 5 | * This object is used for type checking the props of the component. 6 | */ 7 | const propTypes = { 8 | children: PropTypes.object.isRequired, 9 | }; 10 | 11 | /** 12 | * Represents a component that adds a zigzag-bottomed outline to a material-ui list component. 13 | * @param {Object} props - The props that were defined by the caller of this component. 14 | * @param {Object} props.children - Children component. 15 | * @returns {XML} 16 | * @constructor 17 | */ 18 | const MobileTearSheet = (props) => { 19 | 20 | const height = "100%"; 21 | const styles = { 22 | root: { 23 | margin: '0 auto', 24 | maxWidth: 500, 25 | width: '100%', 26 | }, 27 | container: { 28 | border: 'solid 1px #d9d9d9', 29 | borderBottom: 'none', 30 | height: height, 31 | overflow: 'hidden', 32 | }, 33 | bottomTear: { 34 | display: 'block', 35 | position: 'relative', 36 | marginTop: -10, 37 | maxWidth: 500, 38 | }, 39 | }; 40 | 41 | return ( 42 |
43 |
44 | {props.children} 45 |
46 |
47 | 54 | 61 | 62 |
63 |
64 | ); 65 | }; 66 | 67 | // Type checking the props of the component 68 | MobileTearSheet.propTypes = propTypes; 69 | 70 | export default MobileTearSheet; -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | padding: 0; 4 | font-family: sans-serif; 5 | } 6 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | import registerServiceWorker from './registerServiceWorker'; 6 | 7 | ReactDOM.render(, document.getElementById('root')); 8 | registerServiceWorker(); 9 | -------------------------------------------------------------------------------- /src/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/registerServiceWorker.js: -------------------------------------------------------------------------------- 1 | // In production, we register a service worker to serve assets from local cache. 2 | 3 | // This lets the app load faster on subsequent visits in production, and gives 4 | // it offline capabilities. However, it also means that developers (and users) 5 | // will only see deployed updates on the "N+1" visit to a page, since previously 6 | // cached resources are updated in the background. 7 | 8 | // To learn more about the benefits of this model, read https://goo.gl/KwvDNy. 9 | // This link also includes instructions on opting out of this behavior. 10 | 11 | const isLocalhost = Boolean( 12 | window.location.hostname === 'localhost' || 13 | // [::1] is the IPv6 localhost address. 14 | window.location.hostname === '[::1]' || 15 | // 127.0.0.1/8 is considered localhost for IPv4. 16 | window.location.hostname.match( 17 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ 18 | ) 19 | ); 20 | 21 | export default function register() { 22 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { 23 | // The URL constructor is available in all browsers that support SW. 24 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location); 25 | if (publicUrl.origin !== window.location.origin) { 26 | // Our service worker won't work if PUBLIC_URL is on a different origin 27 | // from what our page is served on. This might happen if a CDN is used to 28 | // serve assets; see https://github.com/facebookincubator/create-react-app/issues/2374 29 | return; 30 | } 31 | 32 | window.addEventListener('load', () => { 33 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; 34 | 35 | if (isLocalhost) { 36 | // This is running on localhost. Lets check if a service worker still exists or not. 37 | checkValidServiceWorker(swUrl); 38 | } else { 39 | // Is not local host. Just register service worker 40 | registerValidSW(swUrl); 41 | } 42 | }); 43 | } 44 | } 45 | 46 | function registerValidSW(swUrl) { 47 | navigator.serviceWorker 48 | .register(swUrl) 49 | .then(registration => { 50 | registration.onupdatefound = () => { 51 | const installingWorker = registration.installing; 52 | installingWorker.onstatechange = () => { 53 | if (installingWorker.state === 'installed') { 54 | if (navigator.serviceWorker.controller) { 55 | // At this point, the old content will have been purged and 56 | // the fresh content will have been added to the cache. 57 | // It's the perfect time to display a "New content is 58 | // available; please refresh." message in your web app. 59 | console.log('New content is available; please refresh.'); 60 | } else { 61 | // At this point, everything has been precached. 62 | // It's the perfect time to display a 63 | // "Content is cached for offline use." message. 64 | console.log('Content is cached for offline use.'); 65 | } 66 | } 67 | }; 68 | }; 69 | }) 70 | .catch(error => { 71 | console.error('Error during service worker registration:', error); 72 | }); 73 | } 74 | 75 | function checkValidServiceWorker(swUrl) { 76 | // Check if the service worker can be found. If it can't reload the page. 77 | fetch(swUrl) 78 | .then(response => { 79 | // Ensure service worker exists, and that we really are getting a JS file. 80 | if ( 81 | response.status === 404 || 82 | response.headers.get('content-type').indexOf('javascript') === -1 83 | ) { 84 | // No service worker found. Probably a different app. Reload the page. 85 | navigator.serviceWorker.ready.then(registration => { 86 | registration.unregister().then(() => { 87 | window.location.reload(); 88 | }); 89 | }); 90 | } else { 91 | // Service worker found. Proceed as normal. 92 | registerValidSW(swUrl); 93 | } 94 | }) 95 | .catch(() => { 96 | console.log( 97 | 'No internet connection found. App is running in offline mode.' 98 | ); 99 | }); 100 | } 101 | 102 | export function unregister() { 103 | if ('serviceWorker' in navigator) { 104 | navigator.serviceWorker.ready.then(registration => { 105 | registration.unregister(); 106 | }); 107 | } 108 | } 109 | --------------------------------------------------------------------------------