Skip to content

Commit 409a3de

Browse files
committed
update NoteList
sort by updatedAt improve style add auto-scrolling
1 parent 431ac5a commit 409a3de

2 files changed

Lines changed: 58 additions & 22 deletions

File tree

browser/main/NoteList/NoteList.styl

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,26 @@
4949
font-weight bold
5050
overflow ellipsis
5151

52-
.item-tags
52+
.item-tagList
5353
height 30px
5454
font-size 12px
5555
line-height 30px
56-
color $ui-inactive-text-color
5756
overflow ellipsis
57+
58+
.item-tagList-icon
59+
vertical-align middle
60+
color $ui-button-color
61+
62+
.item-tagList-item
63+
margin 2px
64+
padding 0 4px
65+
height 20px
66+
border-radius 5px
67+
vertical-align middle
68+
border $ui-border
69+
color $ui-button-color
70+
71+
.item-tagList-empty
72+
color $ui-inactive-text-color
73+
vertical-align middle
74+

browser/main/NoteList/index.js

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,29 @@ class NoteList extends React.Component {
3232
key: `${this.notes[0]._repository.key}-${this.notes[0].key}`
3333
}
3434
})
35+
return
3536
}
36-
// return false
37-
// var index = articles.indexOf(null)
38-
// var el = ReactDOM.findDOMNode(this)
39-
// var li = el.querySelectorAll('.NoteList>div')[index]
40-
41-
// if (li == null) {
42-
// return
43-
// }
4437

45-
// var overflowBelow = el.clientHeight + el.scrollTop < li.offsetTop + li.clientHeight
46-
// if (overflowBelow) {
47-
// el.scrollTop = li.offsetTop + li.clientHeight - el.clientHeight
48-
// }
49-
// var overflowAbove = el.scrollTop > li.offsetTop
50-
// if (overflowAbove) {
51-
// el.scrollTop = li.offsetTop
52-
// }
38+
// Auto scroll
39+
let targetIndex = _.findIndex(this.notes, (note) => {
40+
let splitted = location.query.key.split('-')
41+
let repoKey = splitted[0]
42+
let noteKey = splitted[1]
43+
return repoKey === note._repository.key && noteKey === note.key
44+
})
45+
if (targetIndex > -1) {
46+
let list = this.refs.root
47+
let item = list.childNodes[targetIndex]
48+
49+
let overflowBelow = list.clientHeight + list.scrollTop < item.offsetTop + list.clientHeight
50+
if (overflowBelow) {
51+
list.scrollTop = item.offsetTop + item.clientHeight - list.clientHeight
52+
}
53+
let overflowAbove = list.scrollTop > item.offsetTop
54+
if (overflowAbove) {
55+
list.scrollTop = item.offsetTop
56+
}
57+
}
5358
}
5459

5560
focus () {
@@ -187,12 +192,18 @@ class NoteList extends React.Component {
187192

188193
render () {
189194
let { location } = this.props
190-
let notes = this.notes = this.getNotes()
195+
let notes = this.notes = this.getNotes().sort((a, b) => new Date(b.updatedAt) - new Date(a.updatedAt))
196+
191197
let noteElements = notes
192198
.map((note) => {
193199
let folder = _.find(note._repository.folders, {key: note.folder})
194200
let tagElements = note.tags.map((tag) => {
195-
return <span key={tag}>{tag}</span>
201+
return (
202+
<span styleName='item-tagList-item'
203+
key={tag}>
204+
{tag}
205+
</span>
206+
)
196207
})
197208
let key = `${note._repository.key}-${note.key}`
198209
let isActive = location.query.key === key
@@ -219,15 +230,23 @@ class NoteList extends React.Component {
219230

220231
<div styleName='item-title'>{note.title}</div>
221232

222-
<div styleName='item-tags'><i className='fa fa-tags fa-fw'/>{tagElements.length > 0 ? tagElements : <span>Not tagged yet</span>}</div>
223-
233+
<div styleName='item-tagList'>
234+
<i styleName='item-tagList-icon'
235+
className='fa fa-tags fa-fw'
236+
/>
237+
{tagElements.length > 0
238+
? tagElements
239+
: <span styleName='item-tagList-empty'>Not tagged yet</span>
240+
}
241+
</div>
224242
</div>
225243
)
226244
})
227245

228246
return (
229247
<div className='NoteList'
230248
styleName='root'
249+
ref='root'
231250
tabIndex='0'
232251
onKeyDown={(e) => this.handleNoteListKeyDown(e)}
233252
style={this.props.style}

0 commit comments

Comments
 (0)