mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-15 18:56:22 +00:00
Change contextNotes a state to a variable because of lifesycle loop
This commit is contained in:
@@ -51,8 +51,9 @@ class NoteList extends React.Component {
|
|||||||
this.jumpNoteByHash = this.jumpNoteByHashHandler.bind(this)
|
this.jumpNoteByHash = this.jumpNoteByHashHandler.bind(this)
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
contextNotes: []
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.contextNotes = []
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
@@ -91,7 +92,8 @@ 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.setState({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: {
|
||||||
@@ -236,6 +238,7 @@ class NoteList extends React.Component {
|
|||||||
let { router } = this.context
|
let { router } = this.context
|
||||||
|
|
||||||
if (location.pathname.match(/\/home/)) {
|
if (location.pathname.match(/\/home/)) {
|
||||||
|
this.contextNotes = data.noteMap.map((note) => note)
|
||||||
return data.noteMap.map((note) => note)
|
return data.noteMap.map((note) => note)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,9 +250,9 @@ class NoteList extends React.Component {
|
|||||||
if (location.pathname.match(/\/searched/)) {
|
if (location.pathname.match(/\/searched/)) {
|
||||||
const searchInputText = document.getElementsByClassName('searchInput')[0].value
|
const searchInputText = document.getElementsByClassName('searchInput')[0].value
|
||||||
if (searchInputText === '') {
|
if (searchInputText === '') {
|
||||||
return this.state.contextNotes
|
return this.contextNotes
|
||||||
}
|
}
|
||||||
return searchFromNotes(this.state.contextNotes, searchInputText)
|
return searchFromNotes(this.contextNotes, searchInputText)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (location.pathname.match(/\/trashed/)) {
|
if (location.pathname.match(/\/trashed/)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user