fix: Reset sidebar to show expanded list when refreshing the page (#13229)
Previously, the sidebar remembered which section was expanded using session storage. This caused a confusing experience where the sidebar would collapse on page refresh. With this update, the session storage dependency is removed, and the sidebar would expand based on the current active page, which gives a cleaner UX.
This commit is contained in:
@@ -1,12 +1,11 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { h, computed, onMounted } from 'vue';
|
import { h, ref, computed, onMounted } from 'vue';
|
||||||
import { provideSidebarContext } from './provider';
|
import { provideSidebarContext } from './provider';
|
||||||
import { useAccount } from 'dashboard/composables/useAccount';
|
import { useAccount } from 'dashboard/composables/useAccount';
|
||||||
import { useKbd } from 'dashboard/composables/utils/useKbd';
|
import { useKbd } from 'dashboard/composables/utils/useKbd';
|
||||||
import { useMapGetter } from 'dashboard/composables/store';
|
import { useMapGetter } from 'dashboard/composables/store';
|
||||||
import { useStore } from 'vuex';
|
import { useStore } from 'vuex';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { useStorage } from '@vueuse/core';
|
|
||||||
import { useSidebarKeyboardShortcuts } from './useSidebarKeyboardShortcuts';
|
import { useSidebarKeyboardShortcuts } from './useSidebarKeyboardShortcuts';
|
||||||
import { vOnClickOutside } from '@vueuse/components';
|
import { vOnClickOutside } from '@vueuse/components';
|
||||||
import { emitter } from 'shared/helpers/mitt';
|
import { emitter } from 'shared/helpers/mitt';
|
||||||
@@ -55,14 +54,7 @@ const toggleShortcutModalFn = show => {
|
|||||||
|
|
||||||
useSidebarKeyboardShortcuts(toggleShortcutModalFn);
|
useSidebarKeyboardShortcuts(toggleShortcutModalFn);
|
||||||
|
|
||||||
// We're using localStorage to store the expanded item in the sidebar
|
const expandedItem = ref(null);
|
||||||
// This helps preserve context when navigating between portal and dashboard layouts
|
|
||||||
// and also when the user refreshes the page
|
|
||||||
const expandedItem = useStorage(
|
|
||||||
'next-sidebar-expanded-item',
|
|
||||||
null,
|
|
||||||
sessionStorage
|
|
||||||
);
|
|
||||||
|
|
||||||
const setExpandedItem = name => {
|
const setExpandedItem = name => {
|
||||||
expandedItem.value = expandedItem.value === name ? null : name;
|
expandedItem.value = expandedItem.value === name ? null : name;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { computed, onMounted, nextTick } from 'vue';
|
import { computed, onMounted, watch, nextTick } from 'vue';
|
||||||
import { useSidebarContext } from './provider';
|
import { useSidebarContext } from './provider';
|
||||||
import { useRoute, useRouter } from 'vue-router';
|
import { useRoute, useRouter } from 'vue-router';
|
||||||
import Policy from 'dashboard/components/policy.vue';
|
import Policy from 'dashboard/components/policy.vue';
|
||||||
@@ -126,6 +126,16 @@ onMounted(async () => {
|
|||||||
setExpandedItem(props.name);
|
setExpandedItem(props.name);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
watch(
|
||||||
|
hasActiveChild,
|
||||||
|
hasNewActiveChild => {
|
||||||
|
if (hasNewActiveChild && !isExpanded.value) {
|
||||||
|
setExpandedItem(props.name);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ once: true }
|
||||||
|
);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- eslint-disable-next-line vue/no-root-v-if -->
|
<!-- eslint-disable-next-line vue/no-root-v-if -->
|
||||||
|
|||||||
Reference in New Issue
Block a user