Browse Source

fix(nc-gui): sidebar width issue if user hide & reload page (#8972)

pull/8973/head
Ramesh Mane 5 months ago committed by GitHub
parent
commit
1fc030ea27
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 7
      packages/nc-gui/components/dashboard/View.vue
  2. 7
      packages/nc-gui/composables/useGlobal/actions.ts
  3. 5
      packages/nc-gui/composables/useGlobal/state.ts
  4. 7
      packages/nc-gui/composables/useGlobal/types.ts
  5. 6
      packages/nc-gui/store/sidebar.ts

7
packages/nc-gui/components/dashboard/View.vue

@ -42,7 +42,7 @@ const mobileNormalizedContentSize = computed(() => {
watch(currentSidebarSize, () => { watch(currentSidebarSize, () => {
leftSidebarWidthPercent.value = (currentSidebarSize.value / viewportWidth.value) * 100 leftSidebarWidthPercent.value = (currentSidebarSize.value / viewportWidth.value) * 100
setLeftSidebarSize(currentSidebarSize.value) setLeftSidebarSize({ current: currentSidebarSize.value, old: sideBarSize.value.old })
}) })
const sidebarWidth = computed(() => (isMobileMode.value ? viewportWidth.value : sideBarSize.value.old)) const sidebarWidth = computed(() => (isMobileMode.value ? viewportWidth.value : sideBarSize.value.old))
@ -102,6 +102,11 @@ function handleMouseMove(e: MouseEvent) {
function onWindowResize(e?: any): void { function onWindowResize(e?: any): void {
viewportWidth.value = window.innerWidth viewportWidth.value = window.innerWidth
// if user hide sidebar and refresh the page then sidebar will be visible again so we have to set sidebar width
if (!e && isLeftSidebarOpen.value && !sideBarSize.value.current && !isMobileMode.value) {
currentSidebarSize.value = sideBarSize.value.old
}
leftSidebarWidthPercent.value = (currentSidebarSize.value / viewportWidth.value) * 100 leftSidebarWidthPercent.value = (currentSidebarSize.value / viewportWidth.value) * 100
// if sidebar width is greater than normalized width and this function is called from window resize event (not from template) update left sidebar width // if sidebar width is greater than normalized width and this function is called from window resize event (not from template) update left sidebar width

7
packages/nc-gui/composables/useGlobal/actions.ts

@ -160,8 +160,11 @@ export function useGlobalActions(state: State): Actions {
state.gridViewPageSize.value = pageSize state.gridViewPageSize.value = pageSize
} }
const setLeftSidebarSize = (size: number) => { const setLeftSidebarSize = ({ old, current }: { old?: number; current?: number }) => {
state.leftSidebarSize.value = size state.leftSidebarSize.value = {
old: old ?? state.leftSidebarSize.value.old,
current: current ?? state.leftSidebarSize.value.current,
}
} }
return { return {

5
packages/nc-gui/composables/useGlobal/state.ts

@ -58,7 +58,10 @@ export function useGlobalState(storageKey = 'nocodb-gui-v2'): State {
isMobileMode: null, isMobileMode: null,
lastOpenedWorkspaceId: null, lastOpenedWorkspaceId: null,
gridViewPageSize: 25, gridViewPageSize: 25,
leftSidebarSize: INITIAL_LEFT_SIDEBAR_WIDTH, leftSidebarSize: {
old: INITIAL_LEFT_SIDEBAR_WIDTH,
current: INITIAL_LEFT_SIDEBAR_WIDTH,
},
} }
/** saves a reactive state, any change to these values will write/delete to localStorage */ /** saves a reactive state, any change to these values will write/delete to localStorage */

7
packages/nc-gui/composables/useGlobal/types.ts

@ -53,7 +53,10 @@ export interface StoredState {
isMobileMode: boolean | null isMobileMode: boolean | null
lastOpenedWorkspaceId: string | null lastOpenedWorkspaceId: string | null
gridViewPageSize: number gridViewPageSize: number
leftSidebarSize: number leftSidebarSize: {
old: number
current: number
}
} }
export type State = ToRefs<Omit<StoredState, 'token'>> & { export type State = ToRefs<Omit<StoredState, 'token'>> & {
@ -90,7 +93,7 @@ export interface Actions {
getBaseUrl: (workspaceId: string) => string | undefined getBaseUrl: (workspaceId: string) => string | undefined
getMainUrl: (workspaceId: string) => string | undefined getMainUrl: (workspaceId: string) => string | undefined
setGridViewPageSize: (pageSize: number) => void setGridViewPageSize: (pageSize: number) => void
setLeftSidebarSize: (size: number) => void setLeftSidebarSize: (params: { old?: number; current?: number }) => void
} }
export type ReadonlyState = Readonly<Pick<State, 'token' | 'user'>> & Omit<State, 'token' | 'user'> export type ReadonlyState = Readonly<Pick<State, 'token' | 'user'>> & Omit<State, 'token' | 'user'>

6
packages/nc-gui/store/sidebar.ts

@ -6,7 +6,7 @@ export const useSidebarStore = defineStore('sidebarStore', () => {
const isViewPortMobile = () => { const isViewPortMobile = () => {
return width.value < MAX_WIDTH_FOR_MOBILE_MODE return width.value < MAX_WIDTH_FOR_MOBILE_MODE
} }
const { isMobileMode, leftSidebarSize: _leftSidebarSize, setLeftSidebarSize } = useGlobal() const { isMobileMode, leftSidebarSize: _leftSidebarSize } = useGlobal()
const tablesStore = useTablesStore() const tablesStore = useTablesStore()
const _isLeftSidebarOpen = ref(!isViewPortMobile()) const _isLeftSidebarOpen = ref(!isViewPortMobile())
@ -22,8 +22,8 @@ export const useSidebarStore = defineStore('sidebarStore', () => {
const isRightSidebarOpen = ref(true) const isRightSidebarOpen = ref(true)
const leftSideBarSize = ref({ const leftSideBarSize = ref({
old: _leftSidebarSize.value ?? INITIAL_LEFT_SIDEBAR_WIDTH, old: _leftSidebarSize.value?.old ?? INITIAL_LEFT_SIDEBAR_WIDTH,
current: isViewPortMobile() ? 0 : _leftSidebarSize.value ?? INITIAL_LEFT_SIDEBAR_WIDTH, current: isViewPortMobile() ? 0 : _leftSidebarSize.value?.current ?? INITIAL_LEFT_SIDEBAR_WIDTH,
}) })
const leftSidebarWidthPercent = ref((leftSideBarSize.value.current / width.value) * 100) const leftSidebarWidthPercent = ref((leftSideBarSize.value.current / width.value) * 100)

Loading…
Cancel
Save