From 409a3de901622285a1bf6928fa573bae17180477 Mon Sep 17 00:00:00 2001 From: Dick Choi Date: Sun, 29 May 2016 14:02:23 +0900 Subject: [PATCH] update NoteList sort by updatedAt improve style add auto-scrolling --- browser/main/NoteList/NoteList.styl | 21 ++++++++++- browser/main/NoteList/index.js | 57 +++++++++++++++++++---------- 2 files changed, 57 insertions(+), 21 deletions(-) diff --git a/browser/main/NoteList/NoteList.styl b/browser/main/NoteList/NoteList.styl index dd4043c6..dec5da35 100644 --- a/browser/main/NoteList/NoteList.styl +++ b/browser/main/NoteList/NoteList.styl @@ -49,9 +49,26 @@ font-weight bold overflow ellipsis -.item-tags +.item-tagList height 30px font-size 12px line-height 30px - color $ui-inactive-text-color overflow ellipsis + +.item-tagList-icon + vertical-align middle + color $ui-button-color + +.item-tagList-item + margin 2px + padding 0 4px + height 20px + border-radius 5px + vertical-align middle + border $ui-border + color $ui-button-color + +.item-tagList-empty + color $ui-inactive-text-color + vertical-align middle + diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index 15988da5..3509b625 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -32,24 +32,29 @@ class NoteList extends React.Component { key: `${this.notes[0]._repository.key}-${this.notes[0].key}` } }) + return } - // return false - // var index = articles.indexOf(null) - // var el = ReactDOM.findDOMNode(this) - // var li = el.querySelectorAll('.NoteList>div')[index] - // if (li == null) { - // return - // } + // Auto scroll + let targetIndex = _.findIndex(this.notes, (note) => { + let splitted = location.query.key.split('-') + let repoKey = splitted[0] + let noteKey = splitted[1] + return repoKey === note._repository.key && noteKey === note.key + }) + if (targetIndex > -1) { + let list = this.refs.root + let item = list.childNodes[targetIndex] - // var overflowBelow = el.clientHeight + el.scrollTop < li.offsetTop + li.clientHeight - // if (overflowBelow) { - // el.scrollTop = li.offsetTop + li.clientHeight - el.clientHeight - // } - // var overflowAbove = el.scrollTop > li.offsetTop - // if (overflowAbove) { - // el.scrollTop = li.offsetTop - // } + let overflowBelow = list.clientHeight + list.scrollTop < item.offsetTop + list.clientHeight + if (overflowBelow) { + list.scrollTop = item.offsetTop + item.clientHeight - list.clientHeight + } + let overflowAbove = list.scrollTop > item.offsetTop + if (overflowAbove) { + list.scrollTop = item.offsetTop + } + } } focus () { @@ -187,12 +192,18 @@ class NoteList extends React.Component { render () { let { location } = this.props - let notes = this.notes = this.getNotes() + let notes = this.notes = this.getNotes().sort((a, b) => new Date(b.updatedAt) - new Date(a.updatedAt)) + let noteElements = notes .map((note) => { let folder = _.find(note._repository.folders, {key: note.folder}) let tagElements = note.tags.map((tag) => { - return {tag} + return ( + + {tag} + + ) }) let key = `${note._repository.key}-${note.key}` let isActive = location.query.key === key @@ -219,8 +230,15 @@ class NoteList extends React.Component {
{note.title}
-
{tagElements.length > 0 ? tagElements : Not tagged yet}
- +
+ + {tagElements.length > 0 + ? tagElements + : Not tagged yet + } +
) }) @@ -228,6 +246,7 @@ class NoteList extends React.Component { return (
this.handleNoteListKeyDown(e)} style={this.props.style}