diff --git a/README.md b/README.md index 34ed423ce3..ae6d02c69a 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ Upon your first commit, please submit a Pull Request and add _both_ the **Trello - [ ] Fill in the `backlog` list with all the extra features listed below - [ ] Share your board with the project manager that has been assigned to you. If you have not been assigned yet, reach out to your lead PM for guidance - [ ] Add your Trello URL to your project's README.md file. Commit the change, push it to your repository & submit a pull request +- https://trello.com/invite/b/yzoRZ87L/f516cc6c13388b51a91f64b682d7f8a1/lambda-notes-aman-singh ## MVP Features: diff --git a/lambda-notes/.gitignore b/lambda-notes/.gitignore new file mode 100644 index 0000000000..4d29575de8 --- /dev/null +++ b/lambda-notes/.gitignore @@ -0,0 +1,23 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# production +/build + +# misc +.DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* diff --git a/lambda-notes/README.md b/lambda-notes/README.md new file mode 100644 index 0000000000..897dc83660 --- /dev/null +++ b/lambda-notes/README.md @@ -0,0 +1,44 @@ +This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). + +## Available Scripts + +In the project directory, you can run: + +### `npm start` + +Runs the app in the development mode.
+Open [http://localhost:3000](http://localhost:3000) to view it in the browser. + +The page will reload if you make edits.
+You will also see any lint errors in the console. + +### `npm test` + +Launches the test runner in the interactive watch mode.
+See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. + +### `npm run build` + +Builds the app for production to the `build` folder.
+It correctly bundles React in production mode and optimizes the build for the best performance. + +The build is minified and the filenames include the hashes.
+Your app is ready to be deployed! + +See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. + +### `npm run eject` + +**Note: this is a one-way operation. Once you `eject`, you can’t go back!** + +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. + +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. + +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. + +## Learn More + +You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). + +To learn React, check out the [React documentation](https://reactjs.org/). diff --git a/lambda-notes/package.json b/lambda-notes/package.json new file mode 100644 index 0000000000..fd85ab20a9 --- /dev/null +++ b/lambda-notes/package.json @@ -0,0 +1,25 @@ +{ + "name": "lambda-notes", + "version": "0.1.0", + "private": true, + "dependencies": { + "react": "^16.6.3", + "react-dom": "^16.6.3", + "react-scripts": "2.1.1" + }, + "scripts": { + "start": "react-scripts start", + "build": "react-scripts build", + "test": "react-scripts test", + "eject": "react-scripts eject" + }, + "eslintConfig": { + "extends": "react-app" + }, + "browserslist": [ + ">0.2%", + "not dead", + "not ie <= 11", + "not op_mini all" + ] +} diff --git a/lambda-notes/public/favicon.ico b/lambda-notes/public/favicon.ico new file mode 100644 index 0000000000..a11777cc47 Binary files /dev/null and b/lambda-notes/public/favicon.ico differ diff --git a/lambda-notes/public/index.html b/lambda-notes/public/index.html new file mode 100644 index 0000000000..0323ac7755 --- /dev/null +++ b/lambda-notes/public/index.html @@ -0,0 +1,41 @@ + + + + + + + + + + + + Lambda Notes + + + +
+ + + diff --git a/lambda-notes/public/manifest.json b/lambda-notes/public/manifest.json new file mode 100644 index 0000000000..1f2f141faf --- /dev/null +++ b/lambda-notes/public/manifest.json @@ -0,0 +1,15 @@ +{ + "short_name": "React App", + "name": "Create React App Sample", + "icons": [ + { + "src": "favicon.ico", + "sizes": "64x64 32x32 24x24 16x16", + "type": "image/x-icon" + } + ], + "start_url": ".", + "display": "standalone", + "theme_color": "#000000", + "background_color": "#ffffff" +} diff --git a/lambda-notes/src/Actions/index.js b/lambda-notes/src/Actions/index.js new file mode 100644 index 0000000000..73a9a987a3 --- /dev/null +++ b/lambda-notes/src/Actions/index.js @@ -0,0 +1,78 @@ + import axios from "axios"; + +export const FETCHING_NOTES_START = "FETCHING_NOTES_START"; +export const FETCHING_NOTES_SUCCESS = "FETCHING_NOTES_SUCCESS"; +export const FETCHING_NOTES_FAILURE = "FETCHING_NOTES_FAILURE"; + +export const ADD_NOTE_START = "ADD_NOTE_START"; +export const ADD_NOTE_SUCCESS = "ADD_NOTE_SUCCESS"; +export const ADD_NOTE_FAILURE = "ADD_NOTE_FAILURE"; + +export const EDIT_NOTE_START = "EDIT_NOTE_START"; +export const EDIT_NOTE_SUCCESS = "EDIT_NOTE_SUCCESS"; +export const EDIT_NOTE_FAILURE = "EDIT_NOTE_FAILURE"; + +export const DELETE_NOTE_START = "DELETE_NOTE_START"; +export const DELETE_NOTE_SUCCESS = "DELETE_NOTE_SUCCESS"; +export const DELETE_NOTE_FAILURE = "DELETE_NOTE_FAILURE"; + + +export const fetchNotes = () => dispatch => { + dispatch({ type: FETCHING_NOTES_START }); + axios + .get("https://fe-notes.herokuapp.com/note/get/all") + .then(response => { + console.log(response); + dispatch({ type: FETCHING_NOTES_SUCCESS, payload: response.data }); + }) + .catch(error => { + dispatch({ type: FETCHING_NOTES_FAILURE, payload: error }); + }); +}; + +export const addNote = note => dispatch => { + dispatch({ type: ADD_NOTE_START }); + axios + .post("https://fe-notes.herokuapp.com/note/create", note) + .then(response => { + console.log(response); + dispatch({ + type: ADD_NOTE_SUCCESS, + payload: { ...note, _id: response.data.success } + }); + }) + .catch(error => { + dispatch({ type: ADD_NOTE_FAILURE, payload: error }); + }); +}; + +export const editNote = (note, id) => dispatch => { + dispatch({ type: EDIT_NOTE_START }); + axios + .put(`https://fe-notes.herokuapp.com/note/edit/${id}`, note) + .then(response => { + dispatch({ + type: EDIT_NOTE_SUCCESS, + payload: response.data + }); + }) + .catch(error => { + dispatch({ type: EDIT_NOTE_FAILURE, payload: error }); + }); +}; + +export const deleteNote = (id) => dispatch => { + dispatch({ type: DELETE_NOTE_START }) + axios + .delete(`https://fe-notes.herokuapp.com/note/delete/${id}`) + .then(response => { + console.log(response); + dispatch({ + type: DELETE_NOTE_SUCCESS, + payload: id + }) + }) + .catch(error => { + dispatch({ type: DELETE_NOTE_FAILURE, payload: error }) + }) +} \ No newline at end of file diff --git a/lambda-notes/src/App.css b/lambda-notes/src/App.css new file mode 100644 index 0000000000..33a08eda82 --- /dev/null +++ b/lambda-notes/src/App.css @@ -0,0 +1,27 @@ +.App .home-container { + display: flex; +} + +.App .home-container .content-container { + width: 70%; + margin-left: 25%; +} + +.btn { + padding: 1rem 2rem; + background: var(--blue); + color: var(--white); + border: 1px solid var(--border-gray); + font-size: 1.6rem; + font-weight: 800; + text-align: center; + cursor: pointer; + width: 20rem; + box-shadow: 0 1rem 2rem rgba(0, 0, 0, 0.1); +} + +.blue:hover { + box-shadow: 0 1.5rem 2.5rem rgba(0, 0, 0, 0.1); + color: var(--blue); + background: var(--white); +} diff --git a/lambda-notes/src/App.js b/lambda-notes/src/App.js new file mode 100644 index 0000000000..5585ed471a --- /dev/null +++ b/lambda-notes/src/App.js @@ -0,0 +1,80 @@ +import React, { Component } from "react"; +import { connect } from "react-redux"; +import { Route, withRouter } from "react-router-dom"; + +import { fetchNotes } from "./Actions"; +import Navigation from "./Components/Navigation/Navigation.js"; +import NoteList from "./Components/NoteList/NoteList.js"; +import NoteForm from "./Components/NoteForm/NoteForm.js"; +import Note from "./Components/Note/Note.js"; + +import "./App.css"; + +class App extends Component { + state = { + searchText: "" + } + + componentDidMount() { + this.props.fetchNotes(); + } + + searchNotes = event => { + this.setState({ + searchText: event.target.value + }) + } + + render() { + let filteredNotes = this.props.notes.slice(); + + if (this.state.searchText !== "") { + filteredNotes = filteredNotes.filter( note => { + let title = note.title.toLowerCase().includes(this.state.searchText.toLowerCase()); + let content = note.textBody.toLowerCase().includes(this.state.searchText.toLowerCase()); + return title || content; + }) + } + + + return ( +
+
+ +
+ 0 ? filteredNotes : this.props.notes} searchText={this.state.searchText} searchNotes={this.searchNotes}/>} + /> + + } + /> + + } /> + + } + /> +
+
+
+ ); + } +} + +const mapStateToProps = state => ({ + notes: state.notes +}); + +export default withRouter( + connect( + mapStateToProps, + { fetchNotes } + )(App) +); diff --git a/lambda-notes/src/Components/DeleteNote/DeleteNote.css b/lambda-notes/src/Components/DeleteNote/DeleteNote.css new file mode 100644 index 0000000000..b054958e92 --- /dev/null +++ b/lambda-notes/src/Components/DeleteNote/DeleteNote.css @@ -0,0 +1,29 @@ +.delete-container { + position: absolute; + left: calc(62.5% - 60rem/2); + top: calc(50% - 15rem/2); +} + +.delete-modal { + background: var(--white); + border: 2px solid var(--border-gray); + padding: 3rem 4rem; + display: flex; + justify-content: center; + flex-direction: column; + align-items: center; + width: 60rem; +} + +.delete-modal .delete-message { + margin-bottom: 2rem; +} + +.delete-modal .button-row { + display: flex; +} + +.delete-modal .button-row .delete { + background: var(--red); + margin-right: 2rem; +} diff --git a/lambda-notes/src/Components/DeleteNote/DeleteNote.js b/lambda-notes/src/Components/DeleteNote/DeleteNote.js new file mode 100644 index 0000000000..e1f5ecc9b9 --- /dev/null +++ b/lambda-notes/src/Components/DeleteNote/DeleteNote.js @@ -0,0 +1,38 @@ + import React from "react"; +import { connect } from "react-redux"; +import { deleteNote } from "../../Actions"; + +import "./DeleteNote.css"; + +const DeleteNote = props => { + if (props.isVisible) { + return ( +
+
+

Are you sure you want to delete this?

+
+
{ + props.deleteNote(props.note._id); + props.history.push("/"); + }} + > + Delete +
+
+ No +
+
+
+
+ ); + } else { + return <>; + } +}; + +export default connect( + null, + { deleteNote } +)(DeleteNote); diff --git a/lambda-notes/src/Components/Navigation/Navigation.css b/lambda-notes/src/Components/Navigation/Navigation.css new file mode 100644 index 0000000000..824fa0da21 --- /dev/null +++ b/lambda-notes/src/Components/Navigation/Navigation.css @@ -0,0 +1,33 @@ +.nav-bar { + background-color: var(--medium-gray); + width: 25%; + max-width: 25rem; + padding: 1rem 1rem; + height: 100vh; + border: 1px solid var(--border-gray); + position: fixed; +} + +.nav-bar .nav-container { + display: flex; + flex-direction: column; +} +.nav-bar .nav-container a { + text-decoration: none; +} + +.nav-bar .nav-container h1 { + color: var(--dark-gray); + line-height: 1; + margin-bottom: 2rem; + font-size: 3rem; +} +.nav-bar .nav-container .btn { + margin: 0 auto; + width: 95%; + max-width: 22rem; +} + +.nav-bar .nav-container .top-btn { + margin-bottom: 2rem; +} diff --git a/lambda-notes/src/Components/Navigation/Navigation.js b/lambda-notes/src/Components/Navigation/Navigation.js new file mode 100644 index 0000000000..48f2af777f --- /dev/null +++ b/lambda-notes/src/Components/Navigation/Navigation.js @@ -0,0 +1,27 @@ +import React from "react"; + +import { NavLink } from "react-router-dom"; + +import "./Navigation.css"; + +const Navigation = () => { + return ( + + ); +}; + +export default Navigation; diff --git a/lambda-notes/src/Components/Note/Note.css b/lambda-notes/src/Components/Note/Note.css new file mode 100644 index 0000000000..52ab88fd1f --- /dev/null +++ b/lambda-notes/src/Components/Note/Note.css @@ -0,0 +1,28 @@ +.note-container { + padding: 2rem 1rem; +} + +.note-container .button-menu { + display: flex; + justify-content: flex-end; + align-items: center; + margin-bottom: 2rem; +} + +.note-container .button-menu i { + font-size: 3rem; + color: var(--black); + cursor: pointer; +} + +.note-container .title { + margin-bottom: 2rem; +} + +.fa-edit { + margin-left: 2.5rem; +} + +.error-message { + margin-top: 3rem; +} diff --git a/lambda-notes/src/Components/Note/Note.js b/lambda-notes/src/Components/Note/Note.js new file mode 100644 index 0000000000..c48be24cfc --- /dev/null +++ b/lambda-notes/src/Components/Note/Note.js @@ -0,0 +1,77 @@ +import React from "react"; +import { connect } from "react-redux"; +import PropTypes from "prop-types"; + +import DeleteNote from "../DeleteNote/DeleteNote"; + +import "./Note.css"; + +class Note extends React.Component { + constructor(props) { + super(props); + this.state = { + isVisible: false + }; + } + + toggleDelete = event => { + event.preventDefault(); + this.setState({ + isVisible: !this.state.isVisible + }); + }; + + render() { + const note = this.props.notes.find( + note => `${note._id}` === this.props.match.params.id + ); + + if (!note) { + return ( +

+ Sorry, the note is currently unavailable! +

+ ); + } + return ( +
+
+ + this.props.history.push(`/edit-note/${note._id}`)} + className="fas fa-edit" + /> +
+

{note.title}

+

{note.textBody}

+ +
+ ); + } +} + +const mapStateToProps = state => { + return { + notes: state.notes + }; +}; + +export default connect( + mapStateToProps, + null +)(Note); + + +Note.propTypes = { + notes: PropTypes.arrayOf( + PropTypes.shape({ + title: PropTypes.string, + textBody: PropTypes.string + }) + ) +} \ No newline at end of file diff --git a/lambda-notes/src/Components/NoteBox/NoteBox.css b/lambda-notes/src/Components/NoteBox/NoteBox.css new file mode 100644 index 0000000000..6a3ffd14fa --- /dev/null +++ b/lambda-notes/src/Components/NoteBox/NoteBox.css @@ -0,0 +1,14 @@ +.note-box { + background: var(--white); + border: 2px solid var(--border-gray); + padding: 1.5rem; + box-shadow: 0 1rem 2rem rgba(0, 0, 0, 0.1); + min-height: 31rem; +} + +.note-box .line { + background: var(--border-gray); + height: 2px; + width: 100%; + margin: 0.5rem auto; +} diff --git a/lambda-notes/src/Components/NoteBox/NoteBox.js b/lambda-notes/src/Components/NoteBox/NoteBox.js new file mode 100644 index 0000000000..ba8ee9091c --- /dev/null +++ b/lambda-notes/src/Components/NoteBox/NoteBox.js @@ -0,0 +1,49 @@ +import React from "react"; +import PropTypes from "prop-types"; + +import "./NoteBox.css"; + +const NoteBox = props => { + let text = props.textBody + .split("") + .splice(0, 199) + .join("") + .concat("..."); + let title = props.title + .split("") + .splice(0, 19) + .join("") + .concat("..."); + + let longWord = props.textBody + .split(" ") + .filter(word => word.length > 20) + .join(""); + let displayWord = longWord + .split("") + .splice(0, 19) + .join("") + .concat("..."); + + return ( +
+

{props.title.length > 20 ? title : props.title}

+
+

+ {longWord.length > 20 + ? displayWord + : props.textBody.length > 200 + ? text + : props.textBody} +

+
+ ); +}; + +export default NoteBox; + + +NoteBox.propTypes = { + title: PropTypes.string, + textBody: PropTypes.string +} \ No newline at end of file diff --git a/lambda-notes/src/Components/NoteForm/NoteForm.css b/lambda-notes/src/Components/NoteForm/NoteForm.css new file mode 100644 index 0000000000..2c100604a5 --- /dev/null +++ b/lambda-notes/src/Components/NoteForm/NoteForm.css @@ -0,0 +1,34 @@ +.note-form-container { + background: var(--light-gray); + width: 100%; + padding: 4rem 3rem; +} + +.note-form-container h2 { + margin-bottom: 2rem; +} + +.note-form-container form { + display: flex; + flex-direction: column; +} + +.name-input { + padding: 1rem; + border: 1.3px solid var(--border-gray); + border-radius: 3px; + margin-bottom: 1rem; + width: 35rem; + outline: none; +} + +.content-textarea { + padding: 1rem; + border: 1.3px solid var(--border-gray); + border-radius: 3px; + max-width: 70rem; + height: 40rem; + margin-bottom: 1rem; + outline: none; + resize: none; +} diff --git a/lambda-notes/src/Components/NoteForm/NoteForm.js b/lambda-notes/src/Components/NoteForm/NoteForm.js new file mode 100644 index 0000000000..596dcd877d --- /dev/null +++ b/lambda-notes/src/Components/NoteForm/NoteForm.js @@ -0,0 +1,84 @@ +import React, { Component } from "react"; +import { connect } from "react-redux"; +import { withRouter } from "react-router-dom"; +import PropTypes from "prop-types"; + +import { addNote, editNote } from "../../Actions"; + +import "./NoteForm.css"; + +class NoteForm extends Component { + constructor() { + super(); + this.state = { + title: "", + textBody: "" + }; + } + + handleInputChange = event => { + this.setState({ + [event.target.name]: event.target.value + }); + }; + + submitHandler = event => { + event.preventDefault(); + if (this.props.edit) { + this.props.editNote(this.state, this.props.match.params.id); + } else { + this.props.addNote(this.state); + } + this.props.history.push("/"); + }; + + render() { + return ( +
+

{this.props.edit ? "Edit Note:" : "Create New Note:"}

+
+ +