mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
change search ux
This commit is contained in:
@@ -212,6 +212,10 @@ class NoteList extends React.Component {
|
||||
.map((uniqueKey) => data.noteMap.get(uniqueKey))
|
||||
}
|
||||
|
||||
if (location.pathname.match(/\/searched/)) {
|
||||
return this.getSearchNotes()
|
||||
}
|
||||
|
||||
let storageKey = params.storageKey
|
||||
let folderKey = params.folderKey
|
||||
let storage = data.storageMap.get(storageKey)
|
||||
@@ -349,6 +353,71 @@ class NoteList extends React.Component {
|
||||
})
|
||||
}
|
||||
|
||||
getSearchNotes () {
|
||||
let { data } = this.props
|
||||
let search = document.getElementsByClassName('TopBar__control-search-input___browser-main-TopBar-')[0].childNodes[0].value
|
||||
let notes = data.noteMap.map((note) => note)
|
||||
if (search.trim().length === 0) return []
|
||||
let searchBlocks = search.split(' ')
|
||||
searchBlocks.forEach((block) => {
|
||||
if (block.match(/^!#.+/)) {
|
||||
let tag = block.match(/^!#(.+)/)[1]
|
||||
let regExp = new RegExp(_.escapeRegExp(tag), 'i')
|
||||
notes = notes
|
||||
.filter((note) => {
|
||||
if (!_.isArray(note.tags)) return false
|
||||
return note.tags.some((_tag) => {
|
||||
return _tag.match(regExp)
|
||||
})
|
||||
})
|
||||
} else if (block.match(/^!.+/)) {
|
||||
let block = block.match(/^!(.+)/)[1]
|
||||
let regExp = new RegExp(_.escapeRegExp(block), 'i')
|
||||
notes = notes.filter((note) => {
|
||||
if (!_.isArray(note.tags) || !note.tags.some((_tag) => {
|
||||
return _tag.match(regExp)
|
||||
})) {
|
||||
return true
|
||||
}
|
||||
if (note.type === 'SNIPPET_NOTE') {
|
||||
return !note.description.match(regExp)
|
||||
} else if (note.type === 'MARKDOWN_NOTE') {
|
||||
return !note.content.match(regExp)
|
||||
}
|
||||
return false
|
||||
})
|
||||
} else if (block.match(/^#.+/)) {
|
||||
let tag = block.match(/#(.+)/)[1]
|
||||
let regExp = new RegExp(_.escapeRegExp(tag), 'i')
|
||||
notes = notes
|
||||
.filter((note) => {
|
||||
if (!_.isArray(note.tags)) return false
|
||||
return note.tags.some((_tag) => {
|
||||
return _tag.match(regExp)
|
||||
})
|
||||
})
|
||||
} else {
|
||||
let regExp = new RegExp(_.escapeRegExp(block), 'i')
|
||||
notes = notes.filter((note) => {
|
||||
if (_.isArray(note.tags) && note.tags.some((_tag) => {
|
||||
return _tag.match(regExp)
|
||||
})) {
|
||||
return true
|
||||
}
|
||||
if (note.type === 'SNIPPET_NOTE') {
|
||||
return note.description.match(regExp)
|
||||
} else if (note.type === 'MARKDOWN_NOTE') {
|
||||
return note.content.match(regExp)
|
||||
}
|
||||
return false
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
return notes
|
||||
|
||||
}
|
||||
|
||||
render () {
|
||||
let { location, notes, config } = this.props
|
||||
let sortFunc = config.sortBy === 'CREATED_AT'
|
||||
|
||||
Reference in New Issue
Block a user