mirror of https://github.com/status-im/codimd.git
Update store
Signed-off-by: Sheogorath <sheogorath@shivering-isles.com>
This commit is contained in:
parent
1812b1aaca
commit
dea62cf310
|
@ -119,7 +119,7 @@
|
||||||
"socket.io-client": "~2.0.4",
|
"socket.io-client": "~2.0.4",
|
||||||
"spin.js": "^2.3.2",
|
"spin.js": "^2.3.2",
|
||||||
"sqlite3": "^4.0.1",
|
"sqlite3": "^4.0.1",
|
||||||
"store": "^1.3.20",
|
"store": "^2.0.12",
|
||||||
"string": "^3.3.3",
|
"string": "^3.3.3",
|
||||||
"tedious": "^1.14.0",
|
"tedious": "^1.14.0",
|
||||||
"to-markdown": "^3.0.3",
|
"to-markdown": "^3.0.3",
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* eslint-env browser, jquery */
|
/* eslint-env browser, jquery */
|
||||||
/* global serverurl, Cookies, moment */
|
/* global serverurl, moment */
|
||||||
|
|
||||||
import store from 'store'
|
import store from 'store'
|
||||||
import S from 'string'
|
import S from 'string'
|
||||||
|
@ -64,13 +64,7 @@ export function saveHistory (notehistory) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveHistoryToStorage (notehistory) {
|
function saveHistoryToStorage (notehistory) {
|
||||||
if (store.enabled) { store.set('notehistory', JSON.stringify(notehistory)) } else { saveHistoryToCookie(notehistory) }
|
store.set('notehistory', JSON.stringify(notehistory))
|
||||||
}
|
|
||||||
|
|
||||||
function saveHistoryToCookie (notehistory) {
|
|
||||||
Cookies.set('notehistory', notehistory, {
|
|
||||||
expires: 365
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveHistoryToServer (notehistory) {
|
function saveHistoryToServer (notehistory) {
|
||||||
|
@ -150,35 +144,17 @@ export function writeHistory (title, tags) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function writeHistoryToCookie (title, tags) {
|
function writeHistoryToStorage (title, tags) {
|
||||||
var notehistory
|
let data = store.get('notehistory')
|
||||||
try {
|
let notehistory
|
||||||
notehistory = Cookies.getJSON('notehistory')
|
if (data && typeof data === 'string') {
|
||||||
} catch (err) {
|
notehistory = JSON.parse(data)
|
||||||
|
} else {
|
||||||
notehistory = []
|
notehistory = []
|
||||||
}
|
}
|
||||||
if (!notehistory) { notehistory = [] }
|
|
||||||
const newnotehistory = generateHistory(title, tags, notehistory)
|
const newnotehistory = generateHistory(title, tags, notehistory)
|
||||||
saveHistoryToCookie(newnotehistory)
|
saveHistoryToStorage(newnotehistory)
|
||||||
}
|
|
||||||
|
|
||||||
function writeHistoryToStorage (title, tags) {
|
|
||||||
if (store.enabled) {
|
|
||||||
let data = store.get('notehistory')
|
|
||||||
var notehistory
|
|
||||||
if (data) {
|
|
||||||
if (typeof data === 'string') { data = JSON.parse(data) }
|
|
||||||
notehistory = data
|
|
||||||
} else {
|
|
||||||
notehistory = []
|
|
||||||
}
|
|
||||||
if (!notehistory) { notehistory = [] }
|
|
||||||
|
|
||||||
const newnotehistory = generateHistory(title, tags, notehistory)
|
|
||||||
saveHistoryToStorage(newnotehistory)
|
|
||||||
} else {
|
|
||||||
writeHistoryToCookie(title, tags)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Array.isArray) {
|
if (!Array.isArray) {
|
||||||
|
@ -236,20 +212,13 @@ function getServerHistory (callback) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCookieHistory (callback) {
|
|
||||||
callback(Cookies.getJSON('notehistory'))
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getStorageHistory (callback) {
|
export function getStorageHistory (callback) {
|
||||||
if (store.enabled) {
|
let data = store.get('notehistory')
|
||||||
let data = store.get('notehistory')
|
if (data) {
|
||||||
if (data) {
|
if (typeof data === 'string') { data = JSON.parse(data) }
|
||||||
if (typeof data === 'string') { data = JSON.parse(data) }
|
callback(data)
|
||||||
callback(data)
|
|
||||||
} else { getCookieHistory(callback) }
|
|
||||||
} else {
|
|
||||||
getCookieHistory(callback)
|
|
||||||
}
|
}
|
||||||
|
callback([])
|
||||||
}
|
}
|
||||||
|
|
||||||
export function parseHistory (list, callback) {
|
export function parseHistory (list, callback) {
|
||||||
|
@ -275,21 +244,13 @@ export function parseServerToHistory (list, callback) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseCookieToHistory (list, callback) {
|
|
||||||
const notehistory = Cookies.getJSON('notehistory')
|
|
||||||
parseToHistory(list, notehistory, callback)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function parseStorageToHistory (list, callback) {
|
export function parseStorageToHistory (list, callback) {
|
||||||
if (store.enabled) {
|
let data = store.get('notehistory')
|
||||||
let data = store.get('notehistory')
|
if (data) {
|
||||||
if (data) {
|
if (typeof data === 'string') { data = JSON.parse(data) }
|
||||||
if (typeof data === 'string') { data = JSON.parse(data) }
|
parseToHistory(list, data, callback)
|
||||||
parseToHistory(list, data, callback)
|
|
||||||
} else { parseCookieToHistory(list, callback) }
|
|
||||||
} else {
|
|
||||||
parseCookieToHistory(list, callback)
|
|
||||||
}
|
}
|
||||||
|
parseToHistory(list, [], callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseToHistory (list, notehistory, callback) {
|
function parseToHistory (list, notehistory, callback) {
|
||||||
|
|
Loading…
Reference in New Issue