├── __pycache__ ├── database.cpython-39.pyc ├── main.cpython-39.pyc └── secret.cpython-39.pyc ├── database.py ├── frontend ├── .gitignore ├── README.md ├── package-lock.json ├── package.json ├── public │ ├── favicon.ico │ ├── index.html │ ├── logo192.png │ ├── logo512.png │ ├── manifest.json │ └── robots.txt └── src │ ├── App.css │ ├── App.js │ ├── assets │ ├── add.svg │ ├── arrow-left.svg │ └── save.svg │ ├── components │ ├── Header.js │ ├── Layout.js │ └── ListItem.js │ ├── index.js │ └── pages │ ├── Note.js │ └── Notes.js ├── main.py ├── requirements.txt └── secret.py /__pycache__/database.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divanov11/FastAPI-with-React-Notes-App/bc421c8775253a0f0d073bb453cee185a2e0886c/__pycache__/database.cpython-39.pyc -------------------------------------------------------------------------------- /__pycache__/main.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divanov11/FastAPI-with-React-Notes-App/bc421c8775253a0f0d073bb453cee185a2e0886c/__pycache__/main.cpython-39.pyc -------------------------------------------------------------------------------- /__pycache__/secret.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divanov11/FastAPI-with-React-Notes-App/bc421c8775253a0f0d073bb453cee185a2e0886c/__pycache__/secret.cpython-39.pyc -------------------------------------------------------------------------------- /database.py: -------------------------------------------------------------------------------- 1 | import harperdb 2 | 3 | from secret import HARPERDB_PASSWORD, HARPERDB_URL, HARPERDB_USERNAME 4 | 5 | db = harperdb.HarperDB( 6 | url=HARPERDB_URL, 7 | username=HARPERDB_USERNAME, 8 | password=HARPERDB_PASSWORD) -------------------------------------------------------------------------------- /frontend/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /frontend/README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `npm start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in your browser. 13 | 14 | The page will reload when you make changes.\ 15 | You may also see any lint errors in the console. 16 | 17 | ### `npm test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `npm run build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `npm run eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can't go back!** 35 | 36 | 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. 37 | 38 | 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. 39 | 40 | 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. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | 48 | ### Code Splitting 49 | 50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) 51 | 52 | ### Analyzing the Bundle Size 53 | 54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) 55 | 56 | ### Making a Progressive Web App 57 | 58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) 59 | 60 | ### Advanced Configuration 61 | 62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) 63 | 64 | ### Deployment 65 | 66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) 67 | 68 | ### `npm run build` fails to minify 69 | 70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) 71 | -------------------------------------------------------------------------------- /frontend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "frontend1", 3 | "version": "0.1.0", 4 | "private": true, 5 | "proxy": "http://localhost:8000", 6 | "dependencies": { 7 | "@testing-library/jest-dom": "^5.16.4", 8 | "@testing-library/react": "^13.3.0", 9 | "@testing-library/user-event": "^13.5.0", 10 | "react": "^18.1.0", 11 | "react-dom": "^18.1.0", 12 | "react-router-dom": "^6.3.0", 13 | "react-scripts": "5.0.1", 14 | "web-vitals": "^2.1.4" 15 | }, 16 | "scripts": { 17 | "start": "react-scripts start", 18 | "build": "react-scripts build", 19 | "test": "react-scripts test", 20 | "eject": "react-scripts eject" 21 | }, 22 | "eslintConfig": { 23 | "extends": [ 24 | "react-app", 25 | "react-app/jest" 26 | ] 27 | }, 28 | "browserslist": { 29 | "production": [ 30 | ">0.2%", 31 | "not dead", 32 | "not op_mini all" 33 | ], 34 | "development": [ 35 | "last 1 chrome version", 36 | "last 1 firefox version", 37 | "last 1 safari version" 38 | ] 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /frontend/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divanov11/FastAPI-with-React-Notes-App/bc421c8775253a0f0d073bb453cee185a2e0886c/frontend/public/favicon.ico -------------------------------------------------------------------------------- /frontend/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /frontend/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divanov11/FastAPI-with-React-Notes-App/bc421c8775253a0f0d073bb453cee185a2e0886c/frontend/public/logo192.png -------------------------------------------------------------------------------- /frontend/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divanov11/FastAPI-with-React-Notes-App/bc421c8775253a0f0d073bb453cee185a2e0886c/frontend/public/logo512.png -------------------------------------------------------------------------------- /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 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /frontend/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /frontend/src/App.css: -------------------------------------------------------------------------------- 1 | @import url('https://fonts.googleapis.com/css2?family=Lexend:wght@400;600;700&display=swap'); 2 | 3 | 4 | 5 | :root { 6 | --color-main: #f68657; 7 | --color-text: #383a3f; 8 | --color-dark: #1f2124; 9 | --color-gray: #677; 10 | --color-bg: #f3f6f9; 11 | --color-light: #acb4bd; 12 | --color-lighter: #f9f9f9; 13 | --color-white: #fff; 14 | --color-border:#e0e3e6; 15 | } 16 | 17 | .dark { 18 | --color-main: #f68657; 19 | --color-text: #d6d1d1; 20 | --color-dark: #f5f6f7; 21 | --color-gray: #999; 22 | --color-bg: #1f2124; 23 | --color-lighter: #292a2c; 24 | --color-white: #2e3235; 25 | --color-border:#252629; 26 | } 27 | 28 | /* BASE STYLES */ 29 | 30 | 31 | *{ 32 | margin: 0; 33 | padding: 0; 34 | box-sizing: border-box; 35 | font-family: 'Lexend', sans-serif; 36 | color: inherit; 37 | font-size: inherit; 38 | scroll-behavior: smooth; 39 | } 40 | 41 | 42 | body{ 43 | line-height: 1.8em; 44 | font-weight: 400; 45 | font-size: 16px; 46 | } 47 | 48 | a { 49 | text-decoration: none; 50 | } 51 | 52 | /* APP STYLES */ 53 | 54 | 55 | .container { 56 | width: 100%; 57 | height: 100vh; 58 | color: var(--color-text); 59 | background-color: var(--color-bg); 60 | display: flex; 61 | align-items: center; 62 | } 63 | 64 | 65 | .app { 66 | width: 100%; 67 | max-width: 480px; 68 | height: 88vh; 69 | margin: 0 auto; 70 | background-color: var(--color-white); 71 | box-shadow: 1px 1px 6px rgba(0, 0, 0, 0.05); 72 | position: relative; 73 | } 74 | 75 | 76 | .app-header { 77 | display: flex; 78 | align-items: center; 79 | padding: 16px; 80 | justify-content: space-between; 81 | background-color: var(--color-lighter); 82 | box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.1); 83 | } 84 | 85 | .app-header h1 { 86 | font-size: 30px; 87 | color: var(--color-dark); 88 | font-weight: 800; 89 | text-align: center; 90 | } 91 | 92 | .app-header button { 93 | border: 0; 94 | background: transparent; 95 | cursor: pointer; 96 | } 97 | 98 | .app-header button > svg { 99 | fill: var(--color-dark); 100 | height: 25px; 101 | width: 25px; 102 | object-fit: cover; 103 | } 104 | 105 | .app-body { 106 | padding: 16px; 107 | } 108 | 109 | 110 | /* NOTES STYLES */ 111 | 112 | .notes-header { 113 | display: flex; 114 | align-items: center; 115 | justify-content: space-between; 116 | padding: 10px 16px; 117 | } 118 | 119 | .notes-title, 120 | .notes-count { 121 | color: var(--color-main); 122 | font-size: 24px; 123 | font-weight: 600; 124 | } 125 | 126 | .notes-count { 127 | font-size: 18px; 128 | color: var(--color-gray); 129 | } 130 | 131 | 132 | .notes-list { 133 | padding: 0; 134 | margin: 16px 0; 135 | height: 70vh; 136 | overflow-y: auto; 137 | scrollbar-width: none; /* Firefox */ 138 | } 139 | 140 | .notes-list::-webkit-scrollbar { 141 | display: none; 142 | } 143 | 144 | .notes-list-item { 145 | border-bottom: 1px solid var(--color-border); 146 | margin-bottom: 12px; 147 | padding: 8px 16px; 148 | transition: all 0.2s ease-in-out; 149 | } 150 | 151 | .notes-list-item:hover { 152 | background-color: var(--color-bg); 153 | cursor: pointer; 154 | } 155 | 156 | .notes-list-item h3, 157 | .notes-list-item p span { 158 | font-weight: 600; 159 | } 160 | 161 | 162 | .notes-list-item p span { 163 | color: var(--color-gray); 164 | display: inline-block; 165 | margin-right: 8px; 166 | } 167 | 168 | .notes-list-item p { 169 | font-size: 14px; 170 | color: var(--color-light); 171 | } 172 | 173 | .floating-button { 174 | font-size: 48px; 175 | position: absolute; 176 | bottom: 24px; 177 | right: 16px; 178 | background: var(--color-main); 179 | border: none; 180 | width: 60px; 181 | height: 60px; 182 | border-radius: 50%; 183 | display: flex; 184 | align-items: center; 185 | justify-content: center; 186 | cursor: pointer; 187 | box-shadow: 1px 1px 10px rgba(0, 0, 0, 0.2); 188 | } 189 | 190 | 191 | .floating-button > svg { 192 | fill: var(--color-bg); 193 | } 194 | 195 | 196 | 197 | /*============================== 198 | => Note Styles 199 | ================================*/ 200 | 201 | .note-header { 202 | display: flex; 203 | align-items: center; 204 | justify-content: space-between; 205 | color: var(--color-main); 206 | padding: 10px; 207 | } 208 | 209 | .note-header h3 { 210 | display: flex; 211 | align-items: center; 212 | font-size: 24px; 213 | cursor: pointer; 214 | } 215 | 216 | .note-header h3 svg { 217 | fill: var(--color-main); 218 | width: 20px; 219 | margin-right: 8px; 220 | } 221 | 222 | .note-header button { 223 | border: none; 224 | outline: none; 225 | font-weight: 600; 226 | background-color: transparent; 227 | font-size: 18px; 228 | cursor: pointer; 229 | } 230 | 231 | .note textarea { 232 | background-color: var(--color-white); 233 | border: none; 234 | padding: 16px 12px; 235 | width: 100%; 236 | height: 70vh; 237 | resize: none; 238 | scrollbar-width: none; /* Firefox */ 239 | } 240 | 241 | .note textarea:active, 242 | .note textarea:focus { 243 | outline: none; 244 | border: none; 245 | } 246 | 247 | .note textarea::-webkit-scrollbar { 248 | display: none; 249 | } -------------------------------------------------------------------------------- /frontend/src/App.js: -------------------------------------------------------------------------------- 1 | import './App.css'; 2 | import { 3 | BrowserRouter as Router, 4 | Routes, 5 | Route 6 | 7 | } from 'react-router-dom' 8 | import Notes from './pages/Notes' 9 | import Note from './pages/Note' 10 | import Layout from './components/Layout' 11 | 12 | 13 | function App() { 14 | return ( 15 | 16 | 17 | 18 | } exact/> 19 | }/> 20 | 21 | 22 | 23 | ); 24 | } 25 | 26 | export default App; 27 | -------------------------------------------------------------------------------- /frontend/src/assets/add.svg: -------------------------------------------------------------------------------- 1 | 2 | add 3 | 4 | 5 | -------------------------------------------------------------------------------- /frontend/src/assets/arrow-left.svg: -------------------------------------------------------------------------------- 1 | 2 | chevron-left 3 | 4 | 5 | -------------------------------------------------------------------------------- /frontend/src/assets/save.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /frontend/src/components/Header.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | const Header = () => { 4 | return ( 5 |
6 |

