Skip to content

Commit 21976ee

Browse files
delete note
1 parent bfd1b77 commit 21976ee

File tree

7 files changed

+49
-9
lines changed

7 files changed

+49
-9
lines changed

package-lock.json

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"@types/react-dom": "^18.0.6",
1313
"react": "^18.2.0",
1414
"react-dom": "^18.2.0",
15+
"react-icons": "^4.4.0",
1516
"react-scripts": "5.0.1",
1617
"typescript": "^4.8.3",
1718
"uuid": "^9.0.0",

src/App.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,24 @@ function App() {
1212
const addNote = (note:NoteType)=>{
1313
setNotes([note,...notes])
1414
}
15+
const editNote = (id:string)=>{
16+
console.log('edit',id);
17+
}
18+
19+
const deleteNote = (id:string)=>{
20+
const index = notes.findIndex(note=>note.id===id);
21+
let editedNotes = [...notes]
22+
editedNotes.splice(index,1);
23+
setNotes(editedNotes);
24+
}
1525
return (
1626
<div className="App">
1727
<h2>Notes App</h2>
1828
<AddNote addNote={addNote}></AddNote>
1929
<div>
2030
{
2131
notes.map(
22-
note=> <Note key={note.id} priority={note.priority} text={note.text}></Note>
32+
note=> <Note key={note.id} id={note.id} priority={note.priority} text={note.text} editNote={editNote} deleteNote={deleteNote}></Note>
2333
)
2434
}
2535
</div>

src/components/card/card.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
height: 5rem;
77
border-radius: 0.5rem;
88
margin-top: 1rem;
9+
position: relative;
910

1011
}

src/components/note/note-type.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
export type Priority = 'high' | 'medium' | 'low';
22

3-
export type NoteProps = {
4-
text: string,
5-
priority? : Priority
6-
}
7-
83
export type NoteType = {
94
id: string,
105
text: string,

src/components/note/note.css

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11

2-
2+
.right-corner{
3+
position: absolute;
4+
bottom: 0;
5+
right: 0;
6+
padding: 0.5rem;
7+
}

src/components/note/note.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
import './note.css'
22

3-
import {NoteProps,Color} from './note-type';
3+
import {Color, Priority} from './note-type';
44
import Card from '../card/card';
5+
import { FaTrash, FaEdit } from 'react-icons/fa';
56

6-
7+
type NoteProps = {
8+
id: string,
9+
text: string,
10+
priority? : Priority,
11+
editNote:(id: string) => void,
12+
deleteNote:(id: string) => void
13+
}
714

815

916
function Note(props: NoteProps){
@@ -12,9 +19,15 @@ function Note(props: NoteProps){
1219
bgColor={props.priority && Color[props.priority]}
1320
height='2'
1421
padding='1'>
22+
<>
1523
<div>
1624
{props.text}
1725
</div>
26+
<div className='right-corner'>
27+
<FaEdit onClick={()=>props.editNote(props.id)}></FaEdit>
28+
<FaTrash onClick={()=>props.deleteNote(props.id)}></FaTrash>
29+
</div>
30+
</>
1831
</Card>
1932
)
2033
}

0 commit comments

Comments
 (0)