@@ -2,6 +2,7 @@ import "./style.scss";
22import toast from "components/toast" ;
33import Ref from "html-tag-js/ref" ;
44import actionStack from "lib/actionStack" ;
5+ import appSettings from "lib/settings" ;
56import auth , { loginEvents } from "lib/auth" ;
67import constants from "lib/constants" ;
78
@@ -33,14 +34,14 @@ function create($container, $toggler) {
3334
3435 const START_THRESHOLD = constants . SIDEBAR_SLIDE_START_THRESHOLD_PX ; //Point where to start swipe
3536 const MIN_WIDTH = 200 ; //Min width of the side bar
36- const MAX_WIDTH = ( ) => innerWidth * 0.7 ; //Max width of the side bar
37+ const MAX_WIDTH = ( ) => innerWidth - 40 ; //Max width of the side bar
3738 const resizeBar = Ref ( ) ;
3839 const userAvatar = Ref ( ) ;
3940 const userContextMenu = Ref ( ) ;
4041
4142 $container = $container || app ;
4243 let mode = innerWidth > 600 ? "tab" : "phone" ;
43- let width = + ( localStorage . sideBarWidth || MIN_WIDTH ) ;
44+ let width = Math . min ( appSettings . value . sidebarWidth || MIN_WIDTH , MAX_WIDTH ( ) ) ;
4445
4546 const eventOptions = { passive : false } ;
4647 const $el = (
@@ -92,6 +93,11 @@ function create($container, $toggler) {
9293 $toggler ?. addEventListener ( "click" , toggle ) ;
9394 $container . addEventListener ( "touchstart" , ontouchstart , eventOptions ) ;
9495 window . addEventListener ( "resize" , onWindowResize ) ;
96+
97+ appSettings . on ( "update:sidebarWidth" , ( ) => {
98+ width = Math . min ( appSettings . value . sidebarWidth || MIN_WIDTH , MAX_WIDTH ( ) ) ;
99+ setWidth ( width ) ;
100+ } ) ;
95101
96102 if ( mode === "tab" && localStorage . sidebarShown === "1" ) {
97103 show ( ) ;
@@ -226,6 +232,8 @@ function create($container, $toggler) {
226232 localStorage . sidebarShown = 1 ;
227233 $el . activated = true ;
228234 $el . onclick = null ;
235+
236+ setWidth ( width ) ;
229237
230238 if ( mode === "phone" ) {
231239 resizeBar . style . display = "none" ;
@@ -239,7 +247,6 @@ function create($container, $toggler) {
239247 action : hideMaster ,
240248 } ) ;
241249 } else {
242- setWidth ( width ) ;
243250 resizeBar . style . display = "block" ;
244251 app . append ( $el ) ;
245252 $el . onclick = ( ) => {
@@ -349,7 +356,8 @@ function create($container, $toggler) {
349356 if ( newWidth <= MIN_WIDTH ) width = MIN_WIDTH ;
350357 else if ( newWidth >= MAX_WIDTH ( ) ) width = MAX_WIDTH ( ) ;
351358 else width = newWidth ;
352- localStorage . sideBarWidth = width ;
359+ appSettings . value . sidebarWidth = width ;
360+ appSettings . update ( false ) ;
353361 document . removeEventListener ( "touchmove" , onMove , eventOptions ) ;
354362 document . removeEventListener ( "mousemove" , onMove , eventOptions ) ;
355363 document . removeEventListener ( "touchend" , onEnd , eventOptions ) ;
@@ -468,9 +476,12 @@ function create($container, $toggler) {
468476 */
469477 function setWidth ( width ) {
470478 $el . style . transition = "none" ;
479+ $el . style . width = width + "px" ;
471480 $el . style . maxWidth = width + "px" ;
472- root . style . marginLeft = width + "px" ;
473- root . style . width = `calc(100% - ${ width } px)` ;
481+ if ( mode === "tab" ) {
482+ root . style . marginLeft = width + "px" ;
483+ root . style . width = `calc(100% - ${ width } px)` ;
484+ }
474485 clearTimeout ( setWidthTimeout ) ;
475486 setWidthTimeout = setTimeout ( ( ) => {
476487 editorManager ?. editor ?. resize ( true ) ;
@@ -492,8 +503,8 @@ function create($container, $toggler) {
492503 $el . toggle = toggle ;
493504 $el . onshow = ( ) => { } ;
494505 $el . getWidth = function ( ) {
495- const width = innerWidth * 0.7 ;
496- return mode === "phone" ? ( width >= 350 ? 350 : width ) : MIN_WIDTH ;
506+ const configuredWidth = appSettings . value . sidebarWidth || MIN_WIDTH ;
507+ return mode === "phone" ? Math . min ( configuredWidth , MAX_WIDTH ( ) ) : width ;
497508 } ;
498509
499510 return $el ;
0 commit comments