Skip to content

Commit

Permalink
🔧 Prevent sidebar from saving to metadata until resize is complete (#…
Browse files Browse the repository at this point in the history
…3393)

* prevent sidebar from saving to metadata until resize is complete

* add release notes
  • Loading branch information
MikesGlitch authored Sep 8, 2024
1 parent c466189 commit 008a8a7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
20 changes: 16 additions & 4 deletions packages/desktop-client/src/components/sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,26 @@ export function Sidebar() {
const [isFloating = false, setFloatingSidebarPref] =
useGlobalPref('floatingSidebar');

const [_sidebarWidth, setSidebarWidth] = useLocalPref('sidebarWidth');
const [sidebarWidthLocalPref, setSidebarWidthLocalPref] =
useLocalPref('sidebarWidth');
const DEFAULT_SIDEBAR_WIDTH = 240;
const MAX_SIDEBAR_WIDTH = width / 3;
const MIN_SIDEBAR_WIDTH = 200;
const sidebarWidth = Math.min(
MAX_SIDEBAR_WIDTH,
Math.max(MIN_SIDEBAR_WIDTH, _sidebarWidth || DEFAULT_SIDEBAR_WIDTH),

const [sidebarWidth, setSidebarWidth] = useState(
Math.min(
MAX_SIDEBAR_WIDTH,
Math.max(
MIN_SIDEBAR_WIDTH,
sidebarWidthLocalPref || DEFAULT_SIDEBAR_WIDTH,
),
),
);

const onResizeStop = () => {
setSidebarWidthLocalPref(sidebarWidth);
};

async function onReorder(
id: string,
dropPos: 'top' | 'bottom',
Expand Down Expand Up @@ -95,6 +106,7 @@ export function Sidebar() {
width: sidebarWidth,
height: '100%',
}}
onResizeStop={onResizeStop}
maxWidth={MAX_SIDEBAR_WIDTH}
minWidth={MIN_SIDEBAR_WIDTH}
enable={{
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/3393.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Maintenance
authors: [MikesGlitch]
---

Prevent sidebar from saving to metadata.json unnecessarily

0 comments on commit 008a8a7

Please sign in to comment.