mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
dataStore bug fix
This commit is contained in:
@@ -121,7 +121,7 @@ class FinderMain extends React.Component {
|
|||||||
let { articles, activeArticle, status, dispatch } = this.props
|
let { articles, activeArticle, status, dispatch } = this.props
|
||||||
let saveToClipboard = () => this.saveToClipboard()
|
let saveToClipboard = () => this.saveToClipboard()
|
||||||
return (
|
return (
|
||||||
<div onClick={e => this.handleClick(e)} className='Finder'>
|
<div className='Finder'>
|
||||||
<FinderInput
|
<FinderInput
|
||||||
handleSearchChange={e => this.handleSearchChange(e)}
|
handleSearchChange={e => this.handleSearchChange(e)}
|
||||||
ref='finderInput'
|
ref='finderInput'
|
||||||
@@ -243,7 +243,7 @@ var Finder = connect(remap)(FinderMain)
|
|||||||
var store = createStore(reducer)
|
var store = createStore(reducer)
|
||||||
|
|
||||||
function refreshData () {
|
function refreshData () {
|
||||||
let data = dataStore.getData()
|
let data = dataStore.getData(true)
|
||||||
store.dispatch(actions.refreshData(data))
|
store.dispatch(actions.refreshData(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -71,19 +71,8 @@ export function saveUser (repoName, user) {
|
|||||||
export function init () {
|
export function init () {
|
||||||
// set repositories info
|
// set repositories info
|
||||||
getRepositories()
|
getRepositories()
|
||||||
|
data = jetpack.read(getLocalPath(), 'json')
|
||||||
data = getData()
|
|
||||||
|
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
// for 0.4.1 -> 0.4.2
|
|
||||||
if (localStorage.getItem('local') != null) {
|
|
||||||
data = JSON.parse(localStorage.getItem('local'))
|
|
||||||
jetpack.write(getLocalPath(), data)
|
|
||||||
localStorage.removeItem('local')
|
|
||||||
console.log('update 0.4.1 => 0.4.2')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
let defaultFolder = {
|
let defaultFolder = {
|
||||||
name: 'default',
|
name: 'default',
|
||||||
key: keygen()
|
key: keygen()
|
||||||
@@ -108,14 +97,11 @@ export function init () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getData () {
|
export function getData (forceRead) {
|
||||||
if (data == null) {
|
if (forceRead) {
|
||||||
try {
|
try {
|
||||||
data = jetpack.read(getLocalPath(), 'json')
|
data = jetpack.read(getLocalPath(), 'json')
|
||||||
|
} catch (e) {}
|
||||||
} catch (e) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
@@ -140,7 +126,7 @@ function queueSave () {
|
|||||||
if (timer) {
|
if (timer) {
|
||||||
clearTimeout(timer)
|
clearTimeout(timer)
|
||||||
}
|
}
|
||||||
timer = setTimeout(saveData, 3000)
|
timer = setTimeout(saveData, 500)
|
||||||
} else {
|
} else {
|
||||||
saveAgain = true
|
saveAgain = true
|
||||||
}
|
}
|
||||||
@@ -160,21 +146,11 @@ export function setFolders (folders) {
|
|||||||
queueSave()
|
queueSave()
|
||||||
}
|
}
|
||||||
|
|
||||||
function isFinderCalled () {
|
export default {
|
||||||
var argv = process.argv.slice(1)
|
getUser,
|
||||||
return argv.some(arg => arg.match(/--finder/))
|
saveUser,
|
||||||
|
init,
|
||||||
|
getData,
|
||||||
|
setArticles,
|
||||||
|
setFolders
|
||||||
}
|
}
|
||||||
|
|
||||||
export default (function () {
|
|
||||||
if (!isFinderCalled()) {
|
|
||||||
init()
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
getUser,
|
|
||||||
saveUser,
|
|
||||||
init,
|
|
||||||
getData,
|
|
||||||
setArticles,
|
|
||||||
setFolders
|
|
||||||
}
|
|
||||||
})()
|
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ const initialStatus = {
|
|||||||
isTutorialOpen: false
|
isTutorialOpen: false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dataStore.init()
|
||||||
let data = dataStore.getData()
|
let data = dataStore.getData()
|
||||||
let initialArticles = {
|
let initialArticles = {
|
||||||
data: data && data.articles ? data.articles : [],
|
data: data && data.articles ? data.articles : [],
|
||||||
|
|||||||
Reference in New Issue
Block a user