From 1eb5b6d3a4948ecce5eb3b26129df25c872b1d7a Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Tue, 9 Sep 2025 22:04:40 +1200 Subject: [PATCH 01/21] Copy exisitng key data to new keys --- client/homebrew/homebrew.jsx | 4 ++++ .../localStorageKeyMap.json | 19 ++++++++++++++++ .../updateLocalStorageKeys.js | 22 +++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 client/homebrew/utils/updateLocalStorage/localStorageKeyMap.json create mode 100644 client/homebrew/utils/updateLocalStorage/updateLocalStorageKeys.js 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 From 08d228831d362b579742b0e5f3ade13aad5c3794 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Wed, 10 Sep 2025 18:53:23 +1200 Subject: [PATCH 02/21] Add missing keys to JSON, tweak layout --- .../localStorageKeyMap.json | 43 +++++++++++-------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/client/homebrew/utils/updateLocalStorage/localStorageKeyMap.json b/client/homebrew/utils/updateLocalStorage/localStorageKeyMap.json index d8b4d1268..b880bfa0c 100644 --- a/client/homebrew/utils/updateLocalStorage/localStorageKeyMap.json +++ b/client/homebrew/utils/updateLocalStorage/localStorageKeyMap.json @@ -1,19 +1,28 @@ { - "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" + "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", + + "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", + + "hb_toolbarState" : "HB_renderer_toolbarState", + "hb_toolbarVisibility" : "HB_renderer_toolbarVisibility" } \ No newline at end of file From 7163b1a2873bab9e1ef7d1ed40890315d1333410 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Wed, 10 Sep 2025 18:53:53 +1200 Subject: [PATCH 03/21] Add function to add dynamic keys to local storage map --- .../updateLocalStorage/updateLocalStorageKeys.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/client/homebrew/utils/updateLocalStorage/updateLocalStorageKeys.js b/client/homebrew/utils/updateLocalStorage/updateLocalStorageKeys.js index 02471387d..dae2580f4 100644 --- a/client/homebrew/utils/updateLocalStorage/updateLocalStorageKeys.js +++ b/client/homebrew/utils/updateLocalStorage/updateLocalStorageKeys.js @@ -1,5 +1,15 @@ import localStorageKeyMap from './localStorageKeyMap.json' with { type: 'json' }; +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(){ // Return if no window and thus no local storage if(typeof window === 'undefined') return; @@ -8,11 +18,12 @@ const updateLocalStorage = function(){ if(Object.keys(localStorageKeyMap).length == 0) return; const storage = window.localStorage; + const storageKeyMap = addDynamicKeys(localStorageKeyMap); - Object.keys(localStorageKeyMap).forEach((key)=>{ + Object.keys(storageKeyMap).forEach((key)=>{ if(storage[key]){ const data = storage.getItem(key); - storage.setItem(localStorageKeyMap[key], data); + storage.setItem(storageKeyMap[key], data); // storage.removeItem(key); } }); From c99f59d42b1e8c7ae6e02e99b206bc02bcd76837 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Wed, 10 Sep 2025 19:08:47 +1200 Subject: [PATCH 04/21] Update newPage.jsx keys --- client/homebrew/pages/newPage/newPage.jsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/client/homebrew/pages/newPage/newPage.jsx b/client/homebrew/pages/newPage/newPage.jsx index bb21441cf..67ff227ae 100644 --- a/client/homebrew/pages/newPage/newPage.jsx +++ b/client/homebrew/pages/newPage/newPage.jsx @@ -20,10 +20,10 @@ import BrewRenderer from '../../brewRenderer/brewRenderer.jsx'; import { DEFAULT_BREW } from '../../../../server/brewDefaults.js'; import { printCurrentBrew, fetchThemeBundle, splitTextStyleAndMetadata } from '../../../../shared/helpers.js'; -const BREWKEY = 'homebrewery-new'; -const STYLEKEY = 'homebrewery-new-style'; -const METAKEY = 'homebrewery-new-meta'; -const SAVEKEY = `HOMEBREWERY-DEFAULT-SAVE-LOCATION-${global.account?.username || ''}`; +const BREWKEY = 'HB_newPage_content'; +const STYLEKEY = 'HB_newPage_style'; +const METAKEY = 'HB_newPage_metadata'; +const SAVEKEY = `HB_editor_defaultSave_${global.account?.username || ''}`; const NewPage = (props) => { props = { From 088ca9971cd42bf34d49297da29b6ac4cf58800a Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Wed, 10 Sep 2025 19:16:29 +1200 Subject: [PATCH 05/21] Update accountPage keys --- client/homebrew/pages/accountPage/accountPage.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/homebrew/pages/accountPage/accountPage.jsx b/client/homebrew/pages/accountPage/accountPage.jsx index 598683504..b69eb6e3e 100644 --- a/client/homebrew/pages/accountPage/accountPage.jsx +++ b/client/homebrew/pages/accountPage/accountPage.jsx @@ -13,7 +13,7 @@ const AccountPage = (props)=>{ // initialize save location from local storage based on user id React.useEffect(()=>{ if(!saveLocation && accountDetails.username) { - SAVEKEY = `HOMEBREWERY-DEFAULT-SAVE-LOCATION-${accountDetails.username}`; + SAVEKEY = `HB_editor_defaultSave_${accountDetails.username}`; // if no SAVEKEY in local storage, default save location to Google Drive if user has Google account. let saveLocation = window.localStorage.getItem(SAVEKEY); saveLocation = saveLocation ?? (accountDetails.googleId ? 'GOOGLE-DRIVE' : 'HOMEBREWERY'); From 328e071268cb0e893a82fb85080a2d8124622cf1 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Wed, 10 Sep 2025 19:22:54 +1200 Subject: [PATCH 06/21] Update BrewRenderer toolbar keys --- client/homebrew/brewRenderer/brewRenderer.jsx | 6 ++++-- client/homebrew/brewRenderer/toolBar/toolBar.jsx | 8 +++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/client/homebrew/brewRenderer/brewRenderer.jsx b/client/homebrew/brewRenderer/brewRenderer.jsx index 7a101e9f9..bda7143fc 100644 --- a/client/homebrew/brewRenderer/brewRenderer.jsx +++ b/client/homebrew/brewRenderer/brewRenderer.jsx @@ -24,6 +24,8 @@ const PAGEBREAK_REGEX_LEGACY = /\\page(?:break)?/m; const COLUMNBREAK_REGEX_LEGACY = /\\column(:?break)?/m; const PAGE_HEIGHT = 1056; +const TOOLBAR_STATE_KEY = 'HB_renderer_toolbarState'; + const INITIAL_CONTENT = dedent` @@ -122,7 +124,7 @@ const BrewRenderer = (props)=>{ //useEffect to store or gather toolbar state from storage useEffect(()=>{ - const toolbarState = JSON.parse(window.localStorage.getItem('hb_toolbarState')); + const toolbarState = JSON.parse(window.localStorage.getItem(TOOLBAR_STATE_KEY)); toolbarState && setDisplayOptions(toolbarState); }, []); @@ -284,7 +286,7 @@ const BrewRenderer = (props)=>{ const handleDisplayOptionsChange = (newDisplayOptions)=>{ setDisplayOptions(newDisplayOptions); - localStorage.setItem('hb_toolbarState', JSON.stringify(newDisplayOptions)); + localStorage.setItem(TOOLBAR_STATE_KEY, JSON.stringify(newDisplayOptions)); }; const pagesStyle = { diff --git a/client/homebrew/brewRenderer/toolBar/toolBar.jsx b/client/homebrew/brewRenderer/toolBar/toolBar.jsx index 6938eacb7..4aee3b6bd 100644 --- a/client/homebrew/brewRenderer/toolBar/toolBar.jsx +++ b/client/homebrew/brewRenderer/toolBar/toolBar.jsx @@ -9,6 +9,8 @@ import { Anchored, AnchoredBox, AnchoredTrigger } from '../../../components/Anch const MAX_ZOOM = 300; const MIN_ZOOM = 10; +const TOOLBAR_VISIBILITY = 'HB_renderer_toolbarVisibility'; + const ToolBar = ({ displayOptions, onDisplayOptionsChange, visiblePages, totalPages, headerState, setHeaderState })=>{ const [pageNum, setPageNum] = useState(1); @@ -21,8 +23,8 @@ const ToolBar = ({ displayOptions, onDisplayOptionsChange, visiblePages, totalPa }, [visiblePages]); useEffect(()=>{ - const Visibility = localStorage.getItem('hb_toolbarVisibility'); - if (Visibility) setToolsVisible(Visibility === 'true'); + const Visibility = localStorage.getItem(TOOLBAR_VISIBILITY); + if(Visibility) setToolsVisible(Visibility === 'true'); }, []); @@ -100,7 +102,7 @@ const ToolBar = ({ displayOptions, onDisplayOptionsChange, visiblePages, totalPa
From 52486495c82cf9d8cafe2df08655ec390360f7d8 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Wed, 10 Sep 2025 19:35:14 +1200 Subject: [PATCH 07/21] Update adminPage storage keys --- client/admin/admin.jsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/client/admin/admin.jsx b/client/admin/admin.jsx index 29973d221..15ca430e0 100644 --- a/client/admin/admin.jsx +++ b/client/admin/admin.jsx @@ -7,15 +7,17 @@ import LockTools from './lockTools/lockTools.jsx'; const tabGroups = ['brew', 'notifications', 'authors', 'locks']; +const ADMIN_TAB = 'hbAdminTab'; + const Admin = ()=>{ const [currentTab, setCurrentTab] = useState(''); useEffect(()=>{ - setCurrentTab(localStorage.getItem('hbAdminTab') || 'brew'); + setCurrentTab(localStorage.getItem(ADMIN_TAB) || 'brew'); }, []); useEffect(()=>{ - localStorage.setItem('hbAdminTab', currentTab); + localStorage.setItem(ADMIN_TAB, currentTab); }, [currentTab]); return ( From 885c0105f32988cf6af70ea5df2cae2164620ae6 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Wed, 10 Sep 2025 19:36:39 +1200 Subject: [PATCH 08/21] Update adminPage key --- client/admin/admin.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/admin/admin.jsx b/client/admin/admin.jsx index 15ca430e0..787c2a3eb 100644 --- a/client/admin/admin.jsx +++ b/client/admin/admin.jsx @@ -7,7 +7,7 @@ import LockTools from './lockTools/lockTools.jsx'; const tabGroups = ['brew', 'notifications', 'authors', 'locks']; -const ADMIN_TAB = 'hbAdminTab'; +const ADMIN_TAB = 'HB_adminPage_currentTab'; const Admin = ()=>{ const [currentTab, setCurrentTab] = useState(''); From 58277585e1d770724585e662110c52720888d9b5 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Wed, 10 Sep 2025 19:55:42 +1200 Subject: [PATCH 09/21] Update Recent Items keys --- client/homebrew/navbar/recent.navitem.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/homebrew/navbar/recent.navitem.jsx b/client/homebrew/navbar/recent.navitem.jsx index a6cbbf406..4c4722515 100644 --- a/client/homebrew/navbar/recent.navitem.jsx +++ b/client/homebrew/navbar/recent.navitem.jsx @@ -5,8 +5,8 @@ const Moment = require('moment'); const Nav = require('naturalcrit/nav/nav.jsx'); -const EDIT_KEY = 'homebrewery-recently-edited'; -const VIEW_KEY = 'homebrewery-recently-viewed'; +const EDIT_KEY = 'HB_nav_recentlyEdited'; +const VIEW_KEY = 'HB_nav_recentlyViewed'; const RecentItems = createClass({ From fd370c777dc465d99c9281ec6f4d792ce2acc489 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Wed, 10 Sep 2025 19:57:16 +1200 Subject: [PATCH 10/21] Update Editor theme key --- client/homebrew/editor/editor.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/homebrew/editor/editor.jsx b/client/homebrew/editor/editor.jsx index 8d331e46e..8c53cb333 100644 --- a/client/homebrew/editor/editor.jsx +++ b/client/homebrew/editor/editor.jsx @@ -10,7 +10,7 @@ const CodeEditor = require('naturalcrit/codeEditor/codeEditor.jsx'); const SnippetBar = require('./snippetbar/snippetbar.jsx'); const MetadataEditor = require('./metadataEditor/metadataEditor.jsx'); -const EDITOR_THEME_KEY = 'HOMEBREWERY-EDITOR-THEME'; +const EDITOR_THEME_KEY = 'HB_editor_theme'; const PAGEBREAK_REGEX_V3 = /^(?=\\page(?:break)?(?: *{[^\n{}]*})?$)/m; const SNIPPETBREAK_REGEX_V3 = /^\\snippet\ .*$/; @@ -143,7 +143,7 @@ const Editor = createClass({ handleViewChange : function(newView){ this.props.setMoveArrows(newView === 'text'); - + this.setState({ view : newView }, ()=>{ From 5504c1b96b74e465f14941f31451cfc3c7132224 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Wed, 10 Sep 2025 20:00:53 +1200 Subject: [PATCH 11/21] Update Autosave key --- client/homebrew/pages/editPage/editPage.jsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/client/homebrew/pages/editPage/editPage.jsx b/client/homebrew/pages/editPage/editPage.jsx index 49512d66c..b4eca7e2d 100644 --- a/client/homebrew/pages/editPage/editPage.jsx +++ b/client/homebrew/pages/editPage/editPage.jsx @@ -38,6 +38,8 @@ const SAVE_TIMEOUT = 10000; const UNSAVED_WARNING_TIMEOUT = 900000; //Warn user afer 15 minutes of unsaved changes const UNSAVED_WARNING_POPUP_TIMEOUT = 4000; //Show the warning for 4 seconds +const AUTOSAVE_KEY = 'HB_editor_autoSaveOn'; + const EditPage = (props)=>{ props = { brew : DEFAULT_BREW_LOAD, @@ -70,7 +72,7 @@ const EditPage = (props)=>{ useEffect(()=>{ setUrl(window.location.href); - const autoSavePref = JSON.parse(localStorage.getItem('AUTOSAVE_ON') ?? true); + const autoSavePref = JSON.parse(localStorage.getItem(AUTOSAVE_KEY) ?? true); setAutoSaveEnabled(autoSavePref); setAutoSaveWarning(!autoSavePref); setHTMLErrors(Markdown.validate(currentBrew.text)); @@ -317,7 +319,7 @@ const EditPage = (props)=>{ const toggleAutoSave = ()=>{ if(warningTimer.current) clearTimeout(warningTimer.current); - localStorage.setItem('AUTOSAVE_ON', JSON.stringify(!autoSaveEnabled)); + localStorage.setItem(AUTOSAVE_KEY, JSON.stringify(!autoSaveEnabled)); setAutoSaveWarning(autoSaveWarning); setAutoSaveEnabled(!autoSaveEnabled); }; From dc1bc471aad9f63a34a5ea11fd262b60cc4f98e9 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Wed, 10 Sep 2025 20:10:18 +1200 Subject: [PATCH 12/21] Update SplitPane keys --- client/components/splitPane/splitPane.jsx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/client/components/splitPane/splitPane.jsx b/client/components/splitPane/splitPane.jsx index 4c77d81a5..78ba59ed3 100644 --- a/client/components/splitPane/splitPane.jsx +++ b/client/components/splitPane/splitPane.jsx @@ -2,7 +2,8 @@ require('./splitPane.less'); const React = require('react'); const { useState, useEffect } = React; -const storageKey = 'naturalcrit-pane-split'; +const PANE_WIDTH_KEY = 'HB_editor_splitWidth'; +const LIVE_SCROLL_KEY = 'HB_editor_liveScroll'; const SplitPane = (props)=>{ const { @@ -18,9 +19,9 @@ const SplitPane = (props)=>{ const [liveScroll, setLiveScroll] = useState(false); useEffect(()=>{ - const savedPos = window.localStorage.getItem(storageKey); + const savedPos = window.localStorage.getItem(PANE_WIDTH_KEY); setDividerPos(savedPos ? limitPosition(savedPos, 0.1 * (window.innerWidth - 13), 0.9 * (window.innerWidth - 13)) : window.innerWidth / 2); - setLiveScroll(window.localStorage.getItem('liveScroll') === 'true'); + setLiveScroll(window.localStorage.getItem(LIVE_SCROLL_KEY) === 'true'); window.addEventListener('resize', handleResize); return ()=>window.removeEventListener('resize', handleResize); @@ -29,13 +30,13 @@ const SplitPane = (props)=>{ const limitPosition = (x, min = 1, max = window.innerWidth - 13)=>Math.round(Math.min(max, Math.max(min, x))); //when resizing, the divider should grow smaller if less space is given, then grow back if the space is restored, to the original position - const handleResize = ()=>setDividerPos(limitPosition(window.localStorage.getItem(storageKey), 0.1 * (window.innerWidth - 13), 0.9 * (window.innerWidth - 13))); + const handleResize = ()=>setDividerPos(limitPosition(window.localStorage.getItem(PANE_WIDTH_KEY), 0.1 * (window.innerWidth - 13), 0.9 * (window.innerWidth - 13))); const handleUp =(e)=>{ e.preventDefault(); if(isDragging) { onDragFinish(dividerPos); - window.localStorage.setItem(storageKey, dividerPos); + window.localStorage.setItem(PANE_WIDTH_KEY, dividerPos); } setIsDragging(false); }; @@ -52,7 +53,7 @@ const SplitPane = (props)=>{ }; const liveScrollToggle = ()=>{ - window.localStorage.setItem('liveScroll', String(!liveScroll)); + window.localStorage.setItem(LIVE_SCROLL_KEY, String(!liveScroll)); setLiveScroll(!liveScroll); }; From b6818e963b7373e3af57c238f3fae08109f10a24 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Wed, 10 Sep 2025 20:12:50 +1200 Subject: [PATCH 13/21] Remove unused dismiss keys --- .../utils/updateLocalStorage/localStorageKeyMap.json | 5 ----- 1 file changed, 5 deletions(-) diff --git a/client/homebrew/utils/updateLocalStorage/localStorageKeyMap.json b/client/homebrew/utils/updateLocalStorage/localStorageKeyMap.json index b880bfa0c..984ccba7e 100644 --- a/client/homebrew/utils/updateLocalStorage/localStorageKeyMap.json +++ b/client/homebrew/utils/updateLocalStorage/localStorageKeyMap.json @@ -9,11 +9,6 @@ "HOMEBREWERY-LISTPAGE-VISIBILITY-published" : "HB_listPage_visibility_group_published", "HOMEBREWERY-LISTPAGE-VISIBILITY-unpublished" : "HB_listPage_visibility_group_unpublished", - "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", From 8d4ea7cfd84a07fe3f3d9aa138f2c4b8d408c98d Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Wed, 10 Sep 2025 20:20:42 +1200 Subject: [PATCH 14/21] Update listPage storage keys --- .../pages/basePages/listPage/listPage.jsx | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/client/homebrew/pages/basePages/listPage/listPage.jsx b/client/homebrew/pages/basePages/listPage/listPage.jsx index ec557ffb1..4afc14364 100644 --- a/client/homebrew/pages/basePages/listPage/listPage.jsx +++ b/client/homebrew/pages/basePages/listPage/listPage.jsx @@ -7,7 +7,9 @@ const moment = require('moment'); const BrewItem = require('./brewItem/brewItem.jsx'); -const USERPAGE_KEY_PREFIX = 'HOMEBREWERY-LISTPAGE'; +const USERPAGE_SORT_DIR = 'HB_listPage_sortDir'; +const USERPAGE_SORT_TYPE = 'HB_listPage_sortType'; +const USERPAGE_GROUP_VISIBILITY_PREFIX = 'HB_listPage_visibility_group'; const DEFAULT_SORT_TYPE = 'alpha'; const DEFAULT_SORT_DIR = 'asc'; @@ -50,12 +52,12 @@ const ListPage = createClass({ // LOAD FROM LOCAL STORAGE if(typeof window !== 'undefined') { - const newSortType = (this.state.sortType ?? (localStorage.getItem(`${USERPAGE_KEY_PREFIX}-SORTTYPE`) || DEFAULT_SORT_TYPE)); - const newSortDir = (this.state.sortDir ?? (localStorage.getItem(`${USERPAGE_KEY_PREFIX}-SORTDIR`) || DEFAULT_SORT_DIR)); + const newSortType = (this.state.sortType ?? (localStorage.getItem(USERPAGE_SORT_TYPE) || DEFAULT_SORT_TYPE)); + const newSortDir = (this.state.sortDir ?? (localStorage.getItem(USERPAGE_SORT_DIR) || DEFAULT_SORT_DIR)); this.updateUrl(this.state.filterString, newSortType, newSortDir); const brewCollection = this.props.brewCollection.map((brewGroup)=>{ - brewGroup.visible = (localStorage.getItem(`${USERPAGE_KEY_PREFIX}-VISIBILITY-${brewGroup.class}`) ?? 'true')=='true'; + brewGroup.visible = (localStorage.getItem(`${USERPAGE_GROUP_VISIBILITY_PREFIX}_${brewGroup.class}`) ?? 'true')=='true'; return brewGroup; }); @@ -73,10 +75,10 @@ const ListPage = createClass({ saveToLocalStorage : function() { this.state.brewCollection.map((brewGroup)=>{ - localStorage.setItem(`${USERPAGE_KEY_PREFIX}-VISIBILITY-${brewGroup.class}`, `${brewGroup.visible}`); + localStorage.setItem(`${USERPAGE_GROUP_VISIBILITY_PREFIX}_${brewGroup.class}`, `${brewGroup.visible}`); }); - localStorage.setItem(`${USERPAGE_KEY_PREFIX}-SORTTYPE`, this.state.sortType); - localStorage.setItem(`${USERPAGE_KEY_PREFIX}-SORTDIR`, this.state.sortDir); + localStorage.setItem(USERPAGE_SORT_TYPE, this.state.sortType); + localStorage.setItem(USERPAGE_SORT_DIR, this.state.sortDir); }, renderBrews : function(brews){ From 2663d86627bdee7b7bc52871be69c846efcbbde7 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Wed, 10 Sep 2025 20:31:50 +1200 Subject: [PATCH 15/21] Don't update storage values if key already exists --- .../homebrew/utils/updateLocalStorage/updateLocalStorageKeys.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/homebrew/utils/updateLocalStorage/updateLocalStorageKeys.js b/client/homebrew/utils/updateLocalStorage/updateLocalStorageKeys.js index dae2580f4..9f32a840b 100644 --- a/client/homebrew/utils/updateLocalStorage/updateLocalStorageKeys.js +++ b/client/homebrew/utils/updateLocalStorage/updateLocalStorageKeys.js @@ -23,7 +23,7 @@ const updateLocalStorage = function(){ Object.keys(storageKeyMap).forEach((key)=>{ if(storage[key]){ const data = storage.getItem(key); - storage.setItem(storageKeyMap[key], data); + if(!storage[storageKeyMap[key]]) storage.setItem(storageKeyMap[key], data); // storage.removeItem(key); } }); From a11fa72261a98e46a618934e2b3701d4a66666a4 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Thu, 11 Sep 2025 21:02:56 +1200 Subject: [PATCH 16/21] Change JSON file to JS getter function --- .../updateLocalStorage/localStorageKeyMap.js | 35 +++++++++++++++++++ .../localStorageKeyMap.json | 23 ------------ .../updateLocalStorageKeys.js | 18 +++------- 3 files changed, 39 insertions(+), 37 deletions(-) create mode 100644 client/homebrew/utils/updateLocalStorage/localStorageKeyMap.js delete mode 100644 client/homebrew/utils/updateLocalStorage/localStorageKeyMap.json diff --git a/client/homebrew/utils/updateLocalStorage/localStorageKeyMap.js b/client/homebrew/utils/updateLocalStorage/localStorageKeyMap.js new file mode 100644 index 000000000..b4a05974f --- /dev/null +++ b/client/homebrew/utils/updateLocalStorage/localStorageKeyMap.js @@ -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; \ No newline at end of file diff --git a/client/homebrew/utils/updateLocalStorage/localStorageKeyMap.json b/client/homebrew/utils/updateLocalStorage/localStorageKeyMap.json deleted file mode 100644 index 984ccba7e..000000000 --- a/client/homebrew/utils/updateLocalStorage/localStorageKeyMap.json +++ /dev/null @@ -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" -} \ No newline at end of file diff --git a/client/homebrew/utils/updateLocalStorage/updateLocalStorageKeys.js b/client/homebrew/utils/updateLocalStorage/updateLocalStorageKeys.js index 9f32a840b..4fd7262a3 100644 --- a/client/homebrew/utils/updateLocalStorage/updateLocalStorageKeys.js +++ b/client/homebrew/utils/updateLocalStorage/updateLocalStorageKeys.js @@ -1,29 +1,19 @@ -import localStorageKeyMap from './localStorageKeyMap.json' with { type: 'json' }; - -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; -}; +import getLocalStorageMap from './localStorageKeyMap.js'; 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 + const localStorageKeyMap = getLocalStorageMap(); if(Object.keys(localStorageKeyMap).length == 0) return; const storage = window.localStorage; - const storageKeyMap = addDynamicKeys(localStorageKeyMap); - Object.keys(storageKeyMap).forEach((key)=>{ + Object.keys(localStorageKeyMap).forEach((key)=>{ if(storage[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); } }); From 1459f6a32077e7778327a687bce912c343887708 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Thu, 11 Sep 2025 21:25:13 +1200 Subject: [PATCH 17/21] Tweak local storage update logic --- .../utils/updateLocalStorage/updateLocalStorageKeys.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/homebrew/utils/updateLocalStorage/updateLocalStorageKeys.js b/client/homebrew/utils/updateLocalStorage/updateLocalStorageKeys.js index 4fd7262a3..6ab4fbcd1 100644 --- a/client/homebrew/utils/updateLocalStorage/updateLocalStorageKeys.js +++ b/client/homebrew/utils/updateLocalStorage/updateLocalStorageKeys.js @@ -11,9 +11,9 @@ const updateLocalStorage = function(){ const storage = window.localStorage; Object.keys(localStorageKeyMap).forEach((key)=>{ - if(storage[key]){ + if(storage[key] && !storage[localStorageKeyMap[key]]){ const data = storage.getItem(key); - if(!storage[localStorageKeyMap[key]]) storage.setItem(localStorageKeyMap[key], data); + storage.setItem(localStorageKeyMap[key], data); // storage.removeItem(key); } }); From 87a36bb02df1cd1d38945193a6fd3e286301c2e8 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Thu, 11 Sep 2025 21:57:00 +1200 Subject: [PATCH 18/21] Add tests for localStorageKeyMap.js --- .../localStorageKeyMap.spec.js | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 client/homebrew/utils/updateLocalStorage/localStorageKeyMap.spec.js diff --git a/client/homebrew/utils/updateLocalStorage/localStorageKeyMap.spec.js b/client/homebrew/utils/updateLocalStorage/localStorageKeyMap.spec.js new file mode 100644 index 000000000..ac61d4add --- /dev/null +++ b/client/homebrew/utils/updateLocalStorage/localStorageKeyMap.spec.js @@ -0,0 +1,30 @@ +import getLocalStorageMap from './localStorageKeyMap.js'; + +describe('getLocalStorageMap', ()=>{ + it('no username', ()=>{ + const account = global.account; + + delete global.account; + + const map = getLocalStorageMap(); + + global.account = account; + + expect(map).toBeInstanceOf(Object); + expect(Object.entries(map)).toHaveLength(16); + }); + + it('no username', ()=>{ + const account = global.account; + + global.account = { username: 'test' }; + + const map = getLocalStorageMap(); + + global.account = account; + + expect(map).toBeInstanceOf(Object); + expect(Object.entries(map)).toHaveLength(17); + expect(map).toHaveProperty('HOMEBREWERY-DEFAULT-SAVE-LOCATION-test', 'HB_editor_defaultSave_test'); + }); +}); \ No newline at end of file From e82921f81a7a2250ab0cade4124e028b0c5df156 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Sat, 4 Oct 2025 14:54:57 +1300 Subject: [PATCH 19/21] Add key to activate deletion for testing --- .../utils/updateLocalStorage/updateLocalStorageKeys.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/client/homebrew/utils/updateLocalStorage/updateLocalStorageKeys.js b/client/homebrew/utils/updateLocalStorage/updateLocalStorageKeys.js index 6ab4fbcd1..05b57dfa2 100644 --- a/client/homebrew/utils/updateLocalStorage/updateLocalStorageKeys.js +++ b/client/homebrew/utils/updateLocalStorage/updateLocalStorageKeys.js @@ -10,11 +10,14 @@ const updateLocalStorage = function(){ const storage = window.localStorage; + const deleteKeys = storage?.getItem('HB_deleteKeys') != null; + console.log('DELETE KEYS:', deleteKeys); + Object.keys(localStorageKeyMap).forEach((key)=>{ if(storage[key] && !storage[localStorageKeyMap[key]]){ const data = storage.getItem(key); storage.setItem(localStorageKeyMap[key], data); - // storage.removeItem(key); + if(deleteKeys) storage.removeItem(key); } }); From 400fa250eec2b71df2bd4ca124b4f3121e000956 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Sat, 4 Oct 2025 15:19:31 +1300 Subject: [PATCH 20/21] Move key deletion out of key update check --- .../utils/updateLocalStorage/updateLocalStorageKeys.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/client/homebrew/utils/updateLocalStorage/updateLocalStorageKeys.js b/client/homebrew/utils/updateLocalStorage/updateLocalStorageKeys.js index 05b57dfa2..6d0bf0c8c 100644 --- a/client/homebrew/utils/updateLocalStorage/updateLocalStorageKeys.js +++ b/client/homebrew/utils/updateLocalStorage/updateLocalStorageKeys.js @@ -11,12 +11,13 @@ const updateLocalStorage = function(){ const storage = window.localStorage; const deleteKeys = storage?.getItem('HB_deleteKeys') != null; - console.log('DELETE KEYS:', deleteKeys); Object.keys(localStorageKeyMap).forEach((key)=>{ - if(storage[key] && !storage[localStorageKeyMap[key]]){ - const data = storage.getItem(key); - storage.setItem(localStorageKeyMap[key], data); + if(storage[key]){ + if(!storage[localStorageKeyMap[key]]){ + const data = storage.getItem(key); + storage.setItem(localStorageKeyMap[key], data); + }; if(deleteKeys) storage.removeItem(key); } }); From 962dcbdbf6edbd8d1dadfa84f38b8fe38cdfe6dd Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Sat, 4 Oct 2025 15:36:14 +1300 Subject: [PATCH 21/21] Update Docker instructions --- README.DOCKER.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/README.DOCKER.md b/README.DOCKER.md index 4dfbef045..c3b38224d 100644 --- a/README.DOCKER.md +++ b/README.DOCKER.md @@ -49,7 +49,7 @@ Make an changes you need to `config/docker.json` then build the image. If it doe "web_port" : 8000, "enable_v3" : true, "mongodb_uri": "mongodb://172.17.0.2/homebrewery", -"enable_themes" : true, +"enable_themes" : true } ``` @@ -90,6 +90,13 @@ docker run --name homebrewery-mongodb -d --restart unless-stopped -v mongodata:/ docker run --name homebrewery-app -d --restart unless-stopped -e NODE_ENV=docker -v $(pwd)/config/docker.json:/usr/src/app/config/docker.json -p 8000:8000 docker.io/library/homebrewery:latest ``` +**NOTE:** If you are running from the Windows command line, this will not work as `$(pwd)` is not valid syntax. Use this command instead: +```shell +# Make sure you run this in the homebrewery directory +docker run --name homebrewery-app -d --restart unless-stopped -e NODE_ENV=docker -v %cd%/config/docker.json:/usr/src/app/config/docker.json -p 8000:8000 docker.io/library/homebrewery:latest +``` + + ## Updating the Image When Homebrewery code updates, your docker container will not automatically follow the changes. To do so you will need to rebuild your homebrewery image. @@ -117,3 +124,9 @@ docker-compose build homebrewery docker run --name homebrewery-app -d --restart unless-stopped -e NODE_ENV=docker -v $(pwd)/config/docker.json:/usr/src/app/config/docker.json -p 8000:8000 docker.io/library/homebrewery:latest ``` +**NOTE:** If you are running from the Windows command line, this will not work as `$(pwd)` is not valid syntax. Use this command instead: +```shell +# Make sure you run this in the homebrewery directory +docker run --name homebrewery-app -d --restart unless-stopped -e NODE_ENV=docker -v %cd%/config/docker.json:/usr/src/app/config/docker.json -p 8000:8000 docker.io/library/homebrewery:latest +``` +