Skip to content

Commit 7374b1c

Browse files
committed
refactor: replace code with micro components
1 parent e8f2972 commit 7374b1c

1 file changed

Lines changed: 34 additions & 54 deletions

File tree

browser/main/NoteList/index.js

Lines changed: 34 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import _ from 'lodash'
66
import ee from 'browser/main/lib/eventEmitter'
77
import dataApi from 'browser/main/lib/dataApi'
88
import ConfigManager from 'browser/main/lib/ConfigManager'
9+
import NoteItem from './NoteItem'
10+
import NoteItemSimple from './NoteItemSimple'
911

1012
const { remote } = require('electron')
1113
const { Menu, MenuItem, dialog } = remote
@@ -314,62 +316,40 @@ class NoteList extends React.Component {
314316
.sort(sortFunc)
315317

316318
let noteList = notes
317-
.map((note) => {
318-
if (note == null) return null
319-
let tagElements = _.isArray(note.tags)
320-
? note.tags.map((tag) => {
321-
return (
322-
<span styleName='item-bottom-tagList-item'
323-
key={tag}>
324-
{tag}
325-
</span>
326-
)
327-
})
328-
: []
329-
let isActive = location.query.key === note.storage + '-' + note.key
330-
const isDefault = config.listStyle === 'DEFAULT'
331-
return (
332-
<div styleName={isActive
333-
? 'item--active'
334-
: 'item'
335-
}
336-
key={note.storage + '-' + note.key}
337-
onClick={(e) => this.handleNoteClick(e, note.storage + '-' + note.key)}
338-
onContextMenu={(e) => this.handleNoteContextMenu(e, note.storage + '-' + note.key)}
339-
>
340-
{isDefault &&
341-
<div styleName='item-bottom-time'>
342-
{moment(config.sortBy === 'CREATED_AT' ? note.createdAt : note.updatedAt).fromNow()}
343-
</div>
344-
}
319+
.map(note => {
320+
if (note == null) {
321+
return null
322+
}
345323

346-
<div styleName='item-title'>
347-
{note.title.trim().length > 0
348-
? note.title
349-
: <span styleName='item-title-empty'>Empty</span>
350-
}
351-
</div>
352-
353-
{isDefault &&
354-
<div styleName='item-bottom'>
355-
<div styleName='item-bottom-tagList'>
356-
{tagElements.length > 0
357-
? tagElements
358-
: ''
359-
}
360-
</div>
361-
</div>
362-
}
324+
const isDefault = config.listStyle === 'DEFAULT'
325+
const isActive = location.query.key === note.storage + '-' + note.key
326+
const dateDisplay = moment(
327+
config.sortBy === 'CREATED_AT' ?
328+
note.createdAt : note.updatedAt
329+
).fromNow()
330+
const key = `${note.storage}-${note.key}`
331+
332+
if (isDefault) {
333+
return (
334+
<NoteItem
335+
isActive={isActive}
336+
note={note}
337+
dateDisplay={dateDisplay}
338+
key={key}
339+
handleNoteClick={this.handleNoteClick.bind(this)}
340+
handleNoteContextMenu={this.handleNoteContextMenu.bind(this)}
341+
/>
342+
)
343+
}
363344

364-
{isDefault &&
365-
<i styleName='item-star'
366-
className={note.isStarred
367-
? 'fa fa-star'
368-
: 'fa fa-star-o'
369-
}
370-
/>
371-
}
372-
</div>
345+
return (
346+
<NoteItemSimple
347+
isActive={isActive}
348+
note={note}
349+
key={key}
350+
handleNoteClick={this.handleNoteClick.bind(this)}
351+
handleNoteContextMenu={this.handleNoteContextMenu.bind(this)}
352+
/>
373353
)
374354
})
375355

0 commit comments

Comments
 (0)