-
Notifications
You must be signed in to change notification settings - Fork 918
feat: add configurable sidebar width in settings #1975
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,6 +2,7 @@ import "./style.scss"; | |||||||||||||||||||||
| import toast from "components/toast"; | ||||||||||||||||||||||
| import Ref from "html-tag-js/ref"; | ||||||||||||||||||||||
| import actionStack from "lib/actionStack"; | ||||||||||||||||||||||
| import appSettings from "lib/settings"; | ||||||||||||||||||||||
| import auth, { loginEvents } from "lib/auth"; | ||||||||||||||||||||||
| import constants from "lib/constants"; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
@@ -33,14 +34,14 @@ function create($container, $toggler) { | |||||||||||||||||||||
|
|
||||||||||||||||||||||
| const START_THRESHOLD = constants.SIDEBAR_SLIDE_START_THRESHOLD_PX; //Point where to start swipe | ||||||||||||||||||||||
| const MIN_WIDTH = 200; //Min width of the side bar | ||||||||||||||||||||||
| const MAX_WIDTH = () => innerWidth * 0.7; //Max width of the side bar | ||||||||||||||||||||||
| const MAX_WIDTH = () => innerWidth - 40; //Max width of the side bar | ||||||||||||||||||||||
| const resizeBar = Ref(); | ||||||||||||||||||||||
| const userAvatar = Ref(); | ||||||||||||||||||||||
| const userContextMenu = Ref(); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| $container = $container || app; | ||||||||||||||||||||||
| let mode = innerWidth > 600 ? "tab" : "phone"; | ||||||||||||||||||||||
| let width = +(localStorage.sideBarWidth || MIN_WIDTH); | ||||||||||||||||||||||
| let width = Math.min(appSettings.value.sidebarWidth || MIN_WIDTH, MAX_WIDTH()); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const eventOptions = { passive: false }; | ||||||||||||||||||||||
| const $el = ( | ||||||||||||||||||||||
|
|
@@ -92,6 +93,11 @@ function create($container, $toggler) { | |||||||||||||||||||||
| $toggler?.addEventListener("click", toggle); | ||||||||||||||||||||||
| $container.addEventListener("touchstart", ontouchstart, eventOptions); | ||||||||||||||||||||||
| window.addEventListener("resize", onWindowResize); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| appSettings.on("update:sidebarWidth", () => { | ||||||||||||||||||||||
| width = Math.min(appSettings.value.sidebarWidth || MIN_WIDTH, MAX_WIDTH()); | ||||||||||||||||||||||
| setWidth(width); | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if (mode === "tab" && localStorage.sidebarShown === "1") { | ||||||||||||||||||||||
| show(); | ||||||||||||||||||||||
|
|
@@ -226,6 +232,8 @@ function create($container, $toggler) { | |||||||||||||||||||||
| localStorage.sidebarShown = 1; | ||||||||||||||||||||||
| $el.activated = true; | ||||||||||||||||||||||
| $el.onclick = null; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| setWidth(width); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if (mode === "phone") { | ||||||||||||||||||||||
| resizeBar.style.display = "none"; | ||||||||||||||||||||||
|
|
@@ -239,7 +247,6 @@ function create($container, $toggler) { | |||||||||||||||||||||
| action: hideMaster, | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
| } else { | ||||||||||||||||||||||
| setWidth(width); | ||||||||||||||||||||||
| resizeBar.style.display = "block"; | ||||||||||||||||||||||
| app.append($el); | ||||||||||||||||||||||
| $el.onclick = () => { | ||||||||||||||||||||||
|
|
@@ -349,7 +356,8 @@ function create($container, $toggler) { | |||||||||||||||||||||
| if (newWidth <= MIN_WIDTH) width = MIN_WIDTH; | ||||||||||||||||||||||
| else if (newWidth >= MAX_WIDTH()) width = MAX_WIDTH(); | ||||||||||||||||||||||
| else width = newWidth; | ||||||||||||||||||||||
| localStorage.sideBarWidth = width; | ||||||||||||||||||||||
| appSettings.value.sidebarWidth = width; | ||||||||||||||||||||||
| appSettings.update(false); | ||||||||||||||||||||||
|
Comment on lines
+359
to
+360
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Setting Use the idiomatic
Suggested change
|
||||||||||||||||||||||
| document.removeEventListener("touchmove", onMove, eventOptions); | ||||||||||||||||||||||
| document.removeEventListener("mousemove", onMove, eventOptions); | ||||||||||||||||||||||
| document.removeEventListener("touchend", onEnd, eventOptions); | ||||||||||||||||||||||
|
|
@@ -468,9 +476,12 @@ function create($container, $toggler) { | |||||||||||||||||||||
| */ | ||||||||||||||||||||||
| function setWidth(width) { | ||||||||||||||||||||||
| $el.style.transition = "none"; | ||||||||||||||||||||||
| $el.style.width = width + "px"; | ||||||||||||||||||||||
| $el.style.maxWidth = width + "px"; | ||||||||||||||||||||||
| root.style.marginLeft = width + "px"; | ||||||||||||||||||||||
| root.style.width = `calc(100% - ${width}px)`; | ||||||||||||||||||||||
| if (mode === "tab") { | ||||||||||||||||||||||
| root.style.marginLeft = width + "px"; | ||||||||||||||||||||||
| root.style.width = `calc(100% - ${width}px)`; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| clearTimeout(setWidthTimeout); | ||||||||||||||||||||||
| setWidthTimeout = setTimeout(() => { | ||||||||||||||||||||||
| editorManager?.editor?.resize(true); | ||||||||||||||||||||||
|
|
@@ -492,8 +503,8 @@ function create($container, $toggler) { | |||||||||||||||||||||
| $el.toggle = toggle; | ||||||||||||||||||||||
| $el.onshow = () => {}; | ||||||||||||||||||||||
| $el.getWidth = function () { | ||||||||||||||||||||||
| const width = innerWidth * 0.7; | ||||||||||||||||||||||
| return mode === "phone" ? (width >= 350 ? 350 : width) : MIN_WIDTH; | ||||||||||||||||||||||
| const configuredWidth = appSettings.value.sidebarWidth || MIN_WIDTH; | ||||||||||||||||||||||
| return mode === "phone" ? Math.min(configuredWidth, MAX_WIDTH()) : width; | ||||||||||||||||||||||
| }; | ||||||||||||||||||||||
|
Comment on lines
505
to
508
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For For consistency (and to avoid the stale-value issue), tab mode should also be re-clamped:
Suggested change
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| return $el; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -87,6 +87,21 @@ export default function otherSettings() { | |||||||||||||||||||||||
| info: strings["settings-info-app-floating-button"], | ||||||||||||||||||||||||
| category: categories.interface, | ||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| key: "sidebarWidth", | ||||||||||||||||||||||||
| text: strings["sidebar width"] || "Sidebar width", | ||||||||||||||||||||||||
| value: values.sidebarWidth, | ||||||||||||||||||||||||
| prompt: strings["sidebar width"] || "Sidebar width (pixels)", | ||||||||||||||||||||||||
| promptType: "number", | ||||||||||||||||||||||||
| promptOptions: { | ||||||||||||||||||||||||
| test(value) { | ||||||||||||||||||||||||
| value = Number.parseInt(value); | ||||||||||||||||||||||||
| return value >= 200 && value <= 1500; | ||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||
|
Comment on lines
+96
to
+101
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The Consider deriving the max from screen dimensions at validation time, or at least document the runtime clamping in the
Suggested change
|
||||||||||||||||||||||||
| info: "Adjust the width of the sidebar (min 200px).", | ||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Every other settings item in this file uses a localized
Suggested change
|
||||||||||||||||||||||||
| category: categories.interface, | ||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| key: "showSideButtons", | ||||||||||||||||||||||||
| text: strings["show side buttons"], | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
appSettings.on("update:sidebarWidth", ...)is registered insidecreate()but there is no correspondingappSettings.off(...)call when the sidebar element is destroyed (e.g. afterhideMasterremoves it from the DOM, or ifcreateis ever called more than once in the singleton pattern).Each call to
create()accumulates another live listener on the globalappSettingsobject. Over time those stale callbacks will callsetWidthon detached elements and keep closed-over DOM nodes alive. Store the callback reference and deregister it in a cleanup path (the existinghide/hideMasterflow would be a good place):