mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-17 03:31:52 +00:00
refactor: replace code with micro components
This commit is contained in:
@@ -6,6 +6,8 @@ import _ from 'lodash'
|
|||||||
import ee from 'browser/main/lib/eventEmitter'
|
import ee from 'browser/main/lib/eventEmitter'
|
||||||
import dataApi from 'browser/main/lib/dataApi'
|
import dataApi from 'browser/main/lib/dataApi'
|
||||||
import ConfigManager from 'browser/main/lib/ConfigManager'
|
import ConfigManager from 'browser/main/lib/ConfigManager'
|
||||||
|
import NoteItem from './NoteItem'
|
||||||
|
import NoteItemSimple from './NoteItemSimple'
|
||||||
|
|
||||||
const { remote } = require('electron')
|
const { remote } = require('electron')
|
||||||
const { Menu, MenuItem, dialog } = remote
|
const { Menu, MenuItem, dialog } = remote
|
||||||
@@ -314,62 +316,40 @@ class NoteList extends React.Component {
|
|||||||
.sort(sortFunc)
|
.sort(sortFunc)
|
||||||
|
|
||||||
let noteList = notes
|
let noteList = notes
|
||||||
.map((note) => {
|
.map(note => {
|
||||||
if (note == null) return null
|
if (note == null) {
|
||||||
let tagElements = _.isArray(note.tags)
|
return null
|
||||||
? note.tags.map((tag) => {
|
}
|
||||||
return (
|
|
||||||
<span styleName='item-bottom-tagList-item'
|
|
||||||
key={tag}>
|
|
||||||
{tag}
|
|
||||||
</span>
|
|
||||||
)
|
|
||||||
})
|
|
||||||
: []
|
|
||||||
let isActive = location.query.key === note.storage + '-' + note.key
|
|
||||||
const isDefault = config.listStyle === 'DEFAULT'
|
const isDefault = config.listStyle === 'DEFAULT'
|
||||||
|
const isActive = location.query.key === note.storage + '-' + note.key
|
||||||
|
const dateDisplay = moment(
|
||||||
|
config.sortBy === 'CREATED_AT' ?
|
||||||
|
note.createdAt : note.updatedAt
|
||||||
|
).fromNow()
|
||||||
|
const key = `${note.storage}-${note.key}`
|
||||||
|
|
||||||
|
if (isDefault) {
|
||||||
|
return (
|
||||||
|
<NoteItem
|
||||||
|
isActive={isActive}
|
||||||
|
note={note}
|
||||||
|
dateDisplay={dateDisplay}
|
||||||
|
key={key}
|
||||||
|
handleNoteClick={this.handleNoteClick.bind(this)}
|
||||||
|
handleNoteContextMenu={this.handleNoteContextMenu.bind(this)}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div styleName={isActive
|
<NoteItemSimple
|
||||||
? 'item--active'
|
isActive={isActive}
|
||||||
: 'item'
|
note={note}
|
||||||
}
|
key={key}
|
||||||
key={note.storage + '-' + note.key}
|
handleNoteClick={this.handleNoteClick.bind(this)}
|
||||||
onClick={(e) => this.handleNoteClick(e, note.storage + '-' + note.key)}
|
handleNoteContextMenu={this.handleNoteContextMenu.bind(this)}
|
||||||
onContextMenu={(e) => this.handleNoteContextMenu(e, note.storage + '-' + note.key)}
|
/>
|
||||||
>
|
|
||||||
{isDefault &&
|
|
||||||
<div styleName='item-bottom-time'>
|
|
||||||
{moment(config.sortBy === 'CREATED_AT' ? note.createdAt : note.updatedAt).fromNow()}
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
|
|
||||||
<div styleName='item-title'>
|
|
||||||
{note.title.trim().length > 0
|
|
||||||
? note.title
|
|
||||||
: <span styleName='item-title-empty'>Empty</span>
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{isDefault &&
|
|
||||||
<div styleName='item-bottom'>
|
|
||||||
<div styleName='item-bottom-tagList'>
|
|
||||||
{tagElements.length > 0
|
|
||||||
? tagElements
|
|
||||||
: ''
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
|
|
||||||
{isDefault &&
|
|
||||||
<i styleName='item-star'
|
|
||||||
className={note.isStarred
|
|
||||||
? 'fa fa-star'
|
|
||||||
: 'fa fa-star-o'
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user