├── .gitignore ├── .vscode └── settings.json ├── Pipfile ├── Pipfile.lock ├── README.md ├── backend ├── backend │ ├── __init__.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py ├── db.sqlite3 ├── manage.py └── todo │ ├── __init__.py │ ├── admin.py │ ├── apps.py │ ├── migrations │ ├── 0001_initial.py │ └── __init__.py │ ├── models.py │ ├── serializers.py │ ├── tests.py │ └── views.py └── frontend ├── README.md ├── package.json ├── public ├── favicon.ico ├── index.html └── manifest.json ├── src ├── App.css ├── App.js ├── App.test.js ├── components │ └── Modal.js ├── index.css ├── index.js ├── logo.svg └── serviceWorker.js └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "python.pythonPath": "/home/jordan/.local/share/virtualenvs/django-todo-react-rwJ1BMxH/bin/python" 3 | } -------------------------------------------------------------------------------- /Pipfile: -------------------------------------------------------------------------------- 1 | [[source]] 2 | url = "https://pypi.org/simple" 3 | verify_ssl = true 4 | name = "pypi" 5 | 6 | [packages] 7 | django = "*" 8 | 9 | [dev-packages] 10 | 11 | [requires] 12 | python_version = "3.6" 13 | -------------------------------------------------------------------------------- /Pipfile.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_meta": { 3 | "hash": { 4 | "sha256": "68309cd71a258c30a39567fce09a09ad5c4ff0bdc85b6fba22b47598c985c883" 5 | }, 6 | "pipfile-spec": 6, 7 | "requires": { 8 | "python_version": "3.6" 9 | }, 10 | "sources": [ 11 | { 12 | "name": "pypi", 13 | "url": "https://pypi.org/simple", 14 | "verify_ssl": true 15 | } 16 | ] 17 | }, 18 | "default": { 19 | "django": { 20 | "hashes": [ 21 | "sha256:1ffab268ada3d5684c05ba7ce776eaeedef360712358d6a6b340ae9f16486916", 22 | "sha256:dd46d87af4c1bf54f4c926c3cfa41dc2b5c15782f15e4329752ce65f5dad1c37" 23 | ], 24 | "index": "pypi", 25 | "version": "==2.1.3" 26 | }, 27 | "pytz": { 28 | "hashes": [ 29 | "sha256:31cb35c89bd7d333cd32c5f278fca91b523b0834369e757f4c5641ea252236ca", 30 | "sha256:8e0f8568c118d3077b46be7d654cc8167fa916092e28320cde048e54bfc9f1e6" 31 | ], 32 | "version": "==2018.7" 33 | } 34 | }, 35 | "develop": {} 36 | } 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Introduction 2 | 3 | This is a simple Todo application built off Django (including the Django REST Framework for API CRUD operations) and React. 4 | 5 | ## Requirements 6 | * Python3 7 | * Pipenv 8 | 9 | ## Getting started 10 | 1. Clone the project to your machine ```[git clone https://github.com/Jordanirabor/django-todo-react]``` 11 | 2. Navigate into the diretory ```[cd django-todo-react]``` 12 | 3. Source the virtual environment ```[pipenv shell]``` 13 | 4. Install the dependencies ```[pipenv install]``` 14 | 5. Navigate into the frontend directory ```[cd frontend]``` 15 | 5. Install the dependencies ```[npm install]``` 16 | 17 | ## Run the application 18 | You will need two terminals pointed to the frontend and backend directories to start the servers for this application. 19 | 20 | 1. Run this command to start the backend server in the ```[backend]``` directory: ```[python manage.py runserver]``` (You have to run this command while you are sourced into the virtual environment) 21 | 2. Run this command to start the frontend development server in the ```[frontend]``` directory: ```[npm install]``` (This will start the frontend on the adddress [localhost:3000](http://localhost:3000)) 22 | 23 | ## Built With 24 | 25 | * [React](https://reactjs.org) - A progressive JavaScript framework. 26 | * [Python](https://www.python.org/) - A programming language that lets you work quickly and integrate systems more effectively. 27 | * [Django](http://djangoproject.org/) - A high-level Python Web framework that encourages rapid development and clean, pragmatic design. -------------------------------------------------------------------------------- /backend/backend/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jordanirabor/django-todo-react/f18e4ee5e0562c41d39e096eb83f3835e11bccd5/backend/backend/__init__.py -------------------------------------------------------------------------------- /backend/backend/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for backend project. 3 | 4 | Generated by 'django-admin startproject' using Django 2.1.3. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/2.1/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/2.1/ref/settings/ 11 | """ 12 | 13 | import os 14 | 15 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 16 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = 'l4y@!^rox=b*!x-qd9xa*nt%r$$zcp!p_d&1gh@b99s-#iqsj&' 24 | 25 | # SECURITY WARNING: don't run with debug turned on in production! 26 | DEBUG = True 27 | 28 | ALLOWED_HOSTS = [] 29 | 30 | 31 | # Application definition 32 | INSTALLED_APPS = [ 33 | 'django.contrib.admin', 34 | 'django.contrib.auth', 35 | 'django.contrib.contenttypes', 36 | 'django.contrib.sessions', 37 | 'django.contrib.messages', 38 | 'django.contrib.staticfiles', 39 | 'corsheaders', # add this 40 | 'rest_framework', # add this 41 | 'todo', 42 | ] 43 | 44 | 45 | MIDDLEWARE = [ 46 | 'corsheaders.middleware.CorsMiddleware', # add this 47 | 'django.middleware.security.SecurityMiddleware', 48 | 'django.contrib.sessions.middleware.SessionMiddleware', 49 | 'django.middleware.common.CommonMiddleware', 50 | 'django.middleware.csrf.CsrfViewMiddleware', 51 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 52 | 'django.contrib.messages.middleware.MessageMiddleware', 53 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 54 | ] 55 | 56 | ROOT_URLCONF = 'backend.urls' 57 | 58 | TEMPLATES = [ 59 | { 60 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 61 | 'DIRS': [], 62 | 'APP_DIRS': True, 63 | 'OPTIONS': { 64 | 'context_processors': [ 65 | 'django.template.context_processors.debug', 66 | 'django.template.context_processors.request', 67 | 'django.contrib.auth.context_processors.auth', 68 | 'django.contrib.messages.context_processors.messages', 69 | ], 70 | }, 71 | }, 72 | ] 73 | 74 | WSGI_APPLICATION = 'backend.wsgi.application' 75 | 76 | 77 | # Database 78 | # https://docs.djangoproject.com/en/2.1/ref/settings/#databases 79 | 80 | DATABASES = { 81 | 'default': { 82 | 'ENGINE': 'django.db.backends.sqlite3', 83 | 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 84 | } 85 | } 86 | 87 | 88 | # Password validation 89 | # https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators 90 | 91 | AUTH_PASSWORD_VALIDATORS = [ 92 | { 93 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 94 | }, 95 | { 96 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 97 | }, 98 | { 99 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 100 | }, 101 | { 102 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 103 | }, 104 | ] 105 | 106 | 107 | # Internationalization 108 | # https://docs.djangoproject.com/en/2.1/topics/i18n/ 109 | 110 | LANGUAGE_CODE = 'en-us' 111 | 112 | TIME_ZONE = 'UTC' 113 | 114 | USE_I18N = True 115 | 116 | USE_L10N = True 117 | 118 | USE_TZ = True 119 | 120 | 121 | # Static files (CSS, JavaScript, Images) 122 | # https://docs.djangoproject.com/en/2.1/howto/static-files/ 123 | 124 | STATIC_URL = '/static/' 125 | 126 | 127 | # we whitelist localhost:3000 because that's where frontend will be served 128 | CORS_ORIGIN_WHITELIST = ( 129 | 'localhost:3000/' 130 | ) 131 | -------------------------------------------------------------------------------- /backend/backend/urls.py: -------------------------------------------------------------------------------- 1 | 2 | # backend/urls.py 3 | 4 | from django.contrib import admin 5 | from django.urls import path, include # add this 6 | from rest_framework import routers # add this 7 | from todo import views # add this 8 | 9 | router = routers.DefaultRouter() # add this 10 | router.register(r'todos', views.TodoView, 'todo') # add this 11 | 12 | urlpatterns = [ 13 | path('admin/', admin.site.urls), 14 | path('api/', include(router.urls)) # add this 15 | ] -------------------------------------------------------------------------------- /backend/backend/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for backend project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /backend/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jordanirabor/django-todo-react/f18e4ee5e0562c41d39e096eb83f3835e11bccd5/backend/db.sqlite3 -------------------------------------------------------------------------------- /backend/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == '__main__': 6 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings') 7 | try: 8 | from django.core.management import execute_from_command_line 9 | except ImportError as exc: 10 | raise ImportError( 11 | "Couldn't import Django. Are you sure it's installed and " 12 | "available on your PYTHONPATH environment variable? Did you " 13 | "forget to activate a virtual environment?" 14 | ) from exc 15 | execute_from_command_line(sys.argv) 16 | -------------------------------------------------------------------------------- /backend/todo/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jordanirabor/django-todo-react/f18e4ee5e0562c41d39e096eb83f3835e11bccd5/backend/todo/__init__.py -------------------------------------------------------------------------------- /backend/todo/admin.py: -------------------------------------------------------------------------------- 1 | 2 | # todo/admin.py 3 | 4 | from django.contrib import admin 5 | from .models import Todo # add this 6 | 7 | class TodoAdmin(admin.ModelAdmin): # add this 8 | list_display = ('title', 'description', 'completed') # add this 9 | 10 | # Register your models here. 11 | admin.site.register(Todo, TodoAdmin) # add this -------------------------------------------------------------------------------- /backend/todo/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class TodoConfig(AppConfig): 5 | name = 'todo' 6 | -------------------------------------------------------------------------------- /backend/todo/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 2.1.3 on 2018-11-17 08:51 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | initial = True 9 | 10 | dependencies = [ 11 | ] 12 | 13 | operations = [ 14 | migrations.CreateModel( 15 | name='Todo', 16 | fields=[ 17 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 18 | ('title', models.CharField(max_length=120)), 19 | ('description', models.TextField()), 20 | ('completed', models.BooleanField(default=False)), 21 | ], 22 | ), 23 | ] 24 | -------------------------------------------------------------------------------- /backend/todo/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jordanirabor/django-todo-react/f18e4ee5e0562c41d39e096eb83f3835e11bccd5/backend/todo/migrations/__init__.py -------------------------------------------------------------------------------- /backend/todo/models.py: -------------------------------------------------------------------------------- 1 | 2 | # todo/models.py 3 | 4 | from django.db import models 5 | # Create your models here. 6 | 7 | # add this 8 | class Todo(models.Model): 9 | title = models.CharField(max_length=120) 10 | description = models.TextField() 11 | completed = models.BooleanField(default=False) 12 | 13 | def __str__(self): 14 | return self.title -------------------------------------------------------------------------------- /backend/todo/serializers.py: -------------------------------------------------------------------------------- 1 | 2 | # todo/serializers.py 3 | 4 | from rest_framework import serializers 5 | from .models import Todo 6 | 7 | class TodoSerializer(serializers.ModelSerializer): 8 | class Meta: 9 | model = Todo 10 | fields = ('id', 'title', 'description', 'completed') -------------------------------------------------------------------------------- /backend/todo/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /backend/todo/views.py: -------------------------------------------------------------------------------- 1 | 2 | # todo/views.py 3 | 4 | from django.shortcuts import render 5 | from rest_framework import viewsets # add this 6 | from .serializers import TodoSerializer # add this 7 | from .models import Todo # add this 8 | 9 | class TodoView(viewsets.ModelViewSet): # add this 10 | serializer_class = TodoSerializer # add this 11 | queryset = Todo.objects.all() # add this -------------------------------------------------------------------------------- /frontend/README.md: -------------------------------------------------------------------------------- 1 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 2 | 3 | ## Available Scripts 4 | 5 | In the project directory, you can run: 6 | 7 | ### `npm start` 8 | 9 | Runs the app in the development mode.
10 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 11 | 12 | The page will reload if you make edits.
13 | You will also see any lint errors in the console. 14 | 15 | ### `npm test` 16 | 17 | Launches the test runner in the interactive watch mode.
18 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 19 | 20 | ### `npm run build` 21 | 22 | Builds the app for production to the `build` folder.
23 | It correctly bundles React in production mode and optimizes the build for the best performance. 24 | 25 | The build is minified and the filenames include the hashes.
26 | Your app is ready to be deployed! 27 | 28 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 29 | 30 | ### `npm run eject` 31 | 32 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 33 | 34 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 35 | 36 | Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 37 | 38 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 39 | 40 | ## Learn More 41 | 42 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 43 | 44 | To learn React, check out the [React documentation](https://reactjs.org/). 45 | -------------------------------------------------------------------------------- /frontend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "frontend", 3 | "version": "0.1.0", 4 | "private": true, 5 | "proxy": "http://localhost:8000", 6 | "dependencies": { 7 | "axios": "^0.18.0", 8 | "bootstrap": "^4.1.3", 9 | "react": "^16.6.3", 10 | "react-dom": "^16.6.3", 11 | "react-scripts": "2.1.1", 12 | "reactstrap": "^6.5.0" 13 | }, 14 | "scripts": { 15 | "start": "react-scripts start", 16 | "build": "react-scripts build", 17 | "test": "react-scripts test", 18 | "eject": "react-scripts eject" 19 | }, 20 | "eslintConfig": { 21 | "extends": "react-app" 22 | }, 23 | "browserslist": [ 24 | ">0.2%", 25 | "not dead", 26 | "not ie <= 11", 27 | "not op_mini all" 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /frontend/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jordanirabor/django-todo-react/f18e4ee5e0562c41d39e096eb83f3835e11bccd5/frontend/public/favicon.ico -------------------------------------------------------------------------------- /frontend/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 22 | React App 23 | 24 | 25 | 28 |
29 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /frontend/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": ".", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /frontend/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | animation: App-logo-spin infinite 20s linear; 7 | height: 40vmin; 8 | } 9 | 10 | .App-header { 11 | background-color: #282c34; 12 | min-height: 100vh; 13 | display: flex; 14 | flex-direction: column; 15 | align-items: center; 16 | justify-content: center; 17 | font-size: calc(10px + 2vmin); 18 | color: white; 19 | } 20 | 21 | .App-link { 22 | color: #61dafb; 23 | } 24 | 25 | @keyframes App-logo-spin { 26 | from { 27 | transform: rotate(0deg); 28 | } 29 | to { 30 | transform: rotate(360deg); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /frontend/src/App.js: -------------------------------------------------------------------------------- 1 | // frontend/src/App.js 2 | 3 | import React, { Component } from "react"; 4 | import Modal from "./components/Modal"; 5 | import axios from "axios"; 6 | 7 | class App extends Component { 8 | constructor(props) { 9 | super(props); 10 | this.state = { 11 | viewCompleted: false, 12 | activeItem: { 13 | title: "", 14 | description: "", 15 | completed: false 16 | }, 17 | todoList: [] 18 | }; 19 | } 20 | componentDidMount() { 21 | this.refreshList(); 22 | } 23 | refreshList = () => { 24 | axios 25 | .get("http://localhost:8000/api/todos/") 26 | .then(res => this.setState({ todoList: res.data })) 27 | .catch(err => console.log(err)); 28 | }; 29 | displayCompleted = status => { 30 | if (status) { 31 | return this.setState({ viewCompleted: true }); 32 | } 33 | return this.setState({ viewCompleted: false }); 34 | }; 35 | renderTabList = () => { 36 | return ( 37 |
38 | this.displayCompleted(true)} 40 | className={this.state.viewCompleted ? "active" : ""} 41 | > 42 | complete 43 | 44 | this.displayCompleted(false)} 46 | className={this.state.viewCompleted ? "" : "active"} 47 | > 48 | Incomplete 49 | 50 |
51 | ); 52 | }; 53 | renderItems = () => { 54 | const { viewCompleted } = this.state; 55 | const newItems = this.state.todoList.filter( 56 | item => item.completed === viewCompleted 57 | ); 58 | return newItems.map(item => ( 59 |
  • 63 | 69 | {item.title} 70 | 71 | 72 | 79 | 85 | 86 |
  • 87 | )); 88 | }; 89 | toggle = () => { 90 | this.setState({ modal: !this.state.modal }); 91 | }; 92 | handleSubmit = item => { 93 | this.toggle(); 94 | if (item.id) { 95 | axios 96 | .put(`http://localhost:8000/api/todos/${item.id}/`, item) 97 | .then(res => this.refreshList()); 98 | return; 99 | } 100 | axios 101 | .post("http://localhost:8000/api/todos/", item) 102 | .then(res => this.refreshList()); 103 | }; 104 | handleDelete = item => { 105 | axios 106 | .delete(`http://localhost:8000/api/todos/${item.id}`) 107 | .then(res => this.refreshList()); 108 | }; 109 | createItem = () => { 110 | const item = { title: "", description: "", completed: false }; 111 | this.setState({ activeItem: item, modal: !this.state.modal }); 112 | }; 113 | editItem = item => { 114 | this.setState({ activeItem: item, modal: !this.state.modal }); 115 | }; 116 | render() { 117 | return ( 118 |
    119 |

    Todo app

    120 |
    121 |
    122 |
    123 |
    124 | 127 |
    128 | {this.renderTabList()} 129 |
      130 | {this.renderItems()} 131 |
    132 |
    133 |
    134 |
    135 | {this.state.modal ? ( 136 | 141 | ) : null} 142 |
    143 | ); 144 | } 145 | } 146 | export default App; 147 | -------------------------------------------------------------------------------- /frontend/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 | ReactDOM.unmountComponentAtNode(div); 9 | }); 10 | -------------------------------------------------------------------------------- /frontend/src/components/Modal.js: -------------------------------------------------------------------------------- 1 | // frontend/src/components/Modal.js 2 | 3 | import React, { Component } from "react"; 4 | import { 5 | Button, 6 | Modal, 7 | ModalHeader, 8 | ModalBody, 9 | ModalFooter, 10 | Form, 11 | FormGroup, 12 | Input, 13 | Label 14 | } from "reactstrap"; 15 | 16 | export default class CustomModal extends Component { 17 | constructor(props) { 18 | super(props); 19 | this.state = { 20 | activeItem: this.props.activeItem 21 | }; 22 | } 23 | 24 | handleChange = e => { 25 | let { name, value } = e.target; 26 | if (e.target.type === "checkbox") { 27 | value = e.target.checked; 28 | } 29 | const activeItem = { ...this.state.activeItem, [name]: value }; 30 | this.setState({ activeItem }); 31 | }; 32 | 33 | render() { 34 | const { toggle, onSave } = this.props; 35 | return ( 36 | 37 | Todo Item 38 | 39 |
    40 | 41 | 42 | 49 | 50 | 51 | 52 | 59 | 60 | 61 | 70 | 71 |
    72 |
    73 | 74 | 77 | 78 |
    79 | ); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /frontend/src/index.css: -------------------------------------------------------------------------------- 1 | 2 | /* frontend/src/index.css */ 3 | 4 | body { 5 | margin: 0; 6 | padding: 0; 7 | font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", 8 | "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", 9 | sans-serif; 10 | -webkit-font-smoothing: antialiased; 11 | -moz-osx-font-smoothing: grayscale; 12 | background-color: #282c34; 13 | } 14 | .todo-title { 15 | cursor: pointer; 16 | } 17 | .completed-todo { 18 | text-decoration: line-through; 19 | } 20 | .tab-list > span { 21 | padding: 5px 8px; 22 | border: 1px solid #282c34; 23 | border-radius: 10px; 24 | margin-right: 5px; 25 | cursor: pointer; 26 | } 27 | .tab-list > span.active { 28 | background-color: #282c34; 29 | color: #ffffff; 30 | } -------------------------------------------------------------------------------- /frontend/src/index.js: -------------------------------------------------------------------------------- 1 | 2 | // frontend/src/index.js 3 | 4 | import React from 'react'; 5 | import ReactDOM from 'react-dom'; 6 | import 'bootstrap/dist/css/bootstrap.min.css'; // add this 7 | import './index.css'; 8 | import App from './App'; 9 | import * as serviceWorker from './serviceWorker'; 10 | 11 | ReactDOM.render(, document.getElementById('root')); 12 | // If you want your app to work offline and load faster, you can change 13 | // unregister() to register() below. Note this comes with some pitfalls. 14 | // Learn more about service workers: http://bit.ly/CRA-PWA 15 | serviceWorker.unregister(); -------------------------------------------------------------------------------- /frontend/src/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /frontend/src/serviceWorker.js: -------------------------------------------------------------------------------- 1 | // This optional code is used to register a service worker. 2 | // register() is not called by default. 3 | 4 | // This lets the app load faster on subsequent visits in production, and gives 5 | // it offline capabilities. However, it also means that developers (and users) 6 | // will only see deployed updates on subsequent visits to a page, after all the 7 | // existing tabs open on the page have been closed, since previously cached 8 | // resources are updated in the background. 9 | 10 | // To learn more about the benefits of this model and instructions on how to 11 | // opt-in, read http://bit.ly/CRA-PWA 12 | 13 | const isLocalhost = Boolean( 14 | window.location.hostname === 'localhost' || 15 | // [::1] is the IPv6 localhost address. 16 | window.location.hostname === '[::1]' || 17 | // 127.0.0.1/8 is considered localhost for IPv4. 18 | window.location.hostname.match( 19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ 20 | ) 21 | ); 22 | 23 | export function register(config) { 24 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { 25 | // The URL constructor is available in all browsers that support SW. 26 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href); 27 | if (publicUrl.origin !== window.location.origin) { 28 | // Our service worker won't work if PUBLIC_URL is on a different origin 29 | // from what our page is served on. This might happen if a CDN is used to 30 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374 31 | return; 32 | } 33 | 34 | window.addEventListener('load', () => { 35 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; 36 | 37 | if (isLocalhost) { 38 | // This is running on localhost. Let's check if a service worker still exists or not. 39 | checkValidServiceWorker(swUrl, config); 40 | 41 | // Add some additional logging to localhost, pointing developers to the 42 | // service worker/PWA documentation. 43 | navigator.serviceWorker.ready.then(() => { 44 | console.log( 45 | 'This web app is being served cache-first by a service ' + 46 | 'worker. To learn more, visit http://bit.ly/CRA-PWA' 47 | ); 48 | }); 49 | } else { 50 | // Is not localhost. Just register service worker 51 | registerValidSW(swUrl, config); 52 | } 53 | }); 54 | } 55 | } 56 | 57 | function registerValidSW(swUrl, config) { 58 | navigator.serviceWorker 59 | .register(swUrl) 60 | .then(registration => { 61 | registration.onupdatefound = () => { 62 | const installingWorker = registration.installing; 63 | if (installingWorker == null) { 64 | return; 65 | } 66 | installingWorker.onstatechange = () => { 67 | if (installingWorker.state === 'installed') { 68 | if (navigator.serviceWorker.controller) { 69 | // At this point, the updated precached content has been fetched, 70 | // but the previous service worker will still serve the older 71 | // content until all client tabs are closed. 72 | console.log( 73 | 'New content is available and will be used when all ' + 74 | 'tabs for this page are closed. See http://bit.ly/CRA-PWA.' 75 | ); 76 | 77 | // Execute callback 78 | if (config && config.onUpdate) { 79 | config.onUpdate(registration); 80 | } 81 | } else { 82 | // At this point, everything has been precached. 83 | // It's the perfect time to display a 84 | // "Content is cached for offline use." message. 85 | console.log('Content is cached for offline use.'); 86 | 87 | // Execute callback 88 | if (config && config.onSuccess) { 89 | config.onSuccess(registration); 90 | } 91 | } 92 | } 93 | }; 94 | }; 95 | }) 96 | .catch(error => { 97 | console.error('Error during service worker registration:', error); 98 | }); 99 | } 100 | 101 | function checkValidServiceWorker(swUrl, config) { 102 | // Check if the service worker can be found. If it can't reload the page. 103 | fetch(swUrl) 104 | .then(response => { 105 | // Ensure service worker exists, and that we really are getting a JS file. 106 | const contentType = response.headers.get('content-type'); 107 | if ( 108 | response.status === 404 || 109 | (contentType != null && contentType.indexOf('javascript') === -1) 110 | ) { 111 | // No service worker found. Probably a different app. Reload the page. 112 | navigator.serviceWorker.ready.then(registration => { 113 | registration.unregister().then(() => { 114 | window.location.reload(); 115 | }); 116 | }); 117 | } else { 118 | // Service worker found. Proceed as normal. 119 | registerValidSW(swUrl, config); 120 | } 121 | }) 122 | .catch(() => { 123 | console.log( 124 | 'No internet connection found. App is running in offline mode.' 125 | ); 126 | }); 127 | } 128 | 129 | export function unregister() { 130 | if ('serviceWorker' in navigator) { 131 | navigator.serviceWorker.ready.then(registration => { 132 | registration.unregister(); 133 | }); 134 | } 135 | } 136 | --------------------------------------------------------------------------------