Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MS] Remember the state of the sidebar #9315

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion client/src/components/sidebar/SidebarMenuList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
lines="none"
class="list-sidebar-header title-h5"
:class="isContentVisible ? 'open' : 'close'"
@click="isContentVisible = !isContentVisible"
@click="setContentVisible(!isContentVisible)"
>
<div class="list-sidebar-header-title">
<ion-icon
Expand Down Expand Up @@ -43,6 +43,22 @@ defineProps<{
title: Translatable;
icon: string;
}>();

defineExpose({
isContentVisible,
setContentVisible,
});

const emits = defineEmits<{
(event: 'visibilityChanged', visibility: boolean): void;
}>();

function setContentVisible(visible: boolean, blockEvent = false): void {
isContentVisible.value = visible;
if (!blockEvent) {
emits('visibilityChanged', isContentVisible.value);
}
}
</script>

<style scoped lang="scss">
Expand Down
63 changes: 55 additions & 8 deletions client/src/views/sidebar-menu/SidebarMenuPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,12 @@
<!-- list of favorite workspaces -->
<!-- show only favorites -->
<sidebar-menu-list
v-if="favoritesWorkspaces.length > 0"
:title="'SideMenu.favorites'"
v-show="favoritesWorkspaces.length > 0"
title="SideMenu.favorites"
:icon="star"
class="favorites"
ref="favoritesMenu"
@visibility-changed="onFavoritesMenuVisibilityChanged"
>
<sidebar-workspace-item
v-for="workspace in favoritesWorkspaces"
Expand All @@ -180,9 +182,11 @@

<!-- list of workspaces -->
<sidebar-menu-list
:title="'SideMenu.workspaces'"
title="SideMenu.workspaces"
:icon="business"
class="workspaces"
ref="workspacesMenu"
@visibility-changed="onWorkspacesMenuVisibilityChanged"
>
<ion-text
class="body list-sidebar__no-workspace"
Expand Down Expand Up @@ -392,14 +396,32 @@ const isTrialOrg = ref(false);
const expirationDuration = ref<Duration | undefined>(undefined);
const isExpired = ref(false);
const loggedInDevices = ref<LoggedInDeviceInfo[]>([]);
const favoritesMenu = ref<typeof SidebarMenuList>();
const workspacesMenu = ref<typeof SidebarMenuList>();
let timeoutId: number | undefined = undefined;

const MIN_WIDTH = 150;
const MAX_WIDTH = 370;

const watchSidebarWidthCancel = watch(computedWidth, (value: number) => {
const watchSidebarWidthCancel = watch(computedWidth, async (value: number) => {
sidebarWidthProperty.value = `${value}px`;
// set toast offset
setToastOffset(value);

if (timeoutId !== undefined) {
clearTimeout(timeoutId);
}
timeoutId = window.setTimeout(async () => {
await storageManager.updateComponentData<SidebarSavedData>(
SIDEBAR_MENU_DATA_KEY,
{
width: value < MIN_WIDTH ? storedWidth.value : computedWidth.value,
hidden: value < MIN_WIDTH,
},
SidebarDefaultData,
);
timeoutId = undefined;
}, 2000);
});

async function goToWorkspace(workspaceHandle: WorkspaceHandle): Promise<void> {
Expand Down Expand Up @@ -455,6 +477,10 @@ onMounted(async () => {
computedWidth.value = savedSidebarData.width;
}
sidebarWidthProperty.value = `${computedWidth.value}px`;
if (workspacesMenu.value && favoritesMenu.value) {
workspacesMenu.value.setContentVisible(savedSidebarData.workspacesVisible, true);
favoritesMenu.value.setContentVisible(savedSidebarData.favoritesVisible, true);
}

const connInfo = getConnectionInfo();
if (connInfo) {
Expand Down Expand Up @@ -484,10 +510,11 @@ onUnmounted(async () => {
if (eventDistributorCbId) {
eventDistributor.removeCallback(eventDistributorCbId);
}
await storageManager.storeComponentData<SidebarSavedData>(SIDEBAR_MENU_DATA_KEY, {
width: computedWidth.value < MIN_WIDTH ? storedWidth.value : computedWidth.value,
hidden: computedWidth.value < MIN_WIDTH,
});
// Clear it. Worst case, some things will not be saved, but it's better
// than to risk accessing something no longer available.
if (timeoutId !== undefined) {
clearTimeout(timeoutId);
}
watchSidebarWidthCancel();
setToastOffset(0);
});
Expand Down Expand Up @@ -550,6 +577,26 @@ async function openRecentFile(file: RecentFile): Promise<void> {
async function removeRecentFile(file: RecentFile): Promise<void> {
recentFileManager.removeFile(file);
}

async function onWorkspacesMenuVisibilityChanged(visible: boolean): Promise<void> {
await storageManager.updateComponentData<SidebarSavedData>(
SIDEBAR_MENU_DATA_KEY,
{
workspacesVisible: visible,
},
SidebarDefaultData,
);
}

async function onFavoritesMenuVisibilityChanged(visible: boolean): Promise<void> {
await storageManager.updateComponentData<SidebarSavedData>(
SIDEBAR_MENU_DATA_KEY,
{
favoritesVisible: visible,
},
SidebarDefaultData,
);
}
</script>

<style lang="scss" scoped>
Expand Down
9 changes: 8 additions & 1 deletion client/src/views/sidebar-menu/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@
export interface SidebarSavedData {
width?: number;
hidden?: boolean;
workspacesVisible?: boolean;
favoritesVisible?: boolean;
}

export const SIDEBAR_MENU_DATA_KEY = 'SidebarMenu';

export const SidebarDefaultData: Required<SidebarSavedData> = { width: 300, hidden: false };
export const SidebarDefaultData: Required<SidebarSavedData> = {
width: 300,
hidden: false,
workspacesVisible: true,
favoritesVisible: true,
};
Loading