@@ -76,37 +76,39 @@ export const rawLabels = async (repos, dispatch) => {
7676 return rawdata ;
7777} ;
7878
79- export const getLabels = ( repos ) => async ( dispatch , getState ) => {
79+ export const getLabels = ( repos , language ) => async ( dispatch , getState ) => {
8080 if ( repos === undefined ) return ;
8181 dispatch ( {
8282 type : label . GET_LABELS_REQUEST ,
8383 loadingPercentage : 0
8484 } ) ;
8585 try {
8686 // get date for list of labels, saved in browser's local strorage
87- const localDataDate = localStorage . getItem ( 'date' ) ;
87+ const localStorageObj = JSON . parse ( localStorage . getItem ( language + '_labelslist' ) ) ;
88+ const localDataDate = localStorageObj ?. date ;
8889 let today = new Date ( ) ;
8990 const dd = String ( today . getDate ( ) ) . padStart ( 2 , '0' ) ;
9091 const mm = String ( today . getMonth ( ) + 1 ) . padStart ( 2 , '0' ) ;
9192 const yyyy = today . getFullYear ( ) ;
9293 today = ( mm + dd + yyyy ) . toString ( ) ;
9394 // if date, when data was saved, is more than a day, clear it.
9495 if ( localDataDate !== today ) {
95- localStorage . removeItem ( 'labelslist' ) ;
96- localStorage . removeItem ( 'date' ) ;
96+ localStorage . removeItem ( language + '_labelslist' ) ;
9797 }
9898
9999 // get label list from local storage
100- const localData = localStorage . getItem ( 'labelslist' ) ;
100+ const localData = localStorageObj ?. labels ;
101101 let data = '' ;
102- if ( localData ) data = JSON . parse ( localData ) ;
102+ if ( localData ) data = localData ;
103103 else data = await rawLabels ( repos , dispatch ) ; // if label list is not present in local storage than get fresh list of labels.
104104 dispatch ( {
105105 type : label . GET_LABELS_SUCCESS ,
106106 payload : data
107107 } ) ;
108- localStorage . setItem ( 'labelslist' , JSON . stringify ( getState ( ) . labelsStore . labelslist ) ) ;
109- localStorage . setItem ( 'date' , today ) ;
108+ localStorage . setItem (
109+ language + '_labelslist' ,
110+ JSON . stringify ( { language : language , date : today , labels : getState ( ) . labelsStore . labelslist } )
111+ ) ;
110112 } catch ( e ) {
111113 console . error ( `getlabels error ${ e . message } ` ) ;
112114 dispatch ( {
0 commit comments