From b0a2ec8dfb0ff62a05d57e6d76d6e9ed5e96a42c Mon Sep 17 00:00:00 2001 From: Arman Date: Thu, 9 Feb 2023 16:36:55 +0100 Subject: [PATCH 1/3] feat: remember overview last tab --- .../console/project-[project]/overview/+layout.svelte | 8 +++++--- src/routes/console/project-[project]/overview/+page.ts | 8 +++++++- src/routes/console/project-[project]/overview/store.ts | 3 +++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/routes/console/project-[project]/overview/+layout.svelte b/src/routes/console/project-[project]/overview/+layout.svelte index 3f7485aa0f..8a0bc4e692 100644 --- a/src/routes/console/project-[project]/overview/+layout.svelte +++ b/src/routes/console/project-[project]/overview/+layout.svelte @@ -25,7 +25,7 @@ import { Container, type UsagePeriods } from '$lib/layout'; import { page } from '$app/stores'; import { onboarding, project } from '../store'; - import { usage } from './store'; + import { selectedTab, usage } from './store'; import { onMount } from 'svelte'; import { afterNavigate } from '$app/navigation'; import { Heading } from '$lib/components'; @@ -203,7 +203,8 @@ + class:is-selected={$page.url.pathname === `${path}/platforms`} + on:click={() => ($selectedTab = 'platforms')}> Platforms @@ -211,7 +212,8 @@ + class:is-selected={$page.url.pathname === `${path}/keys`} + on:click={() => ($selectedTab = 'keys')}> API Keys diff --git a/src/routes/console/project-[project]/overview/+page.ts b/src/routes/console/project-[project]/overview/+page.ts index 2213c6d744..588bddffd7 100644 --- a/src/routes/console/project-[project]/overview/+page.ts +++ b/src/routes/console/project-[project]/overview/+page.ts @@ -1,7 +1,13 @@ import { base } from '$app/paths'; import { redirect } from '@sveltejs/kit'; +import { get } from 'svelte/store'; import type { PageLoad } from './$types'; +import { selectedTab } from './store'; export const load: PageLoad = async ({ params }) => { - throw redirect(302, `${base}/console/project-${params.project}/overview/platforms`); + if (get(selectedTab) === 'keys') { + throw redirect(302, `${base}/console/project-${params.project}/overview/keys`); + } else { + throw redirect(302, `${base}/console/project-${params.project}/overview/platforms`); + } }; diff --git a/src/routes/console/project-[project]/overview/store.ts b/src/routes/console/project-[project]/overview/store.ts index 17c8ad4a17..8ebff5f42f 100644 --- a/src/routes/console/project-[project]/overview/store.ts +++ b/src/routes/console/project-[project]/overview/store.ts @@ -1,6 +1,7 @@ import { sdkForConsole } from '$lib/stores/sdk'; import { cachedStore } from '$lib/helpers/cache'; import type { Models } from '@aw-labs/appwrite-console'; +import { writable, type Writable } from 'svelte/store'; export const usage = cachedStore< Models.UsageProject, @@ -15,3 +16,5 @@ export const usage = cachedStore< } }; }); + +export const selectedTab: Writable<'platforms' | 'keys'> = writable('platforms'); From 438339a406a243cd28af99b26b8f739aa30afd71 Mon Sep 17 00:00:00 2001 From: Arman Date: Thu, 9 Feb 2023 17:10:13 +0100 Subject: [PATCH 2/3] refactor: selected tab is set on pageload --- .../console/project-[project]/overview/+layout.svelte | 6 ++---- src/routes/console/project-[project]/overview/keys/+page.ts | 3 +++ .../console/project-[project]/overview/platforms/+page.ts | 3 +++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/routes/console/project-[project]/overview/+layout.svelte b/src/routes/console/project-[project]/overview/+layout.svelte index 8a0bc4e692..8a3f7dedc3 100644 --- a/src/routes/console/project-[project]/overview/+layout.svelte +++ b/src/routes/console/project-[project]/overview/+layout.svelte @@ -203,8 +203,7 @@ ($selectedTab = 'platforms')}> + class:is-selected={$page.url.pathname === `${path}/platforms`}> Platforms @@ -212,8 +211,7 @@ ($selectedTab = 'keys')}> + class:is-selected={$page.url.pathname === `${path}/keys`}> API Keys diff --git a/src/routes/console/project-[project]/overview/keys/+page.ts b/src/routes/console/project-[project]/overview/keys/+page.ts index 0394783a09..3a04f91f2c 100644 --- a/src/routes/console/project-[project]/overview/keys/+page.ts +++ b/src/routes/console/project-[project]/overview/keys/+page.ts @@ -1,7 +1,10 @@ import { Dependencies } from '$lib/constants'; import { sdkForConsole } from '$lib/stores/sdk'; +import { selectedTab } from '../store'; import type { PageLoad } from './$types'; +selectedTab.set('keys'); + export const load: PageLoad = async ({ params, depends }) => { depends(Dependencies.KEYS); return { diff --git a/src/routes/console/project-[project]/overview/platforms/+page.ts b/src/routes/console/project-[project]/overview/platforms/+page.ts index 80b6a91fe5..de8582eaaf 100644 --- a/src/routes/console/project-[project]/overview/platforms/+page.ts +++ b/src/routes/console/project-[project]/overview/platforms/+page.ts @@ -1,7 +1,10 @@ import { Dependencies } from '$lib/constants'; import { sdkForConsole } from '$lib/stores/sdk'; +import { selectedTab } from '../store'; import type { PageLoad } from './$types'; +selectedTab.set('platforms'); + export const load: PageLoad = async ({ params, depends }) => { depends(Dependencies.PLATFORMS); return { From fdd12428e0b473c622560d7c381b83c3018e3a87 Mon Sep 17 00:00:00 2001 From: Arman Date: Thu, 9 Feb 2023 17:13:18 +0100 Subject: [PATCH 3/3] chore: remove import --- src/routes/console/project-[project]/overview/+layout.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/console/project-[project]/overview/+layout.svelte b/src/routes/console/project-[project]/overview/+layout.svelte index 8a3f7dedc3..3f7485aa0f 100644 --- a/src/routes/console/project-[project]/overview/+layout.svelte +++ b/src/routes/console/project-[project]/overview/+layout.svelte @@ -25,7 +25,7 @@ import { Container, type UsagePeriods } from '$lib/layout'; import { page } from '$app/stores'; import { onboarding, project } from '../store'; - import { selectedTab, usage } from './store'; + import { usage } from './store'; import { onMount } from 'svelte'; import { afterNavigate } from '$app/navigation'; import { Heading } from '$lib/components';