11import { toast } from 'react-toastify' ;
22
3- const lsGet = ( key ) => {
3+ const localStorageGet = ( key ) => {
44 try {
55 return window . localStorage . getItem ( key ) ;
66 } catch ( e ) {
@@ -9,15 +9,15 @@ const lsGet = (key) => {
99 }
1010} ;
1111
12- const lsSet = ( key , value ) => {
12+ const localStorageSet = ( key , value ) => {
1313 try {
1414 window . localStorage . setItem ( key , value ) ;
1515 } catch ( e ) {
1616 toast . error ( e . message ) ;
1717 }
1818} ;
1919
20- const lsRemove = ( key ) => {
20+ const localStorageRemove = ( key ) => {
2121 try {
2222 window . localStorage . removeItem ( key ) ;
2323 } catch ( e ) {
@@ -26,10 +26,10 @@ const lsRemove = (key) => {
2626} ;
2727
2828const getSet = ( ALL_GRAPHS ) => {
29- if ( ! lsGet ( ALL_GRAPHS ) ) {
30- lsSet ( ALL_GRAPHS , window . btoa ( JSON . stringify ( [ ] ) ) ) ;
29+ if ( ! localStorageGet ( ALL_GRAPHS ) ) {
30+ localStorageSet ( ALL_GRAPHS , window . btoa ( JSON . stringify ( [ ] ) ) ) ;
3131 }
32- const raw = lsGet ( ALL_GRAPHS ) ;
32+ const raw = localStorageGet ( ALL_GRAPHS ) ;
3333 if ( ! raw ) return new Set ( ) ;
3434 return new Set ( JSON . parse ( window . atob ( raw ) ) ) ;
3535} ;
@@ -41,59 +41,59 @@ const localStorageManager = {
4141 allgs : getSet ( window . btoa ( 'ALL_GRAPHS' ) ) ,
4242
4343 saveAllgs ( ) {
44- lsSet ( this . ALL_GRAPHS , window . btoa ( JSON . stringify ( Array . from ( this . allgs ) ) ) ) ;
44+ localStorageSet ( this . ALL_GRAPHS , window . btoa ( JSON . stringify ( Array . from ( this . allgs ) ) ) ) ;
4545 } ,
4646
4747 addEmptyIfNot ( ) {
48- if ( ! lsGet ( this . ALL_GRAPHS ) ) {
49- lsSet ( this . ALL_GRAPHS , window . btoa ( JSON . stringify ( [ ] ) ) ) ;
48+ if ( ! localStorageGet ( this . ALL_GRAPHS ) ) {
49+ localStorageSet ( this . ALL_GRAPHS , window . btoa ( JSON . stringify ( [ ] ) ) ) ;
5050 }
5151 } ,
5252
5353 get ( id ) {
54- const raw = lsGet ( id ) ;
54+ const raw = localStorageGet ( id ) ;
5555 if ( raw === null ) return null ;
5656 return JSON . parse ( window . atob ( raw ) ) ;
5757 } ,
5858 save ( id , graphContent ) {
5959 this . addGraph ( id ) ;
6060 const serializedJson = JSON . stringify ( graphContent ) ;
61- lsSet ( id , window . btoa ( serializedJson ) ) ;
61+ localStorageSet ( id , window . btoa ( serializedJson ) ) ;
6262 } ,
6363 remove ( id ) {
6464 if ( this . allgs . delete ( id ) ) this . saveAllgs ( ) ;
65- lsRemove ( id ) ;
65+ localStorageRemove ( id ) ;
6666 } ,
6767 addGraph ( id ) {
6868 if ( this . allgs . has ( id ) ) return ;
6969 this . allgs . add ( id ) ;
7070 this . saveAllgs ( ) ;
7171 } ,
7272 getAllGraphs ( ) {
73- const raw = lsGet ( this . ALL_GRAPHS ) ;
73+ const raw = localStorageGet ( this . ALL_GRAPHS ) ;
7474 if ( ! raw ) return [ ] ;
7575 return JSON . parse ( window . atob ( raw ) ) ;
7676 } ,
7777 addToFront ( id ) {
7878 if ( this . allgs . has ( id ) ) return ;
7979 this . allgs . add ( id ) ;
80- const raw = lsGet ( this . ALL_GRAPHS ) ;
80+ const raw = localStorageGet ( this . ALL_GRAPHS ) ;
8181 if ( ! raw ) return ;
8282 const Garr = JSON . parse ( window . atob ( raw ) ) ;
8383 Garr . unshift ( id ) ;
84- lsSet ( this . ALL_GRAPHS , window . btoa ( JSON . stringify ( Garr ) ) ) ;
84+ localStorageSet ( this . ALL_GRAPHS , window . btoa ( JSON . stringify ( Garr ) ) ) ;
8585 } ,
8686 getAuthorName ( ) {
87- return lsGet ( this . AUTHOR_NAME ) || '' ;
87+ return localStorageGet ( this . AUTHOR_NAME ) || '' ;
8888 } ,
8989 setAuthorName ( authorName ) {
90- lsSet ( this . AUTHOR_NAME , authorName ) ;
90+ localStorageSet ( this . AUTHOR_NAME , authorName ) ;
9191 } ,
9292 clearGraph ( id ) {
93- lsRemove ( id ) ;
93+ localStorageRemove ( id ) ;
9494 } ,
9595 getFileList ( ) {
96- return lsGet ( 'fileList' ) || '' ;
96+ return localStorageGet ( 'fileList' ) || '' ;
9797 } ,
9898} ;
9999export default localStorageManager ;
0 commit comments