├── .gitignore ├── LICENSE ├── Pipfile ├── Pipfile.lock ├── README.md ├── backend ├── backend │ ├── __init__.py │ ├── asgi.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py ├── manage.py └── todo │ ├── __init__.py │ ├── admin.py │ ├── apps.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 | migrations 2 | __pycache__ 3 | db.sqlite3 4 | node_modules -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Mohammad Dori 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 | -------------------------------------------------------------------------------- /Pipfile: -------------------------------------------------------------------------------- 1 | [[source]] 2 | url = "https://pypi.org/simple" 3 | verify_ssl = true 4 | name = "pypi" 5 | 6 | [packages] 7 | django = "*" 8 | djangorestframework = "*" 9 | django-cors-headers = "*" 10 | 11 | [dev-packages] 12 | 13 | [requires] 14 | python_version = "3.8" 15 | -------------------------------------------------------------------------------- /Pipfile.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_meta": { 3 | "hash": { 4 | "sha256": "981a87d642bb51e35e0c114707a76c8c4b7ba9dcd146a62ea7d0992cb27c8c6b" 5 | }, 6 | "pipfile-spec": 6, 7 | "requires": { 8 | "python_version": "3.8" 9 | }, 10 | "sources": [ 11 | { 12 | "name": "pypi", 13 | "url": "https://pypi.org/simple", 14 | "verify_ssl": true 15 | } 16 | ] 17 | }, 18 | "default": { 19 | "asgiref": { 20 | "hashes": [ 21 | "sha256:2f8abc20f7248433085eda803936d98992f1343ddb022065779f37c5da0181d0", 22 | "sha256:88d59c13d634dcffe0510be048210188edd79aeccb6a6c9028cdad6f31d730a9" 23 | ], 24 | "markers": "python_version >= '3.7'", 25 | "version": "==3.5.0" 26 | }, 27 | "backports.zoneinfo": { 28 | "hashes": [ 29 | "sha256:17746bd546106fa389c51dbea67c8b7c8f0d14b5526a579ca6ccf5ed72c526cf", 30 | "sha256:1b13e654a55cd45672cb54ed12148cd33628f672548f373963b0bff67b217328", 31 | "sha256:1c5742112073a563c81f786e77514969acb58649bcdf6cdf0b4ed31a348d4546", 32 | "sha256:4a0f800587060bf8880f954dbef70de6c11bbe59c673c3d818921f042f9954a6", 33 | "sha256:5c144945a7752ca544b4b78c8c41544cdfaf9786f25fe5ffb10e838e19a27570", 34 | "sha256:7b0a64cda4145548fed9efc10322770f929b944ce5cee6c0dfe0c87bf4c0c8c9", 35 | "sha256:8439c030a11780786a2002261569bdf362264f605dfa4d65090b64b05c9f79a7", 36 | "sha256:8961c0f32cd0336fb8e8ead11a1f8cd99ec07145ec2931122faaac1c8f7fd987", 37 | "sha256:89a48c0d158a3cc3f654da4c2de1ceba85263fafb861b98b59040a5086259722", 38 | "sha256:a76b38c52400b762e48131494ba26be363491ac4f9a04c1b7e92483d169f6582", 39 | "sha256:da6013fd84a690242c310d77ddb8441a559e9cb3d3d59ebac9aca1a57b2e18bc", 40 | "sha256:e55b384612d93be96506932a786bbcde5a2db7a9e6a4bb4bffe8b733f5b9036b", 41 | "sha256:e81b76cace8eda1fca50e345242ba977f9be6ae3945af8d46326d776b4cf78d1", 42 | "sha256:e8236383a20872c0cdf5a62b554b27538db7fa1bbec52429d8d106effbaeca08", 43 | "sha256:f04e857b59d9d1ccc39ce2da1021d196e47234873820cbeaad210724b1ee28ac", 44 | "sha256:fadbfe37f74051d024037f223b8e001611eac868b5c5b06144ef4d8b799862f2" 45 | ], 46 | "markers": "python_version < '3.9'", 47 | "version": "==0.2.1" 48 | }, 49 | "django": { 50 | "hashes": [ 51 | "sha256:1239218849e922033a35d2a2f777cb8bee18bd725416744074f455f34ff50d0c", 52 | "sha256:77ff2e7050e3324c9b67e29b6707754566f58514112a9ac73310f60cd5261930" 53 | ], 54 | "index": "pypi", 55 | "version": "==4.0.3" 56 | }, 57 | "django-cors-headers": { 58 | "hashes": [ 59 | "sha256:a22be2befd4069c4fc174f11cf067351df5c061a3a5f94a01650b4e928b0372b", 60 | "sha256:eb98389bf7a2afc5d374806af4a9149697e3a6955b5a2dc2bf049f7d33647456" 61 | ], 62 | "index": "pypi", 63 | "version": "==3.11.0" 64 | }, 65 | "djangorestframework": { 66 | "hashes": [ 67 | "sha256:0c33407ce23acc68eca2a6e46424b008c9c02eceb8cf18581921d0092bc1f2ee", 68 | "sha256:24c4bf58ed7e85d1fe4ba250ab2da926d263cd57d64b03e8dcef0ac683f8b1aa" 69 | ], 70 | "index": "pypi", 71 | "version": "==3.13.1" 72 | }, 73 | "pytz": { 74 | "hashes": [ 75 | "sha256:3672058bc3453457b622aab7a1c3bfd5ab0bdae451512f6cf25f64ed37f5b87c", 76 | "sha256:acad2d8b20a1af07d4e4c9d2e9285c5ed9104354062f275f3fcd88dcef4f1326" 77 | ], 78 | "version": "==2021.3" 79 | }, 80 | "sqlparse": { 81 | "hashes": [ 82 | "sha256:0c00730c74263a94e5a9919ade150dfc3b19c574389985446148402998287dae", 83 | "sha256:48719e356bb8b42991bdbb1e8b83223757b93789c00910a616a071910ca4a64d" 84 | ], 85 | "markers": "python_version >= '3.5'", 86 | "version": "==0.4.2" 87 | } 88 | }, 89 | "develop": {} 90 | } 91 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Django Todo React 2 | 3 | Create todo app with Django and React. 4 | 5 | # 6 | 7 | ## Tools 8 | 9 | - Django 4 10 | - React Js 11 | - Python 3 12 | 13 | # 14 | 15 | # How to Run Project 16 | 17 | ## Download Codes 18 | 19 | ``` 20 | git clone https://github.com/dori-dev/django-todo-react.git 21 | ``` 22 | 23 | ``` 24 | cd django-todo-react 25 | ``` 26 | 27 | ## Install Backend Requirements 28 | 29 | ``` 30 | pip install pipenv 31 | ``` 32 | 33 | ``` 34 | pipenv shell 35 | ``` 36 | 37 | ``` 38 | pipenv install 39 | ``` 40 | 41 | ## Install Frontend Dependencies 42 | 43 | ``` 44 | cd frontend 45 | ``` 46 | 47 | ``` 48 | npm install 49 | npm audit 50 | ``` 51 | 52 | ## Migrate Backend Models 53 | 54 | ``` 55 | cd .. 56 | cd backend 57 | ``` 58 | 59 | ``` 60 | python manage.py makemigrations todo 61 | ``` 62 | 63 | ``` 64 | python manage.py migrate 65 | ``` 66 | 67 | ## Add Super User 68 | 69 | ``` 70 | python manage.py createsuperuser 71 | ``` 72 | 73 | ## Run Django Server 74 | 75 | ``` 76 | python manage.py runserver 77 | ``` 78 | 79 | ## Run FrontEnd 80 | 81 | open new terminal in `frontend` directory and run this command. 82 | 83 | ``` 84 | npm start 85 | ``` 86 | 87 | ## Open On Browser 88 | 89 | App Page 90 | [localhost:3000](http://localhost:3000/) 91 | 92 | Django Admin Page 93 | [127.0.0.1:8000/admin](http://127.0.0.1:8000/admin) 94 | 95 | # 96 | 97 | ## Links 98 | 99 | Download Source Code: [Click Here](https://github.com/dori-dev/django-todo-react/archive/refs/heads/master.zip) 100 | 101 | My Github Account: [Click Here](https://github.com/dori-dev/) 102 | -------------------------------------------------------------------------------- /backend/backend/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dori-dev/django-todo-react/2116629f4f4ba060b7057a6cb800e1eae058e0f9/backend/backend/__init__.py -------------------------------------------------------------------------------- /backend/backend/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for backend project. 3 | 4 | It exposes the ASGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.asgi import get_asgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /backend/backend/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for backend project. 3 | 4 | Generated by 'django-admin startproject' using Django 3.2.9. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.2/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/3.2/ref/settings/ 11 | """ 12 | 13 | from pathlib import Path 14 | 15 | # Build paths inside the project like this: BASE_DIR / 'subdir'. 16 | BASE_DIR = Path(__file__).resolve().parent.parent 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = 'django-insecure-+14$ncew!$k1v@a$+va7ngm#!#2!+*+!=6)n1bsv(sd4#i^$+m' 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 | 33 | INSTALLED_APPS = [ 34 | 'django.contrib.admin', 35 | 'django.contrib.auth', 36 | 'django.contrib.contenttypes', 37 | 'django.contrib.sessions', 38 | 'django.contrib.messages', 39 | 'django.contrib.staticfiles', 40 | 'corsheaders', 41 | 'rest_framework', 42 | 'todo', 43 | ] 44 | 45 | MIDDLEWARE = [ 46 | 'django.middleware.security.SecurityMiddleware', 47 | 'django.contrib.sessions.middleware.SessionMiddleware', 48 | 'django.middleware.common.CommonMiddleware', 49 | 'django.middleware.csrf.CsrfViewMiddleware', 50 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 51 | 'django.contrib.messages.middleware.MessageMiddleware', 52 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 53 | 'corsheaders.middleware.CorsMiddleware', 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/3.2/ref/settings/#databases 79 | 80 | DATABASES = { 81 | 'default': { 82 | 'ENGINE': 'django.db.backends.sqlite3', 83 | 'NAME': BASE_DIR / 'db.sqlite3', 84 | } 85 | } 86 | 87 | 88 | # Password validation 89 | # https://docs.djangoproject.com/en/3.2/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/3.2/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/3.2/howto/static-files/ 123 | 124 | STATIC_URL = '/static/' 125 | 126 | # Default primary key field type 127 | # https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field 128 | 129 | DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' 130 | 131 | CORS_ORIGIN_WHITELIST = [ 132 | 'http://localhost:3000' 133 | ] 134 | -------------------------------------------------------------------------------- /backend/backend/urls.py: -------------------------------------------------------------------------------- 1 | """backend URL Configuration 2 | """ 3 | from django.contrib import admin 4 | from django.urls import path, include 5 | from rest_framework import routers 6 | from todo import views 7 | 8 | router = routers.DefaultRouter() 9 | router.register(r'todos', views.TodoView, 'todo') 10 | 11 | urlpatterns = [ 12 | path('admin/', admin.site.urls), 13 | path('api/', include(router.urls)), 14 | ] 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/3.2/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/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | """Run administrative tasks.""" 9 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings') 10 | try: 11 | from django.core.management import execute_from_command_line 12 | except ImportError as exc: 13 | raise ImportError( 14 | "Couldn't import Django. Are you sure it's installed and " 15 | "available on your PYTHONPATH environment variable? Did you " 16 | "forget to activate a virtual environment?" 17 | ) from exc 18 | execute_from_command_line(sys.argv) 19 | 20 | 21 | if __name__ == '__main__': 22 | main() 23 | -------------------------------------------------------------------------------- /backend/todo/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dori-dev/django-todo-react/2116629f4f4ba060b7057a6cb800e1eae058e0f9/backend/todo/__init__.py -------------------------------------------------------------------------------- /backend/todo/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import Todo 3 | 4 | 5 | class TodoAdmin(admin.ModelAdmin): 6 | list_display = ('title', 'description', 'completed') 7 | 8 | 9 | admin.site.register(Todo, TodoAdmin) 10 | -------------------------------------------------------------------------------- /backend/todo/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class TodoConfig(AppConfig): 5 | default_auto_field = 'django.db.models.BigAutoField' 6 | name = 'todo' 7 | -------------------------------------------------------------------------------- /backend/todo/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | 4 | class Todo(models.Model): 5 | title = models.CharField(max_length=120) 6 | description = models.TextField() 7 | completed = models.BooleanField(default=False) 8 | 9 | def __str__(self) -> str: 10 | return self.title 11 | -------------------------------------------------------------------------------- /backend/todo/serializers.py: -------------------------------------------------------------------------------- 1 | """serializers 2 | """ 3 | 4 | from rest_framework import serializers 5 | from .models import Todo 6 | 7 | 8 | class TodoSerializer(serializers.ModelSerializer): 9 | class Meta: 10 | model = Todo 11 | fields = ( 12 | 'id', 13 | 'title', 14 | 'description', 15 | 'completed', 16 | ) 17 | -------------------------------------------------------------------------------- /backend/todo/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /backend/todo/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | from rest_framework import viewsets 3 | from .serializers import TodoSerializer 4 | from .models import Todo 5 | 6 | 7 | class TodoView(viewsets.ModelViewSet): 8 | serializer_class = TodoSerializer 9 | queryset = Todo.objects.all() 10 | -------------------------------------------------------------------------------- /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/dori-dev/django-todo-react/2116629f4f4ba060b7057a6cb800e1eae058e0f9/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 | --------------------------------------------------------------------------------