11import React , { Component } from 'react' ;
2- import { Segment , Menu , Icon , Message } from 'semantic-ui-react' ;
2+ import { Segment , Menu , Icon , Message , Modal , Button } from 'semantic-ui-react' ;
33import SyntaxHighlighter from 'react-syntax-highlighter' ;
44import { docco } from 'react-syntax-highlighter/styles/hljs' ;
55import CryptoJS from 'crypto-js' ;
@@ -11,6 +11,10 @@ import History from '../../helpers/History';
1111
1212export default ViewerStore . subscribe (
1313 class extends Component {
14+ state = {
15+ renderDeleteConfirm : false
16+ } ;
17+
1418 componentWillMount = ( ) => {
1519 if ( this . props . match . params . id ) {
1620 ViewerStore . set ( { loading : true } ) ;
@@ -30,8 +34,39 @@ export default ViewerStore.subscribe(
3034
3135 handleEdit = ( ) => History . push ( `/notes/edit/${ this . props . note . id } ` ) ;
3236
37+ handleDelete = ( ) => this . setState ( { renderDeleteConfirm : true } ) ;
38+
3339 handleClose = ( ) => History . push ( '/notes' ) ;
3440
41+ renderDeleteConfirmation = ( ) => (
42+ < Modal
43+ open = { this . state . renderDeleteConfirm }
44+ onClose = { ( ) => this . setState ( { renderDeleteConfirm : false } ) }
45+ >
46+ < Modal . Header > Delete a note</ Modal . Header >
47+ < Modal . Content >
48+ < p > Are you sure you want to delete this note? This action is not reversible.</ p >
49+ </ Modal . Content >
50+ < Modal . Actions >
51+ < Button onClick = { ( ) => this . setState ( { renderDeleteConfirm : false } ) } >
52+ Nope, wrong button
53+ </ Button >
54+ < Button
55+ onClick = { ( ) => {
56+ this . setState ( { renderDeleteConfirm : false } ) ;
57+ ViewerStore . set ( { loading : true } ) ;
58+ Notes . delete ( this . props . note . id ) . then ( ( ) => {
59+ History . push ( `/notes` ) ;
60+ } ) ;
61+ } }
62+ negative
63+ icon = "warning sign"
64+ content = "Yes, delete this note"
65+ />
66+ </ Modal . Actions >
67+ </ Modal >
68+ ) ;
69+
3570 renderTopMenu = ( ) => {
3671 return this . props . note ? (
3772 < Menu secondary attached = "top" >
@@ -50,6 +85,9 @@ export default ViewerStore.subscribe(
5085 < Menu . Item onClick = { this . handleEdit } >
5186 < Icon name = "pencil" /> Edit
5287 </ Menu . Item >
88+ < Menu . Item onClick = { this . handleDelete } >
89+ < Icon name = "trash" /> Delete
90+ </ Menu . Item >
5391 < Menu . Item onClick = { this . handleClose } >
5492 < Icon name = "times" /> Close
5593 </ Menu . Item >
@@ -113,6 +151,7 @@ export default ViewerStore.subscribe(
113151
114152 return (
115153 < Segment loading = { loading } className = "raw calepin-viewer" >
154+ { this . renderDeleteConfirmation ( ) }
116155 { this . renderTopMenu ( ) }
117156 < Segment attached = { note ? 'bottom' : null } > { this . renderViewer ( ) } </ Segment >
118157 </ Segment >
0 commit comments