mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-10 13:32:45 +00:00
Change JSON file to JS getter function
This commit is contained in:
@@ -0,0 +1,35 @@
|
|||||||
|
|
||||||
|
const getLocalStorageMap = function(){
|
||||||
|
const localStorageMap = {
|
||||||
|
'AUTOSAVE_ON' : 'HB_editor_autoSaveOn',
|
||||||
|
'HOMEBREWERY-EDITOR-THEME' : 'HB_editor_theme',
|
||||||
|
'liveScroll' : 'HB_editor_liveScroll',
|
||||||
|
'naturalcrit-pane-split' : 'HB_editor_splitWidth',
|
||||||
|
|
||||||
|
'HOMEBREWERY-LISTPAGE-SORTDIR' : 'HB_listPage_sortDir',
|
||||||
|
'HOMEBREWERY-LISTPAGE-SORTTYPE' : 'HB_listPage_sortType',
|
||||||
|
'HOMEBREWERY-LISTPAGE-VISIBILITY-published' : 'HB_listPage_visibility_group_published',
|
||||||
|
'HOMEBREWERY-LISTPAGE-VISIBILITY-unpublished' : 'HB_listPage_visibility_group_unpublished',
|
||||||
|
|
||||||
|
'hbAdminTab' : 'HB_adminPage_currentTab',
|
||||||
|
|
||||||
|
'homebrewery-new' : 'HB_newPage_content',
|
||||||
|
'homebrewery-new-meta' : 'HB_newPage_metadata',
|
||||||
|
'homebrewery-new-style' : 'HB_newPage_style',
|
||||||
|
|
||||||
|
'homebrewery-recently-edited' : 'HB_nav_recentlyEdited',
|
||||||
|
'homebrewery-recently-viewed' : 'HB_nav_recentlyViewed',
|
||||||
|
|
||||||
|
'hb_toolbarState' : 'HB_renderer_toolbarState',
|
||||||
|
'hb_toolbarVisibility' : 'HB_renderer_toolbarVisibility'
|
||||||
|
};
|
||||||
|
|
||||||
|
if(global?.account?.username){
|
||||||
|
const username = global.account.username;
|
||||||
|
localStorageMap[`HOMEBREWERY-DEFAULT-SAVE-LOCATION-${username}`] = `HB_editor_defaultSave_${username}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return localStorageMap;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default getLocalStorageMap;
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
{
|
|
||||||
"AUTOSAVE_ON" : "HB_editor_autoSaveOn",
|
|
||||||
"HOMEBREWERY-EDITOR-THEME" : "HB_editor_theme",
|
|
||||||
"liveScroll" : "HB_editor_liveScroll",
|
|
||||||
"naturalcrit-pane-split" : "HB_editor_splitWidth",
|
|
||||||
|
|
||||||
"HOMEBREWERY-LISTPAGE-SORTDIR" : "HB_listPage_sortDir",
|
|
||||||
"HOMEBREWERY-LISTPAGE-SORTTYPE" : "HB_listPage_sortType",
|
|
||||||
"HOMEBREWERY-LISTPAGE-VISIBILITY-published" : "HB_listPage_visibility_group_published",
|
|
||||||
"HOMEBREWERY-LISTPAGE-VISIBILITY-unpublished" : "HB_listPage_visibility_group_unpublished",
|
|
||||||
|
|
||||||
"hbAdminTab" : "HB_adminPage_currentTab",
|
|
||||||
|
|
||||||
"homebrewery-new" : "HB_newPage_content",
|
|
||||||
"homebrewery-new-meta" : "HB_newPage_metadata",
|
|
||||||
"homebrewery-new-style" : "HB_newPage_style",
|
|
||||||
|
|
||||||
"homebrewery-recently-edited" : "HB_nav_recentlyEdited",
|
|
||||||
"homebrewery-recently-viewed" : "HB_nav_recentlyViewed",
|
|
||||||
|
|
||||||
"hb_toolbarState" : "HB_renderer_toolbarState",
|
|
||||||
"hb_toolbarVisibility" : "HB_renderer_toolbarVisibility"
|
|
||||||
}
|
|
||||||
@@ -1,29 +1,19 @@
|
|||||||
import localStorageKeyMap from './localStorageKeyMap.json' with { type: 'json' };
|
import getLocalStorageMap from './localStorageKeyMap.js';
|
||||||
|
|
||||||
const addDynamicKeys = function(keyObject){
|
|
||||||
|
|
||||||
if(global?.account?.username){
|
|
||||||
const username = global.account.username;
|
|
||||||
keyObject[`HOMEBREWERY-DEFAULT-SAVE-LOCATION-${username}`] = `HB_editor_defaultSave_${username}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return keyObject;
|
|
||||||
};
|
|
||||||
|
|
||||||
const updateLocalStorage = function(){
|
const updateLocalStorage = function(){
|
||||||
// Return if no window and thus no local storage
|
// Return if no window and thus no local storage
|
||||||
if(typeof window === 'undefined') return;
|
if(typeof window === 'undefined') return;
|
||||||
|
|
||||||
// Return if the local storage key map has no content
|
// Return if the local storage key map has no content
|
||||||
|
const localStorageKeyMap = getLocalStorageMap();
|
||||||
if(Object.keys(localStorageKeyMap).length == 0) return;
|
if(Object.keys(localStorageKeyMap).length == 0) return;
|
||||||
|
|
||||||
const storage = window.localStorage;
|
const storage = window.localStorage;
|
||||||
const storageKeyMap = addDynamicKeys(localStorageKeyMap);
|
|
||||||
|
|
||||||
Object.keys(storageKeyMap).forEach((key)=>{
|
Object.keys(localStorageKeyMap).forEach((key)=>{
|
||||||
if(storage[key]){
|
if(storage[key]){
|
||||||
const data = storage.getItem(key);
|
const data = storage.getItem(key);
|
||||||
if(!storage[storageKeyMap[key]]) storage.setItem(storageKeyMap[key], data);
|
if(!storage[localStorageKeyMap[key]]) storage.setItem(localStorageKeyMap[key], data);
|
||||||
// storage.removeItem(key);
|
// storage.removeItem(key);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user