11/* eslint-env browser, jquery */
2- /* global serverurl, Cookies, moment */
2+ /* global serverurl, moment */
33
44import store from 'store'
55import S from 'string'
@@ -64,13 +64,7 @@ export function saveHistory (notehistory) {
6464}
6565
6666function 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
7670function 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-
165147function 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
184160if ( ! Array . isArray ) {
@@ -236,20 +212,13 @@ function getServerHistory (callback) {
236212 } )
237213}
238214
239- function getCookieHistory ( callback ) {
240- callback ( Cookies . getJSON ( 'notehistory' ) )
241- }
242-
243215export 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
255224export 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-
283247export 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
295256function parseToHistory ( list , notehistory , callback ) {
0 commit comments