Note List

7 |
8 | ) 9 | } 10 | 11 | export default Header -------------------------------------------------------------------------------- /frontend/src/components/Layout.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import Header from './Header' 3 | 4 | const Layout = (props) => { 5 | return ( 6 | 7 |
8 |
9 |
10 | {props.children} 11 |
12 |
13 | 14 | ) 15 | } 16 | 17 | export default Layout -------------------------------------------------------------------------------- /frontend/src/components/ListItem.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { Link } from 'react-router-dom' 3 | 4 | let getTimestamp = (note) => { 5 | return new Date(note.__updatedtime__).toLocaleDateString() 6 | } 7 | 8 | let trimmedContent = (note) => { 9 | //Slice content and add three dots in over 45 characters to show there is more 10 | let content = note.body 11 | 12 | if (content.length > 45) { 13 | return content.slice(0, 45) + '...' 14 | } else { 15 | return content 16 | } 17 | } 18 | 19 | const ListItem = ({note}) => { 20 | return ( 21 | 22 |
23 |

{trimmedContent(note)}

24 |

{getTimestamp(note)}

25 |
26 | 27 | ) 28 | } 29 | 30 | export default ListItem -------------------------------------------------------------------------------- /frontend/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom/client'; 3 | import App from './App'; 4 | 5 | const root = ReactDOM.createRoot(document.getElementById('root')); 6 | root.render( 7 | 8 | 9 | 10 | ); 11 | 12 | -------------------------------------------------------------------------------- /frontend/src/pages/Note.js: -------------------------------------------------------------------------------- 1 | import React, {useState, useEffect} from 'react' 2 | import { useParams, useNavigate } from 'react-router-dom' 3 | import { Link } from 'react-router-dom' 4 | import { ReactComponent as ArrowLeft } from '../assets/arrow-left.svg' 5 | import { ReactComponent as SaveIcon } from '../assets/save.svg' 6 | 7 | //let dummyData = [{"id":"1", "body":"Get milk" }, {"id":"2", "body":"Wash car" }, {"id":"3", "body":"Start coding"}] 8 | 9 | const Note = () => { 10 | let params = useParams() 11 | let noteId = params.id 12 | 13 | let navigate = useNavigate() 14 | 15 | //let noteMatch = dummyData.find((note) => note.id == noteId) 16 | 17 | let [note, setNote] = useState(null) 18 | 19 | useEffect(() => { 20 | if(noteId !== 'add') getNote() 21 | }, [noteId]) 22 | 23 | 24 | let getNote = async () => { 25 | let response = await fetch(`/notes/${params.id}`) 26 | let data = await response.json() 27 | setNote(data) 28 | } 29 | 30 | let submitData = async (e) => { 31 | e.preventDefault() 32 | 33 | console.log('Submit data triggerd...') 34 | 35 | let url = '/notes' 36 | let method = 'POST' 37 | 38 | if (params.id !== 'add'){ 39 | url = `/notes/${params.id}` 40 | method = 'PUT' 41 | } 42 | 43 | let noteBody = note?.body 44 | if (noteBody !== undefined){ 45 | noteBody = String(noteBody).trim() 46 | } 47 | 48 | if(noteBody === '' || noteBody === undefined){ 49 | alert('Note cannot be empty.') 50 | return 51 | } 52 | 53 | await fetch(url, { 54 | method:method, 55 | headers:{ 56 | 'Content-Type':'application/json', 57 | }, 58 | body:JSON.stringify({"body":noteBody}) 59 | }) 60 | 61 | navigate('/') 62 | } 63 | 64 | let deleteNote = async (e) => { 65 | e.preventDefault() 66 | await fetch(`/notes/${params.id}`, {method:'DELETE'}) 67 | navigate('/') 68 | 69 | } 70 | 71 | return ( 72 |
73 |
74 |

