mirror of
https://github.com/appwrite/console.git
synced 2026-06-06 19:27:48 +00:00
Persist sidebar state
This commit is contained in:
1 parent
4fcf38fe02
commit
d68e48b98c
2 files changed
+39
-2
No files matched your search
@@ -28,7 +28,8 @@
|
||||
import { feedback } from '$lib/stores/feedback';
|
||||
import { DropList } from '$lib/components/index';
|
||||
import { Feedback } from '$lib/components/feedback';
|
||||
import type { ComponentType } from 'svelte';
|
||||
import { type ComponentType, onMount } from 'svelte';
|
||||
import { getSidebarState, updateSidebarState } from '$lib/helpers/sidebar';
|
||||
|
||||
type $$Props = HTMLElement & {
|
||||
state?: 'closed' | 'open' | 'icons';
|
||||
@@ -43,7 +44,7 @@
|
||||
subNavigation?: ComponentType;
|
||||
};
|
||||
|
||||
export let state: $$Props['state'] = 'closed';
|
||||
export let state: $$Props['state'] = 'icons';
|
||||
export let project: $$Props['project'];
|
||||
export let avatar: $$Props['avatar'];
|
||||
export let progressCard: $$Props['progressCard'] = undefined;
|
||||
@@ -59,6 +60,12 @@
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
state = getSidebarState();
|
||||
});
|
||||
|
||||
$: updateSidebarState(state);
|
||||
|
||||
const projectOptions = [
|
||||
{ name: 'Auth', icon: IconUserGroup, slug: 'auth' },
|
||||
{ name: 'Databases', icon: IconDatabase, slug: 'databases' },
|
||||
@@ -72,6 +79,7 @@
|
||||
<div class:only-mobile={project === undefined}>
|
||||
<Sidebar.Base {...$$props} bind:state resizable={subNavigation === undefined}>
|
||||
<div slot="top">
|
||||
{state}
|
||||
<div class="only-mobile top">
|
||||
<div class="icons">
|
||||
<Link.Button
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import { get } from 'svelte/store';
|
||||
import { user } from '$lib/stores/user';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
|
||||
const userPreferences = () => get(user)?.prefs;
|
||||
|
||||
export function updateSidebarState(state: 'closed' | 'open' | 'icons') {
|
||||
if (state === 'open' || state === 'icons') {
|
||||
const currentPrefs = userPreferences();
|
||||
|
||||
const newPrefs = {
|
||||
...currentPrefs,
|
||||
sidebarState: state
|
||||
};
|
||||
|
||||
sdk.forConsole.account.updatePrefs(newPrefs);
|
||||
}
|
||||
}
|
||||
|
||||
export function getSidebarState(): 'open' | 'icons' {
|
||||
const currentPrefs = userPreferences();
|
||||
if (currentPrefs && currentPrefs.sidebarState) {
|
||||
if (currentPrefs.sidebarState === 'open' || currentPrefs.sidebarState === 'icons') {
|
||||
return currentPrefs.sidebarState;
|
||||
}
|
||||
}
|
||||
|
||||
return 'open';
|
||||
}
|
||||
Reference in new issue
Block a user