File tree Expand file tree Collapse file tree 7 files changed +49
-9
lines changed Expand file tree Collapse file tree 7 files changed +49
-9
lines changed Original file line number Diff line number Diff line change 12
12
"@types/react-dom" : " ^18.0.6" ,
13
13
"react" : " ^18.2.0" ,
14
14
"react-dom" : " ^18.2.0" ,
15
+ "react-icons" : " ^4.4.0" ,
15
16
"react-scripts" : " 5.0.1" ,
16
17
"typescript" : " ^4.8.3" ,
17
18
"uuid" : " ^9.0.0" ,
Original file line number Diff line number Diff line change @@ -12,14 +12,24 @@ function App() {
12
12
const addNote = ( note :NoteType ) => {
13
13
setNotes ( [ note , ...notes ] )
14
14
}
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
+ }
15
25
return (
16
26
< div className = "App" >
17
27
< h2 > Notes App</ h2 >
18
28
< AddNote addNote = { addNote } > </ AddNote >
19
29
< div >
20
30
{
21
31
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 >
23
33
)
24
34
}
25
35
</ div >
Original file line number Diff line number Diff line change 6
6
height : 5rem ;
7
7
border-radius : 0.5rem ;
8
8
margin-top : 1rem ;
9
+ position : relative;
9
10
10
11
}
Original file line number Diff line number Diff line change 1
1
export type Priority = 'high' | 'medium' | 'low' ;
2
2
3
- export type NoteProps = {
4
- text : string ,
5
- priority ? : Priority
6
- }
7
-
8
3
export type NoteType = {
9
4
id : string ,
10
5
text : string ,
Original file line number Diff line number Diff line change 1
1
2
-
2
+ .right-corner {
3
+ position : absolute;
4
+ bottom : 0 ;
5
+ right : 0 ;
6
+ padding : 0.5rem ;
7
+ }
Original file line number Diff line number Diff line change 1
1
import './note.css'
2
2
3
- import { NoteProps , Color } from './note-type' ;
3
+ import { Color , Priority } from './note-type' ;
4
4
import Card from '../card/card' ;
5
+ import { FaTrash , FaEdit } from 'react-icons/fa' ;
5
6
6
-
7
+ type NoteProps = {
8
+ id : string ,
9
+ text : string ,
10
+ priority ? : Priority ,
11
+ editNote :( id : string ) => void ,
12
+ deleteNote :( id : string ) => void
13
+ }
7
14
8
15
9
16
function Note ( props : NoteProps ) {
@@ -12,9 +19,15 @@ function Note(props: NoteProps){
12
19
bgColor = { props . priority && Color [ props . priority ] }
13
20
height = '2'
14
21
padding = '1' >
22
+ < >
15
23
< div >
16
24
{ props . text }
17
25
</ 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
+ </ >
18
31
</ Card >
19
32
)
20
33
}
You can’t perform that action at this time.
0 commit comments