mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
Refactor getContextNotes()
This commit is contained in:
@@ -93,7 +93,6 @@ class NoteList extends React.Component {
|
||||
if (this.notes.length > 0 && location.query.key == null) {
|
||||
let { router } = this.context
|
||||
if (!location.pathname.match(/\/searched/)) this.contextNotes = this.getContextNotes()
|
||||
console.log(this.contextNotes)
|
||||
router.replace({
|
||||
pathname: location.pathname,
|
||||
query: {
|
||||
@@ -266,28 +265,20 @@ class NoteList extends React.Component {
|
||||
|
||||
// get notes in the current folder
|
||||
getContextNotes () {
|
||||
let { data, params } = this.props
|
||||
let storageKey = params.storageKey
|
||||
let folderKey = params.folderKey
|
||||
let storage = data.storageMap.get(storageKey)
|
||||
if (storage == null) return []
|
||||
const { data, params } = this.props
|
||||
const storageKey = params.storageKey
|
||||
const folderKey = params.folderKey
|
||||
const storage = data.storageMap.get(storageKey)
|
||||
if (storage === undefined) return []
|
||||
|
||||
let folder = _.find(storage.folders, {key: folderKey})
|
||||
if (folder == null) {
|
||||
let storageNoteSet = data.storageNoteMap
|
||||
.get(storage.key)
|
||||
if (storageNoteSet == null) storageNoteSet = []
|
||||
return storageNoteSet
|
||||
.map((uniqueKey) => data.noteMap.get(uniqueKey))
|
||||
const folder = _.find(storage.folders, {key: folderKey})
|
||||
if (folder === undefined) {
|
||||
const storageNoteSet = data.storageNoteMap.get(storage.key) || []
|
||||
return storageNoteSet.map((uniqueKey) => data.noteMap.get(uniqueKey))
|
||||
}
|
||||
|
||||
let folderNoteKeyList = data.folderNoteMap
|
||||
.get(storage.key + '-' + folder.key)
|
||||
|
||||
return folderNoteKeyList != null
|
||||
? folderNoteKeyList
|
||||
.map((uniqueKey) => data.noteMap.get(uniqueKey))
|
||||
: []
|
||||
const folderNoteKeyList = data.folderNoteMap.get(`${storage.key}-${folder.key}`) || []
|
||||
return folderNoteKeyList.map((uniqueKey) => data.noteMap.get(uniqueKey))
|
||||
}
|
||||
|
||||
handleNoteClick (e, uniqueKey) {
|
||||
|
||||
@@ -58,6 +58,7 @@ class TopBar extends React.Component {
|
||||
}
|
||||
|
||||
handleKeyUp (e) {
|
||||
const { router } = this.context
|
||||
// reset states
|
||||
this.setState({
|
||||
isConfirmTranslation: false
|
||||
@@ -68,7 +69,6 @@ class TopBar extends React.Component {
|
||||
this.setState({
|
||||
isConfirmTranslation: true
|
||||
})
|
||||
let { router } = this.context
|
||||
router.push('/searched')
|
||||
this.setState({
|
||||
search: this.refs.searchInput.value
|
||||
@@ -77,8 +77,8 @@ class TopBar extends React.Component {
|
||||
}
|
||||
|
||||
handleSearchChange (e) {
|
||||
const { router } = this.context
|
||||
if (this.state.isAlphabet || this.state.isConfirmTranslation) {
|
||||
let { router } = this.context
|
||||
router.push('/searched')
|
||||
} else {
|
||||
e.preventDefault()
|
||||
|
||||
Reference in New Issue
Block a user