diff options
author | Christoph (Sheogorath) Kern | 2018-06-30 17:05:59 +0200 |
---|---|---|
committer | GitHub | 2018-06-30 17:05:59 +0200 |
commit | 501b46f30451f61ecfcd79a121f55d2f3084048a (patch) | |
tree | d46ee1d16e0ace9a6d1f3b46f9337dd241f19972 /public/js | |
parent | 453cb19fff2cd0a63f61faae6585f676e1271f81 (diff) | |
parent | f30cc3044ac8b7f70689444cbb076be4b2cfcaac (diff) |
Merge pull request #871 from SISheogorath/update/dependencies
Update dependencies
Diffstat (limited to '')
-rw-r--r-- | public/js/history.js | 79 |
1 files changed, 20 insertions, 59 deletions
diff --git a/public/js/history.js b/public/js/history.js index 71322818..b4c26b42 100644 --- a/public/js/history.js +++ b/public/js/history.js @@ -1,5 +1,5 @@ /* eslint-env browser, jquery */ -/* global serverurl, Cookies, moment */ +/* global serverurl, moment */ import store from 'store' import S from 'string' @@ -64,13 +64,7 @@ export function saveHistory (notehistory) { } function saveHistoryToStorage (notehistory) { - if (store.enabled) { store.set('notehistory', JSON.stringify(notehistory)) } else { saveHistoryToCookie(notehistory) } -} - -function saveHistoryToCookie (notehistory) { - Cookies.set('notehistory', notehistory, { - expires: 365 - }) + store.set('notehistory', JSON.stringify(notehistory)) } function saveHistoryToServer (notehistory) { @@ -150,35 +144,17 @@ export function writeHistory (title, tags) { ) } -function writeHistoryToCookie (title, tags) { - var notehistory - try { - notehistory = Cookies.getJSON('notehistory') - } catch (err) { - notehistory = [] - } - if (!notehistory) { notehistory = [] } - const newnotehistory = generateHistory(title, tags, notehistory) - saveHistoryToCookie(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) + let data = store.get('notehistory') + let notehistory + if (data && typeof data === 'string') { + notehistory = JSON.parse(data) } else { - writeHistoryToCookie(title, tags) + notehistory = [] } + + const newnotehistory = generateHistory(title, tags, notehistory) + saveHistoryToStorage(newnotehistory) } if (!Array.isArray) { @@ -236,20 +212,13 @@ function getServerHistory (callback) { }) } -function getCookieHistory (callback) { - callback(Cookies.getJSON('notehistory')) -} - export function getStorageHistory (callback) { - if (store.enabled) { - let data = store.get('notehistory') - if (data) { - if (typeof data === 'string') { data = JSON.parse(data) } - callback(data) - } else { getCookieHistory(callback) } - } else { - getCookieHistory(callback) + let data = store.get('notehistory') + if (data) { + if (typeof data === 'string') { data = JSON.parse(data) } + callback(data) } + 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) { - if (store.enabled) { - let data = store.get('notehistory') - if (data) { - if (typeof data === 'string') { data = JSON.parse(data) } - parseToHistory(list, data, callback) - } else { parseCookieToHistory(list, callback) } - } else { - parseCookieToHistory(list, callback) + let data = store.get('notehistory') + if (data) { + if (typeof data === 'string') { data = JSON.parse(data) } + parseToHistory(list, data, callback) } + parseToHistory(list, [], callback) } function parseToHistory (list, notehistory, callback) { |