11import React from 'react' ;
22import FontAwesome from 'react-fontawesome' ;
3+ import PropTypes from 'prop-types' ;
4+ import { Link } from 'react-router-dom' ;
35
46import CloseBtn from './stateless/CloseBtn' ;
57import TagsList from './TagsList' ;
68
79import { formatDate , shorten } from '../common/helpers' ;
810import { sortNotes } from '../common/noteHelpers' ;
911
10- const Note = ( { notes = [ ] , isMobile = false , ...props } ) => {
12+ const Note = ( { notes = [ ] , match , isMobile = false , ...props } ) => {
1113 if ( ! notes . length ) {
1214 return < div className = "empty" > </ div > ;
1315 }
1416
1517 const note = sortNotes ( notes ) . map ( note =>
16- < li className = { ( note . isEditing ) ? 'note selected' : 'note' }
18+ < li className = { ( note . isEditing ) ? 'note selected' : 'note' }
1719 key = { note . id } id = { note . id }
18- onClick = { ( e ) => props . selectNote ( note ) } >
20+ onClick = { ( ) => props . selectNote ( note ) } >
1921
20- { ! isMobile && < CloseBtn onClick = { ( e ) => props . deleteNote ( note ) } /> }
21- { ( isMobile && note . url ) && < a className = "external-link" href = { note . url } target = "_blank" > < FontAwesome name = 'external-link' /> </ a > }
22+ { ! isMobile && < CloseBtn onClick = { ( ) => props . deleteNote ( note ) } /> }
23+ { ( isMobile && note . url ) && < a href = { note . url } className = "external-link" target = "_blank" > < FontAwesome name = 'external-link' /> </ a > }
2224
2325 { note . label && < div className = "note-label" style = { { background : note . label . hex } } > </ div > }
2426
2527 { note . title && < h2 className = "title" >
2628 { ( ! isMobile && note . url ) &&
27- < a href = { note . url } target = "_blank" > { shorten ( note . title , 80 ) } </ a >
29+ < a href = { note . url } target = "_blank" >
30+ { shorten ( note . title , 80 ) }
31+ </ a >
2832 }
2933 { ( ! isMobile && ! note . url ) && shorten ( note . title , 80 ) }
3034 { ( isMobile ) && shorten ( note . title , 80 ) }
@@ -41,16 +45,26 @@ const Note = ({ notes = [], isMobile = false, ...props }) => {
4145 { ( note . notebook && note . notebook . name ) &&
4246 < span className = "notebook" >
4347 < FontAwesome name = 'book' />
44- < a href > { note . notebook . name } </ a >
48+ < Link to = { `${ match . path } /${ note . notebook . name } ` } >
49+ { note . notebook . name }
50+ </ Link >
4551 </ span >
4652 }
47- < TagsList tags = { note . tags } />
53+ < TagsList tags = { note . tags } />
4854 </ div >
4955 </ div >
5056 </ li >
5157 ) ;
5258
53- return < div className = "notes" > < ul > { note } </ ul > </ div > ;
59+ return < div className = "notes" > < ul > { note } </ ul > </ div > ;
60+ } ;
61+
62+ Note . propTypes = {
63+ match : PropTypes . object ,
64+ notes : PropTypes . array ,
65+ isMobile : PropTypes . bool ,
66+ deleteNote : PropTypes . func ,
67+ selectNote : PropTypes . func ,
5468} ;
5569
5670export default Note ;
0 commit comments