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