diff --git a/client/homebrew/homebrew.jsx b/client/homebrew/homebrew.jsx index a6b4b9175..1aff5067d 100644 --- a/client/homebrew/homebrew.jsx +++ b/client/homebrew/homebrew.jsx @@ -4,6 +4,8 @@ import './homebrew.less'; import React from 'react'; import { StaticRouter as Router, Route, Routes, useParams, useSearchParams } from 'react-router'; +import { updateLocalStorage } from './utils/updateLocalStorage/updateLocalStorageKeys.js'; + import HomePage from './pages/homePage/homePage.jsx'; import EditPage from './pages/editPage/editPage.jsx'; import UserPage from './pages/userPage/userPage.jsx'; @@ -48,6 +50,8 @@ const Homebrew = (props)=>{ global.enable_themes = enable_themes; global.config = config; + updateLocalStorage(); + return (
diff --git a/client/homebrew/utils/updateLocalStorage/localStorageKeyMap.json b/client/homebrew/utils/updateLocalStorage/localStorageKeyMap.json new file mode 100644 index 000000000..d8b4d1268 --- /dev/null +++ b/client/homebrew/utils/updateLocalStorage/localStorageKeyMap.json @@ -0,0 +1,19 @@ +{ + "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" : "HB_listPage_visibility_group", + "dismiss_notif_drive" : "HB_dismissNotif_drive", + "dismiss_notif_faq" : "HB_dismissNotif_faq", + "dismiss_notif_update_v3.18" : "HB_dismissNotif_update_v3.18", + "dismiss_v134 update" : "HB_dismissNotif_update_v134", + "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" +} \ No newline at end of file diff --git a/client/homebrew/utils/updateLocalStorage/updateLocalStorageKeys.js b/client/homebrew/utils/updateLocalStorage/updateLocalStorageKeys.js new file mode 100644 index 000000000..02471387d --- /dev/null +++ b/client/homebrew/utils/updateLocalStorage/updateLocalStorageKeys.js @@ -0,0 +1,22 @@ +import localStorageKeyMap from './localStorageKeyMap.json' with { type: 'json' }; + +const updateLocalStorage = function(){ + // Return if no window and thus no local storage + if(typeof window === 'undefined') return; + + // Return if the local storage key map has no content + if(Object.keys(localStorageKeyMap).length == 0) return; + + const storage = window.localStorage; + + Object.keys(localStorageKeyMap).forEach((key)=>{ + if(storage[key]){ + const data = storage.getItem(key); + storage.setItem(localStorageKeyMap[key], data); + // storage.removeItem(key); + } + }); + +}; + +export { updateLocalStorage }; \ No newline at end of file