├── .gitignore ├── README.md ├── package-lock.json ├── package.json ├── public ├── favicon.ico ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt └── src ├── App.js ├── components ├── AddNote.js ├── Header.js ├── Note.js ├── NotesList.js └── Search.js ├── index.css └── index.js /.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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Run the code 2 | 3 | ``` 4 | npm install 5 | npm start 6 | ``` 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-notes-app", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.11.4", 7 | "@testing-library/react": "^11.1.0", 8 | "@testing-library/user-event": "^12.1.10", 9 | "react": "^17.0.2", 10 | "react-dom": "^17.0.2", 11 | "react-scripts": "4.0.3", 12 | "web-vitals": "^1.0.1" 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": [ 22 | "react-app", 23 | "react-app/jest" 24 | ] 25 | }, 26 | "browserslist": { 27 | "production": [ 28 | ">0.2%", 29 | "not dead", 30 | "not op_mini all" 31 | ], 32 | "development": [ 33 | "last 1 chrome version", 34 | "last 1 firefox version", 35 | "last 1 safari version" 36 | ] 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chrisblakely01/react-notes-app/997e60024cf3bcbae4979375cee0103f0f1a5f80/public/favicon.ico -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chrisblakely01/react-notes-app/997e60024cf3bcbae4979375cee0103f0f1a5f80/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chrisblakely01/react-notes-app/997e60024cf3bcbae4979375cee0103f0f1a5f80/public/logo512.png -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import { useState, useEffect } from 'react'; 2 | import { nanoid } from 'nanoid'; 3 | import NotesList from './components/NotesList'; 4 | import Search from './components/Search'; 5 | import Header from './components/Header'; 6 | 7 | const App = () => { 8 | const [notes, setNotes] = useState([ 9 | { 10 | id: nanoid(), 11 | text: 'This is my first note!', 12 | date: '15/04/2021', 13 | }, 14 | { 15 | id: nanoid(), 16 | text: 'This is my second note!', 17 | date: '21/04/2021', 18 | }, 19 | { 20 | id: nanoid(), 21 | text: 'This is my third note!', 22 | date: '28/04/2021', 23 | }, 24 | { 25 | id: nanoid(), 26 | text: 'This is my new note!', 27 | date: '30/04/2021', 28 | }, 29 | ]); 30 | 31 | const [searchText, setSearchText] = useState(''); 32 | 33 | const [darkMode, setDarkMode] = useState(false); 34 | 35 | useEffect(() => { 36 | const savedNotes = JSON.parse( 37 | localStorage.getItem('react-notes-app-data') 38 | ); 39 | 40 | if (savedNotes) { 41 | setNotes(savedNotes); 42 | } 43 | }, []); 44 | 45 | useEffect(() => { 46 | localStorage.setItem( 47 | 'react-notes-app-data', 48 | JSON.stringify(notes) 49 | ); 50 | }, [notes]); 51 | 52 | const addNote = (text) => { 53 | const date = new Date(); 54 | const newNote = { 55 | id: nanoid(), 56 | text: text, 57 | date: date.toLocaleDateString(), 58 | }; 59 | const newNotes = [...notes, newNote]; 60 | setNotes(newNotes); 61 | }; 62 | 63 | const deleteNote = (id) => { 64 | const newNotes = notes.filter((note) => note.id !== id); 65 | setNotes(newNotes); 66 | }; 67 | 68 | return ( 69 |
70 |
71 |
72 | 73 | 75 | note.text.toLowerCase().includes(searchText) 76 | )} 77 | handleAddNote={addNote} 78 | handleDeleteNote={deleteNote} 79 | /> 80 |
81 |
82 | ); 83 | }; 84 | 85 | export default App; 86 | -------------------------------------------------------------------------------- /src/components/AddNote.js: -------------------------------------------------------------------------------- 1 | import { useState } from 'react'; 2 | 3 | const AddNote = ({ handleAddNote }) => { 4 | const [noteText, setNoteText] = useState(''); 5 | const characterLimit = 200; 6 | 7 | const handleChange = (event) => { 8 | if (characterLimit - event.target.value.length >= 0) { 9 | setNoteText(event.target.value); 10 | } 11 | }; 12 | 13 | const handleSaveClick = () => { 14 | if (noteText.trim().length > 0) { 15 | handleAddNote(noteText); 16 | setNoteText(''); 17 | } 18 | }; 19 | 20 | return ( 21 |
22 | 29 |
30 | 31 | {characterLimit - noteText.length} Remaining 32 | 33 | 36 |
37 |
38 | ); 39 | }; 40 | 41 | export default AddNote; 42 | -------------------------------------------------------------------------------- /src/components/Header.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | const Header = ({ handleToggleDarkMode }) => { 4 | return ( 5 |
6 |

Notes

7 | 17 |
18 | ); 19 | }; 20 | 21 | export default Header; 22 | -------------------------------------------------------------------------------- /src/components/Note.js: -------------------------------------------------------------------------------- 1 | import { MdDeleteForever } from 'react-icons/md'; 2 | 3 | const Note = ({ id, text, date, handleDeleteNote }) => { 4 | return ( 5 |
6 | {text} 7 |
8 | {date} 9 | handleDeleteNote(id)} 11 | className='delete-icon' 12 | size='1.3em' 13 | /> 14 |
15 |
16 | ); 17 | }; 18 | 19 | export default Note; 20 | -------------------------------------------------------------------------------- /src/components/NotesList.js: -------------------------------------------------------------------------------- 1 | import Note from './Note'; 2 | import AddNote from './AddNote'; 3 | 4 | const NotesList = ({ 5 | notes, 6 | handleAddNote, 7 | handleDeleteNote, 8 | }) => { 9 | return ( 10 |
11 | {notes.map((note) => ( 12 | 18 | ))} 19 | 20 |
21 | ); 22 | }; 23 | 24 | export default NotesList; 25 | -------------------------------------------------------------------------------- /src/components/Search.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { MdSearch } from 'react-icons/md'; 3 | 4 | const Search = ({ handleSearchNote }) => { 5 | return ( 6 |
7 | 8 | 10 | handleSearchNote(event.target.value) 11 | } 12 | type='text' 13 | placeholder='type to search...' 14 | /> 15 |
16 | ); 17 | }; 18 | 19 | export default Search; 20 | -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 4 | 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 5 | 'Droid Sans', 'Helvetica Neue', sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 12 | 'Courier New', monospace; 13 | } 14 | 15 | .header { 16 | display: flex; 17 | align-items: center; 18 | justify-content: space-between; 19 | } 20 | 21 | .dark-mode { 22 | background-color: black; 23 | } 24 | 25 | .dark-mode h1 { 26 | color: white; 27 | } 28 | 29 | .container { 30 | max-width: 960px; 31 | margin-right: auto; 32 | margin-left: auto; 33 | padding-right: 15px; 34 | padding-left: 15px; 35 | min-height: 100vh; 36 | } 37 | 38 | .notes-list { 39 | display: grid; 40 | grid-gap: 1rem; 41 | grid-template-columns: repeat( 42 | auto-fill, 43 | minmax(250px, 1fr) 44 | ); 45 | } 46 | 47 | .note.new { 48 | background-color: #67d7cc; 49 | } 50 | 51 | textarea { 52 | border: none; 53 | resize: none; 54 | background-color: #67d7cc; 55 | } 56 | 57 | textarea:focus { 58 | outline: none; 59 | } 60 | 61 | .save { 62 | background-color: #e1e1e1; 63 | border: none; 64 | border-radius: 15px; 65 | padding: 5px 10px 5px 10px; 66 | } 67 | 68 | .save:hover { 69 | background-color: #ededed; 70 | cursor: pointer; 71 | } 72 | 73 | .note { 74 | background-color: #fef68a; 75 | border-radius: 10px; 76 | padding: 1rem; 77 | min-height: 170px; 78 | display: flex; 79 | flex-direction: column; 80 | justify-content: space-between; 81 | white-space: pre-wrap; 82 | } 83 | 84 | .note-footer { 85 | display: flex; 86 | align-items: center; 87 | justify-content: space-between; 88 | } 89 | 90 | .delete-icon { 91 | cursor: pointer; 92 | } 93 | 94 | .search { 95 | display: flex; 96 | align-items: center; 97 | background-color: rgb(233, 233, 233); 98 | border-radius: 10px; 99 | padding: 5px; 100 | margin-bottom: 1.5em; 101 | } 102 | 103 | .search input { 104 | border: none; 105 | background-color: rgb(233, 233, 233); 106 | width: 100%; 107 | } 108 | 109 | .search input:focus { 110 | outline: none; 111 | } 112 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | 6 | ReactDOM.render( 7 | 8 | 9 | , 10 | document.getElementById('root') 11 | ); 12 | --------------------------------------------------------------------------------