@@ -7,8 +7,6 @@ import _ from 'lodash'
77class NoteList extends React . Component {
88 constructor ( props ) {
99 super ( props )
10-
11- // this.focusHandler = (e) => this.focus()
1210 }
1311
1412 componentDidMount ( ) {
@@ -34,11 +32,8 @@ class NoteList extends React.Component {
3432
3533 // Auto scroll
3634 if ( _ . isString ( location . query . key ) ) {
37- let splitted = location . query . key . split ( '/' )
38- let repoKey = splitted [ 0 ]
39- let noteKey = splitted [ 1 ]
4035 let targetIndex = _ . findIndex ( this . notes , ( note ) => {
41- return repoKey === note . storage && noteKey === note . key
36+ return note . uniqueKey === location . query . key
4237 } )
4338 if ( targetIndex > - 1 ) {
4439 let list = this . refs . root
@@ -66,11 +61,9 @@ class NoteList extends React.Component {
6661 }
6762 let { router } = this . context
6863 let { location } = this . props
69- let splitted = location . query . key . split ( '-' )
70- let repoKey = splitted [ 0 ]
71- let noteKey = splitted [ 1 ]
64+
7265 let targetIndex = _ . findIndex ( this . notes , ( note ) => {
73- return repoKey === note . storage && noteKey === note . key
66+ return note . uniqueKey === location . query . key
7467 } )
7568
7669 if ( targetIndex === 0 ) {
@@ -93,11 +86,9 @@ class NoteList extends React.Component {
9386 }
9487 let { router } = this . context
9588 let { location } = this . props
96- let splitted = location . query . key . split ( '-' )
97- let repoKey = splitted [ 0 ]
98- let noteKey = splitted [ 1 ]
89+
9990 let targetIndex = _ . findIndex ( this . notes , ( note ) => {
100- return repoKey === note . _repository . key && noteKey === note . key
91+ return note . uniqueKey === location . query . key
10192 } )
10293
10394 if ( targetIndex === this . notes . length - 1 ) {
@@ -140,7 +131,6 @@ class NoteList extends React.Component {
140131
141132 // if (e.keyCode === 69) {
142133 // e.preventDefault()
143- // remote.getCurrentWebContents().send('detail-edit')
144134 // }
145135
146136 // if (e.keyCode === 83) {
@@ -160,37 +150,29 @@ class NoteList extends React.Component {
160150 }
161151
162152 getNotes ( ) {
163- let { repositories, params, location } = this . props
164- let repositoryKey = params . repositoryKey
165- let folderKey = params . folderKey
153+ let { storages, notes, params, location } = this . props
166154
167155 if ( location . pathname . match ( / \/ h o m e / ) ) {
168- return repositories
169- . reduce ( ( sum , repository ) => {
170- return sum . concat ( repository . notes )
171- } , [ ] )
156+ return notes
172157 }
173158
174159 if ( location . pathname . match ( / \/ s t a r r e d / ) ) {
175- return repositories
176- . reduce ( ( sum , repository ) => {
177- return sum . concat ( repository . starred
178- . map ( ( starredKey ) => {
179- return _ . find ( repository . notes , { key : starredKey } )
180- } )
181- . filter ( ( note ) => _ . isObject ( note ) ) )
182- } , [ ] )
160+ return notes
161+ . filter ( ( note ) => note . isStarred )
183162 }
184163
185- let repository = _ . find ( repositories , { key : repositoryKey } )
186- if ( repository == null ) return [ ]
164+ let storageKey = params . storageKey
165+ let folderKey = params . folderKey
166+ let storage = _ . find ( storages , { key : storageKey } )
167+ if ( storage == null ) return [ ]
187168
188- let folder = _ . find ( repository . folders , { key : folderKey } )
169+ let folder = _ . find ( storage . folders , { key : folderKey } )
189170 if ( folder == null ) {
190- return repository . notes
171+ return notes
172+ . filter ( ( note ) => note . storage === storageKey )
191173 }
192174
193- return repository . notes
175+ return notes
194176 . filter ( ( note ) => note . folder === folderKey )
195177 }
196178
@@ -210,11 +192,10 @@ class NoteList extends React.Component {
210192
211193 render ( ) {
212194 let { location, storages, notes } = this . props
213- this . notes = notes
214- // this.notes = this.getNotes( )
195+ this . notes = notes = this . getNotes ( )
196+ . sort ( ( a , b ) => new Date ( b . updatedAt ) - new Date ( a . updatedAt ) )
215197
216198 let noteList = notes
217- . sort ( ( a , b ) => new Date ( b . updatedAt ) - new Date ( a . updatedAt ) )
218199 . map ( ( note ) => {
219200 let storage = _ . find ( storages , { key : note . storage } )
220201 let folder = _ . find ( storage . folders , { key : note . folder } )
0 commit comments