@@ -50,36 +50,10 @@ const localStorageRemove = (key) => {
5050 }
5151} ;
5252
53- const getSet = ( ALL_GRAPHS ) => {
54- if ( ! localStorageGet ( ALL_GRAPHS ) ) {
55- localStorageSet ( ALL_GRAPHS , encodeBase64 ( JSON . stringify ( [ ] ) ) ) ;
56- }
57- const raw = localStorageGet ( ALL_GRAPHS ) ;
58- if ( ! raw ) return new Set ( ) ;
59- const parsed = parseStoredJson ( raw ) ;
60- if ( ! Array . isArray ( parsed ) ) {
61- localStorageSet ( ALL_GRAPHS , encodeBase64 ( JSON . stringify ( [ ] ) ) ) ;
62- return new Set ( ) ;
63- }
64- return new Set ( parsed ) ;
65- } ;
66-
6753const localStorageManager = {
6854 ALL_GRAPHS : window . btoa ( 'ALL_GRAPHS' ) ,
6955 AUTHOR_NAME : window . btoa ( 'AUTHOR_NAME' ) ,
7056
71- allgs : getSet ( window . btoa ( 'ALL_GRAPHS' ) ) ,
72-
73- saveAllgs ( ) {
74- localStorageSet ( this . ALL_GRAPHS , encodeBase64 ( JSON . stringify ( Array . from ( this . allgs ) ) ) ) ;
75- } ,
76-
77- addEmptyIfNot ( ) {
78- if ( ! localStorageGet ( this . ALL_GRAPHS ) ) {
79- localStorageSet ( this . ALL_GRAPHS , encodeBase64 ( JSON . stringify ( [ ] ) ) ) ;
80- }
81- } ,
82-
8357 get ( id ) {
8458 const raw = localStorageGet ( id ) ;
8559 if ( raw === null ) return null ;
@@ -100,13 +74,15 @@ const localStorageManager = {
10074 }
10175 } ,
10276 remove ( id ) {
103- if ( this . allgs . delete ( id ) ) this . saveAllgs ( ) ;
77+ const list = this . getAllGraphs ( ) . filter ( ( g ) => g !== id ) ;
78+ localStorageSet ( this . ALL_GRAPHS , encodeBase64 ( JSON . stringify ( list ) ) ) ;
10479 localStorageRemove ( id ) ;
10580 } ,
10681 addGraph ( id ) {
107- if ( this . allgs . has ( id ) ) return ;
108- this . allgs . add ( id ) ;
109- this . saveAllgs ( ) ;
82+ const list = this . getAllGraphs ( ) ;
83+ if ( list . includes ( id ) ) return ;
84+ list . push ( id ) ;
85+ localStorageSet ( this . ALL_GRAPHS , encodeBase64 ( JSON . stringify ( list ) ) ) ;
11086 } ,
11187 getAllGraphs ( ) {
11288 const raw = localStorageGet ( this . ALL_GRAPHS ) ;
@@ -119,17 +95,10 @@ const localStorageManager = {
11995 return parsed ;
12096 } ,
12197 addToFront ( id ) {
122- if ( this . allgs . has ( id ) ) return ;
123- this . allgs . add ( id ) ;
124- const raw = localStorageGet ( this . ALL_GRAPHS ) ;
125- if ( ! raw ) return ;
126- const Garr = parseStoredJson ( raw ) ;
127- if ( ! Array . isArray ( Garr ) ) {
128- this . saveAllgs ( ) ;
129- return ;
130- }
131- Garr . unshift ( id ) ;
132- localStorageSet ( this . ALL_GRAPHS , encodeBase64 ( JSON . stringify ( Garr ) ) ) ;
98+ const list = this . getAllGraphs ( ) ;
99+ if ( list . includes ( id ) ) return ;
100+ list . unshift ( id ) ;
101+ localStorageSet ( this . ALL_GRAPHS , encodeBase64 ( JSON . stringify ( list ) ) ) ;
133102 } ,
134103 getAuthorName ( ) {
135104 return localStorageGet ( this . AUTHOR_NAME ) || '' ;
0 commit comments