generated from Wes-Coburn/template-MERN-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated to be a standalone note taker app
- Loading branch information
1 parent
9da9203
commit 7ac28fe
Showing
20 changed files
with
696 additions
and
1,432 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,19 @@ | ||
const serverURL = import.meta.env.VITE_SERVER_URL; | ||
const apiURL = (path: string) => `${serverURL}/${path}`; | ||
|
||
const jsonHeaders = { | ||
Accept: 'application/json', | ||
'Content-type': 'application/json', | ||
}; | ||
|
||
const API = { | ||
getAllNotes: () => apiURL('note'), | ||
getAllNotes: () => fetch(apiURL('note'), { method: 'GET' }), | ||
saveNewNote: (text: string) => | ||
fetch(apiURL('note'), { | ||
method: 'POST', | ||
headers: jsonHeaders, | ||
body: JSON.stringify({ text }), | ||
}), | ||
}; | ||
|
||
export default API; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
Main { | ||
grid-area: middle; | ||
min-height: 50vh; | ||
display: flex; | ||
justify-content: center; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.NewNoteContainer { | ||
width: 60vmax; | ||
max-width: 80%; | ||
} | ||
|
||
.NewNoteInput { | ||
width: 100%; | ||
margin: 5vmin 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { setNewNote, selectNewNote, saveNewNote } from '../notesSlice'; | ||
import { useAppDispatch, useAppSelector } from '../../../app/hooks'; | ||
import styles from './NewNote.module.css'; | ||
|
||
export default function NewNote() { | ||
const dispatch = useAppDispatch(); | ||
const newNote = useAppSelector(selectNewNote); | ||
|
||
const handleChange: React.ChangeEventHandler<HTMLInputElement> = (event) => { | ||
dispatch(setNewNote(event.target.value)); | ||
}; | ||
|
||
const handleSubmit = async (event: React.SyntheticEvent) => { | ||
event.preventDefault(); | ||
// eslint-disable-next-line no-alert | ||
alert(newNote); | ||
dispatch(saveNewNote(newNote)); | ||
dispatch(setNewNote('')); | ||
}; | ||
|
||
return ( | ||
<div className={styles.NewNoteContainer}> | ||
<p>New Note</p> | ||
<form onSubmit={handleSubmit}> | ||
<div className={styles.NewNoteInput}> | ||
<input | ||
id="newNoteInput" | ||
type="text" | ||
value={newNote} | ||
onChange={handleChange} | ||
required | ||
/> | ||
</div> | ||
<button type="submit">Save</button> | ||
</form> | ||
</div> | ||
); | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* eslint-disable no-underscore-dangle */ | ||
import { useEffect } from 'react'; | ||
import { useAppDispatch, useAppSelector } from '../../../app/hooks'; | ||
import { selectAllNotes, getAllNotes } from '../notesSlice'; | ||
import Note from '../Note'; | ||
import NotFound from '../../NotFound'; | ||
|
||
export default function NotesList() { | ||
const allNotes = useAppSelector(selectAllNotes); | ||
const dispatch = useAppDispatch(); | ||
|
||
useEffect(() => { | ||
dispatch(getAllNotes()); | ||
}, [dispatch]); | ||
|
||
const notesList = allNotes.map((note) => ( | ||
<Note key={note._id} text={note.text} /> | ||
)); | ||
|
||
// TODO: Replace <NotFound /> with 'no notes' message | ||
return notesList.length > 0 ? <div>{notesList}</div> : <NotFound />; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.