Skip to content

Commit

Permalink
feat(editor): Persist sidebar collapsed status preference (#12505)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgrozav authored Jan 8, 2025
1 parent 2775f61 commit dba7d46
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
32 changes: 14 additions & 18 deletions packages/editor-ui/src/components/MainSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,9 @@ onMounted(async () => {
});
}
await nextTick(() => {
uiStore.sidebarMenuCollapsed = window.innerWidth < 900;
fullyExpanded.value = !isCollapsed.value;
});
becomeTemplateCreatorStore.startMonitoringCta();
await nextTick(onResizeEnd);
});
onBeforeUnmount(() => {
Expand Down Expand Up @@ -273,22 +270,21 @@ const handleSelect = (key: string) => {
}
};
const onResize = (event: UIEvent) => {
void callDebounced(onResizeEnd, { debounceTime: 100 }, event);
};
const onResizeEnd = async (event: UIEvent) => {
const browserWidth = (event.target as Window).outerWidth;
await checkWidthAndAdjustSidebar(browserWidth);
};
function onResize() {
void callDebounced(onResizeEnd, { debounceTime: 250 });
}
const checkWidthAndAdjustSidebar = async (width: number) => {
if (width < 900) {
async function onResizeEnd() {
if (window.outerWidth < 900) {
uiStore.sidebarMenuCollapsed = true;
await nextTick();
fullyExpanded.value = !isCollapsed.value;
} else {
uiStore.sidebarMenuCollapsed = uiStore.sidebarMenuCollapsedPreference;
}
};
void nextTick(() => {
fullyExpanded.value = !isCollapsed.value;
});
}
const {
menu,
Expand Down
9 changes: 7 additions & 2 deletions packages/editor-ui/src/stores/ui.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import {
} from './ui.utils';
import { computed, ref } from 'vue';
import type { Connection } from '@vue-flow/core';
import { useLocalStorage } from '@vueuse/core';

let savedTheme: ThemeOption = 'system';

Expand Down Expand Up @@ -151,7 +152,8 @@ export const useUIStore = defineStore(STORES.UI, () => {
});

const modalStack = ref<string[]>([]);
const sidebarMenuCollapsed = ref<boolean>(true);
const sidebarMenuCollapsedPreference = useLocalStorage<boolean>('sidebar.collapsed', false);
const sidebarMenuCollapsed = ref<boolean>(sidebarMenuCollapsedPreference.value);
const currentView = ref<string>('');
const draggable = ref<Draggable>({
isDragging: false,
Expand Down Expand Up @@ -502,7 +504,9 @@ export const useUIStore = defineStore(STORES.UI, () => {
};

const toggleSidebarMenuCollapse = () => {
sidebarMenuCollapsed.value = !sidebarMenuCollapsed.value;
const newCollapsedState = !sidebarMenuCollapsed.value;
sidebarMenuCollapsedPreference.value = newCollapsedState;
sidebarMenuCollapsed.value = newCollapsedState;
};

const getCurlToJson = async (curlCommand: string) => {
Expand Down Expand Up @@ -592,6 +596,7 @@ export const useUIStore = defineStore(STORES.UI, () => {
nodeViewInitialized,
addFirstStepOnLoad,
sidebarMenuCollapsed,
sidebarMenuCollapsedPreference,
bannerStack,
theme,
modalsById,
Expand Down

0 comments on commit dba7d46

Please sign in to comment.