Skip to content

Commit 33b6234

Browse files
committed
MY FINAL COMMIT
1 parent f1cfdbf commit 33b6234

File tree

4 files changed

+28
-23
lines changed

4 files changed

+28
-23
lines changed

static/app/utils/useResizable.tsx

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,6 @@ interface UseResizableOptions {
3838
* Triggered when the user starts dragging the resize handle.
3939
*/
4040
onResizeStart?: () => void;
41-
42-
/**
43-
* The local storage key used to persist the size of the container. If not provided,
44-
* the size will not be persisted and the defaultWidth will be used.
45-
*/
46-
sizeStorageKey?: string;
4741
}
4842

4943
/**
@@ -58,7 +52,6 @@ export const useResizable = ({
5852
minWidth = RESIZABLE_MIN_WIDTH,
5953
onResizeEnd,
6054
onResizeStart,
61-
sizeStorageKey,
6255
}: UseResizableOptions): {
6356
/**
6457
* Whether the drag handle is held.
@@ -86,14 +79,9 @@ export const useResizable = ({
8679

8780
useEffect(() => {
8881
if (ref.current) {
89-
const storedSize = sizeStorageKey
90-
? parseInt(localStorage.getItem(sizeStorageKey) ?? '', 10)
91-
: undefined;
92-
93-
ref.current.style.width = `${storedSize ?? initialSize}px`;
82+
ref.current.style.width = `${initialSize}px`;
9483
}
95-
console.log(ref.current?.style.width);
96-
}, [ref, initialSize, sizeStorageKey]);
84+
}, [ref, initialSize]);
9785

9886
const handleMouseDown = useCallback(
9987
(e: React.MouseEvent) => {
@@ -139,10 +127,7 @@ export const useResizable = ({
139127
document.body.style.cursor = '';
140128
document.body.style.userSelect = '';
141129
onResizeEnd?.(newSize);
142-
if (sizeStorageKey) {
143-
localStorage.setItem(sizeStorageKey, newSize.toString());
144-
}
145-
}, [onResizeEnd, ref, sizeStorageKey, initialSize]);
130+
}, [onResizeEnd, ref, initialSize]);
146131

147132
useEffect(() => {
148133
document.addEventListener('mousemove', handleMouseMove);

static/app/views/nav/constants.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export const NAV_SIDEBAR_COLLAPSED_LOCAL_STORAGE_KEY = 'navigation-sidebar-is-co
22

33
export const PRIMARY_SIDEBAR_WIDTH = 74;
44
export const SECONDARY_SIDEBAR_WIDTH = 190;
5-
export const SECONDARY_SIDEBAR_MIN_WIDTH = 100;
5+
export const SECONDARY_SIDEBAR_MIN_WIDTH = 150;
66
export const SECONDARY_SIDEBAR_MAX_WIDTH = 500;
77

88
// Slightly delay closing the nav to prevent accidental dismissal

static/app/views/nav/secondary/secondarySidebar.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import styled from '@emotion/styled';
33
import {AnimatePresence, motion} from 'framer-motion';
44

55
import useResizable from 'sentry/utils/useResizable';
6+
import {useSyncedLocalStorageState} from 'sentry/utils/useSyncedLocalStorageState';
67
import {
78
SECONDARY_SIDEBAR_MAX_WIDTH,
89
SECONDARY_SIDEBAR_MIN_WIDTH,
@@ -25,16 +26,23 @@ export function SecondarySidebar() {
2526
const resizableContainerRef = useRef<HTMLDivElement>(null);
2627
const resizeHandleRef = useRef<HTMLDivElement>(null);
2728

29+
const [secondarySidebarWidth, setSecondarySidebarWidth] = useSyncedLocalStorageState(
30+
'secondary-sidebar-width',
31+
SECONDARY_SIDEBAR_WIDTH
32+
);
33+
2834
const {
2935
onMouseDown: handleStartResize,
3036
size,
3137
onDoubleClick,
3238
} = useResizable({
3339
ref: resizableContainerRef,
34-
initialSize: SECONDARY_SIDEBAR_WIDTH,
40+
initialSize: secondarySidebarWidth,
3541
minWidth: SECONDARY_SIDEBAR_MIN_WIDTH,
3642
maxWidth: SECONDARY_SIDEBAR_MAX_WIDTH,
37-
sizeStorageKey: 'secondary-sidebar-width',
43+
onResizeEnd: newWidth => {
44+
setSecondarySidebarWidth(newWidth);
45+
},
3846
});
3947

4048
const {activePrimaryNavGroup} = useNavContext();

static/app/views/nav/sidebar.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {isActiveSuperuser} from 'sentry/utils/isActiveSuperuser';
1111
import {chonkStyled} from 'sentry/utils/theme/theme.chonk';
1212
import {withChonk} from 'sentry/utils/theme/withChonk';
1313
import useOrganization from 'sentry/utils/useOrganization';
14+
import {useSyncedLocalStorageState} from 'sentry/utils/useSyncedLocalStorageState';
1415
import {PRIMARY_SIDEBAR_WIDTH, SECONDARY_SIDEBAR_WIDTH} from 'sentry/views/nav/constants';
1516
import {useNavContext} from 'sentry/views/nav/context';
1617
import {OrgDropdown} from 'sentry/views/nav/orgDropdown';
@@ -37,6 +38,11 @@ export function Sidebar() {
3738
const isCollapsed = forceExpanded ? false : isCollapsedState;
3839
const {isOpen} = useCollapsedNav();
3940

41+
const [secondarySidebarWidth] = useSyncedLocalStorageState(
42+
'secondary-sidebar-width',
43+
SECONDARY_SIDEBAR_WIDTH
44+
);
45+
4046
useTourModal();
4147

4248
return (
@@ -63,9 +69,15 @@ export function Sidebar() {
6369
animate={isOpen ? 'visible' : 'hidden'}
6470
variants={{
6571
visible: {x: 0},
66-
hidden: {x: -SECONDARY_SIDEBAR_WIDTH - 10},
72+
hidden: {x: -secondarySidebarWidth - 10},
73+
}}
74+
transition={{
75+
type: 'spring',
76+
damping: 50,
77+
stiffness: 700,
78+
bounce: 0,
79+
visualDuration: 0.1,
6780
}}
68-
transition={{duration: 0.15, ease: 'easeOut'}}
6981
data-test-id="collapsed-secondary-sidebar"
7082
data-visible={isOpen}
7183
>

0 commit comments

Comments
 (0)