1
1
import style from './style.module.css'
2
2
import { CrossIcon } from '@ui/icons/CrossIcon'
3
+ import { useState , useRef } from 'react'
3
4
import ReactMarkdown from 'react-markdown'
4
5
5
6
// Types
@@ -18,26 +19,47 @@ export function NotesList({ notes }: { notes?: NoteEdge[] }) {
18
19
}
19
20
20
21
function Note ( { note } : { note ?: NoteEdge } ) {
22
+ const [ confirmDelete , setConfirmDelete ] = useState < boolean > ( false )
23
+ const noteRef = useRef < HTMLDivElement > ( null )
24
+
21
25
const node = note ?. node
22
26
const title = node ?. title
23
27
const contentPreview = node ?. contentPreview as string
28
+
29
+ const handleDeleteClick = ( ) => {
30
+ if ( noteRef . current ) noteRef . current . scrollIntoView ( { behavior : 'smooth' } )
31
+ setConfirmDelete ( true )
32
+ }
33
+ const handleCancelClick = ( ) => setConfirmDelete ( false )
34
+
24
35
return contentPreview ? (
25
- < div className = { style . container } >
36
+ < div className = { ` ${ style . container } ${ confirmDelete && style . active } ` } ref = { noteRef } >
26
37
< div className = { style . note } >
27
38
{ title ? < h3 > { title } </ h3 > : null }
28
39
< ReactMarkdown allowedElements = { [ 'div' ] } unwrapDisallowed = { true } >
29
40
{ contentPreview }
30
41
</ ReactMarkdown >
31
42
</ div >
32
43
< div className = { style . actions } >
33
- < button >
34
- < CrossIcon />
35
- </ button >
44
+ { ! confirmDelete ? (
45
+ < button onClick = { handleDeleteClick } >
46
+ < CrossIcon />
47
+ </ button >
48
+ ) : null }
36
49
</ div >
50
+ { confirmDelete ? < NoteDeleteConfirm handleCancelClick = { handleCancelClick } /> : null }
37
51
</ div >
38
52
) : null
39
53
}
40
54
55
+ function NoteDeleteConfirm ( { handleCancelClick } : { handleCancelClick : ( ) => void } ) {
56
+ return (
57
+ < div className = { style . confirm } >
58
+ < button > Delete this note</ button >
59
+ < button onClick = { handleCancelClick } > Cancel</ button >
60
+ </ div >
61
+ )
62
+ }
41
63
function NoNotes ( ) {
42
64
return < div className = { style . noNotes } > Add your first note to this page</ div >
43
65
}
0 commit comments