Skip to content

Commit dea62cf

Browse files
committed
Update store
Signed-off-by: Sheogorath <sheogorath@shivering-isles.com>
1 parent 1812b1a commit dea62cf

2 files changed

Lines changed: 21 additions & 60 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
"socket.io-client": "~2.0.4",
120120
"spin.js": "^2.3.2",
121121
"sqlite3": "^4.0.1",
122-
"store": "^1.3.20",
122+
"store": "^2.0.12",
123123
"string": "^3.3.3",
124124
"tedious": "^1.14.0",
125125
"to-markdown": "^3.0.3",

public/js/history.js

Lines changed: 20 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-env browser, jquery */
2-
/* global serverurl, Cookies, moment */
2+
/* global serverurl, moment */
33

44
import store from 'store'
55
import S from 'string'
@@ -64,13 +64,7 @@ export function saveHistory (notehistory) {
6464
}
6565

6666
function saveHistoryToStorage (notehistory) {
67-
if (store.enabled) { store.set('notehistory', JSON.stringify(notehistory)) } else { saveHistoryToCookie(notehistory) }
68-
}
69-
70-
function saveHistoryToCookie (notehistory) {
71-
Cookies.set('notehistory', notehistory, {
72-
expires: 365
73-
})
67+
store.set('notehistory', JSON.stringify(notehistory))
7468
}
7569

7670
function saveHistoryToServer (notehistory) {
@@ -150,35 +144,17 @@ export function writeHistory (title, tags) {
150144
)
151145
}
152146

153-
function writeHistoryToCookie (title, tags) {
154-
var notehistory
155-
try {
156-
notehistory = Cookies.getJSON('notehistory')
157-
} catch (err) {
158-
notehistory = []
159-
}
160-
if (!notehistory) { notehistory = [] }
161-
const newnotehistory = generateHistory(title, tags, notehistory)
162-
saveHistoryToCookie(newnotehistory)
163-
}
164-
165147
function writeHistoryToStorage (title, tags) {
166-
if (store.enabled) {
167-
let data = store.get('notehistory')
168-
var notehistory
169-
if (data) {
170-
if (typeof data === 'string') { data = JSON.parse(data) }
171-
notehistory = data
172-
} else {
173-
notehistory = []
174-
}
175-
if (!notehistory) { notehistory = [] }
176-
177-
const newnotehistory = generateHistory(title, tags, notehistory)
178-
saveHistoryToStorage(newnotehistory)
148+
let data = store.get('notehistory')
149+
let notehistory
150+
if (data && typeof data === 'string') {
151+
notehistory = JSON.parse(data)
179152
} else {
180-
writeHistoryToCookie(title, tags)
153+
notehistory = []
181154
}
155+
156+
const newnotehistory = generateHistory(title, tags, notehistory)
157+
saveHistoryToStorage(newnotehistory)
182158
}
183159

184160
if (!Array.isArray) {
@@ -236,20 +212,13 @@ function getServerHistory (callback) {
236212
})
237213
}
238214

239-
function getCookieHistory (callback) {
240-
callback(Cookies.getJSON('notehistory'))
241-
}
242-
243215
export function getStorageHistory (callback) {
244-
if (store.enabled) {
245-
let data = store.get('notehistory')
246-
if (data) {
247-
if (typeof data === 'string') { data = JSON.parse(data) }
248-
callback(data)
249-
} else { getCookieHistory(callback) }
250-
} else {
251-
getCookieHistory(callback)
216+
let data = store.get('notehistory')
217+
if (data) {
218+
if (typeof data === 'string') { data = JSON.parse(data) }
219+
callback(data)
252220
}
221+
callback([])
253222
}
254223

255224
export function parseHistory (list, callback) {
@@ -275,21 +244,13 @@ export function parseServerToHistory (list, callback) {
275244
})
276245
}
277246

278-
function parseCookieToHistory (list, callback) {
279-
const notehistory = Cookies.getJSON('notehistory')
280-
parseToHistory(list, notehistory, callback)
281-
}
282-
283247
export function parseStorageToHistory (list, callback) {
284-
if (store.enabled) {
285-
let data = store.get('notehistory')
286-
if (data) {
287-
if (typeof data === 'string') { data = JSON.parse(data) }
288-
parseToHistory(list, data, callback)
289-
} else { parseCookieToHistory(list, callback) }
290-
} else {
291-
parseCookieToHistory(list, callback)
248+
let data = store.get('notehistory')
249+
if (data) {
250+
if (typeof data === 'string') { data = JSON.parse(data) }
251+
parseToHistory(list, data, callback)
292252
}
253+
parseToHistory(list, [], callback)
293254
}
294255

295256
function parseToHistory (list, notehistory, callback) {

0 commit comments

Comments
 (0)