75 | 76 | 77 | 78 |

79 | 80 | {noteId != 'add' && } 81 |
82 | 83 | 84 | 85 |
86 | 87 |
88 |
89 | ) 90 | } 91 | 92 | export default Note 93 | -------------------------------------------------------------------------------- /frontend/src/pages/Notes.js: -------------------------------------------------------------------------------- 1 | import React, {useState, useEffect} from 'react' 2 | import { Link } from 'react-router-dom' 3 | import ListItem from '../components/ListItem' 4 | import { ReactComponent as AddIcon } from '../assets/add.svg' 5 | 6 | //let dummyData = [{"id":"1", "body":"Get milk" }, {"id":"2", "body":"Wash car" }, {"id":"3", "body":"Start coding"}] 7 | 8 | 9 | const Notes = () => { 10 | 11 | let [notes, setNotes] = useState([]) 12 | 13 | useEffect(() => { 14 | getNotes() 15 | }, []) 16 | 17 | let getNotes = async () =>{ 18 | let response = await fetch('/notes') 19 | let data = await response.json() 20 | setNotes(data) 21 | } 22 | 23 | return ( 24 |
25 |
26 |

☶ Notes

27 |

{notes.length}

28 |
29 | 30 |
31 | {notes.map((note) => ( 32 | 33 | ))} 34 |
35 | 36 | 37 | 38 | 39 |
40 | ) 41 | } 42 | 43 | export default Notes -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | from fastapi import FastAPI, Body 2 | from fastapi.middleware.cors import CORSMiddleware 3 | from database import db 4 | 5 | app = FastAPI() 6 | 7 | app.add_middleware( 8 | CORSMiddleware, 9 | allow_origins=["*"], 10 | allow_credentials=True, 11 | allow_methods=["*"], 12 | allow_headers=["*"], 13 | ) 14 | 15 | @app.get("/") 16 | def getRoutes(): 17 | return ['/notes', '/notes/'] 18 | 19 | 20 | @app.get("/notes") 21 | def getNotes(): 22 | notes = db.sql('SELECT * FROM notesapp.notes ORDER BY __updatedtime__ DESC') 23 | #notes = db.search_by_value('notesapp', 'notes', "id", "*", get_attributes=['*']) 24 | return notes 25 | 26 | @app.get("/notes/{id}") 27 | def getNote(id:str): 28 | notes = db.search_by_hash('notesapp', 'notes', [id] , get_attributes=['*'] ) 29 | return notes[0] 30 | 31 | @app.post("/notes") 32 | def addNotes(data = Body()): 33 | db.insert('notesapp', 'notes', [{"body":data['body']}]) 34 | notes = db.sql('SELECT * FROM notesapp.notes') 35 | return notes 36 | 37 | 38 | @app.put("/notes/{id}") 39 | def updateNote(id:str, data = Body()): 40 | note = db.update('notesapp', 'notes', [{"id":id, "body":data["body"]}]) 41 | notes = db.sql('SELECT * FROM notesapp.notes') 42 | return notes 43 | 44 | @app.delete("/notes/{id}") 45 | def deleteNote(id:str): 46 | db.delete('notesapp', 'notes', [id]) 47 | notes = db.sql('SELECT * FROM notesapp.notes') 48 | return notes 49 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divanov11/FastAPI-with-React-Notes-App/bc421c8775253a0f0d073bb453cee185a2e0886c/requirements.txt -------------------------------------------------------------------------------- /secret.py: -------------------------------------------------------------------------------- 1 | HARPERDB_URL = '' 2 | HARPERDB_USERNAME = '' 3 | HARPERDB_PASSWORD = '' --------------------------------------------------------------------------------