From 7099a5fda1eb64f266c6e81e39ef48afc6a7bd35 Mon Sep 17 00:00:00 2001 From: Mattias Granlund Date: Wed, 22 Jan 2025 16:20:30 +0100 Subject: [PATCH] Add basic tabs to the V3 workspace page --- apps/desktop/src/components/StackTabs.svelte | 60 +++++++++++++++++++ apps/desktop/src/lib/routes/routes.svelte.ts | 2 +- apps/desktop/src/lib/tabs/mapping.ts | 15 +++++ apps/desktop/src/lib/tabs/tab.ts | 5 ++ apps/desktop/src/routes/+layout.svelte | 3 + .../+page.svelte | 47 ++++++++------- 6 files changed, 111 insertions(+), 21 deletions(-) create mode 100644 apps/desktop/src/components/StackTabs.svelte create mode 100644 apps/desktop/src/lib/tabs/mapping.ts create mode 100644 apps/desktop/src/lib/tabs/tab.ts rename apps/desktop/src/routes/[projectId]/workspace/{[[branchId]] => [[stackId]]}/+page.svelte (84%) diff --git a/apps/desktop/src/components/StackTabs.svelte b/apps/desktop/src/components/StackTabs.svelte new file mode 100644 index 0000000000..7224f5cdc0 --- /dev/null +++ b/apps/desktop/src/components/StackTabs.svelte @@ -0,0 +1,60 @@ + + +
+ {#each tabs as tab, i (tab.name)} + {@const first = i === 0} + {@const last = i === tabs.length - 1} +
+ {tab.name} +
+ {/each} + +
+ + diff --git a/apps/desktop/src/lib/routes/routes.svelte.ts b/apps/desktop/src/lib/routes/routes.svelte.ts index 51d7c79107..b12b66f98e 100644 --- a/apps/desktop/src/lib/routes/routes.svelte.ts +++ b/apps/desktop/src/lib/routes/routes.svelte.ts @@ -22,7 +22,7 @@ export class DesktopRoutesService { return `/${projectId}/workspace`; } isWorkspacePath = $derived( - isUrl<{ projectId: string; branchId?: string }>('/[projectId]/workspace/[[branchId]]') + isUrl<{ projectId: string; branchId?: string }>('/[projectId]/workspace/[[stackId]]') ); branchesPath(projectId: string) { diff --git a/apps/desktop/src/lib/tabs/mapping.ts b/apps/desktop/src/lib/tabs/mapping.ts new file mode 100644 index 0000000000..c8b78ae711 --- /dev/null +++ b/apps/desktop/src/lib/tabs/mapping.ts @@ -0,0 +1,15 @@ +import type { Stack } from '$lib/stacks/stack'; +import type { Tab } from './tab'; + +export function stacksToTabs(stacks: Stack[] | undefined): Tab[] { + if (!stacks) { + return []; + } + return stacks.map((stack) => { + return { + id: stack.id, + name: stack.branchNames[0] || 'new branch', + anchors: stack.branchNames.slice(1) + }; + }); +} diff --git a/apps/desktop/src/lib/tabs/tab.ts b/apps/desktop/src/lib/tabs/tab.ts new file mode 100644 index 0000000000..46cf8c7a15 --- /dev/null +++ b/apps/desktop/src/lib/tabs/tab.ts @@ -0,0 +1,5 @@ +export type Tab = { + id: string; + name: string; + anchors: string[]; +}; diff --git a/apps/desktop/src/routes/+layout.svelte b/apps/desktop/src/routes/+layout.svelte index 38350cb191..e70722b95f 100644 --- a/apps/desktop/src/routes/+layout.svelte +++ b/apps/desktop/src/routes/+layout.svelte @@ -38,6 +38,7 @@ import { DesktopRoutesService } from '$lib/routes/routes.svelte'; import { setSecretsService } from '$lib/secrets/secretsService'; import { SETTINGS, loadUserSettings } from '$lib/settings/userSettings'; + import { StackService } from '$lib/stacks/stackService.svelte'; import { UpdaterService } from '$lib/updater/updater'; import { User } from '$lib/user/user'; import { UserService } from '$lib/user/userService'; @@ -73,6 +74,7 @@ const appState = new AppState(); const desktopState = new DesktopRedux(data.tauri); + const stackService = new StackService(desktopState); const feedService = new FeedService(data.cloud, appState.appDispatch); const organizationService = new OrganizationService(data.cloud, appState.appDispatch); const cloudUserService = new CloudUserService(data.cloud, appState.appDispatch); @@ -119,6 +121,7 @@ setContext(StackingLineManagerFactory, data.stackingLineManagerFactory); setContext(AppSettings, data.appSettings); setContext(GitHubAuthenticationService, data.githubAuthenticationService); + setContext(StackService, stackService); setNameNormalizationServiceContext(new IpcNameNormalizationService(invoke)); diff --git a/apps/desktop/src/routes/[projectId]/workspace/[[branchId]]/+page.svelte b/apps/desktop/src/routes/[projectId]/workspace/[[stackId]]/+page.svelte similarity index 84% rename from apps/desktop/src/routes/[projectId]/workspace/[[branchId]]/+page.svelte rename to apps/desktop/src/routes/[projectId]/workspace/[[stackId]]/+page.svelte index 87fb97b953..a0098e3e79 100644 --- a/apps/desktop/src/routes/[projectId]/workspace/[[branchId]]/+page.svelte +++ b/apps/desktop/src/routes/[projectId]/workspace/[[stackId]]/+page.svelte @@ -1,14 +1,18 @@ -
-
+
+ +
+
+