Skip to content

Commit

Permalink
Add basic tabs to the V3 workspace page
Browse files Browse the repository at this point in the history
  • Loading branch information
mtsgrd committed Jan 22, 2025
1 parent db45fea commit 7099a5f
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 21 deletions.
60 changes: 60 additions & 0 deletions apps/desktop/src/components/StackTabs.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<script lang="ts">
import { DesktopRedux } from '$lib/redux/store.svelte';
import { StackService } from '$lib/stacks/stackService.svelte';
import { stacksToTabs } from '$lib/tabs/mapping';
import { getContext } from '@gitbutler/shared/context';
type Props = {
projectId: string;
selectedId: string | undefined;
};
const { projectId, selectedId }: Props = $props();
const stackService = getContext(StackService);
const redux = getContext(DesktopRedux);
const { data: stacks } = $derived(stackService.select(projectId)(redux.rootState$));
const tabs = $derived(stacksToTabs(stacks));
stackService.poll(projectId);
</script>

<div class="tabs">
{#each tabs as tab, i (tab.name)}
{@const first = i === 0}
{@const last = i === tabs.length - 1}
<div class="tab" class:first class:last class:selected={tab.id === selectedId}>
{tab.name}
</div>
{/each}
<button type="button" class="new-stack" onclick={() => stackService.new(projectId)}>+</button>
</div>

<style lang="postcss">
.tabs {
display: flex;
}
.tab {
padding: 12px 14px;
background: var(--clr-stack-tab-inactive);
border: 1px solid var(--clr-border-2);
border-right: none;
border-bottom: none;
&.first {
border-radius: 10px 0 0 0;
}
}
.new-stack {
border: 1px solid var(--clr-border-2);
border-bottom: none;
border-radius: 0 10px 0 0;
padding: 14px 20px;
}
.selected {
background-color: cadetblue;
background: var(--clr-stack-tab-active);
}
</style>
2 changes: 1 addition & 1 deletion apps/desktop/src/lib/routes/routes.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
15 changes: 15 additions & 0 deletions apps/desktop/src/lib/tabs/mapping.ts
Original file line number Diff line number Diff line change
@@ -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)
};
});
}
5 changes: 5 additions & 0 deletions apps/desktop/src/lib/tabs/tab.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type Tab = {
id: string;
name: string;
anchors: string[];
};
3 changes: 3 additions & 0 deletions apps/desktop/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -119,6 +121,7 @@
setContext(StackingLineManagerFactory, data.stackingLineManagerFactory);
setContext(AppSettings, data.appSettings);
setContext(GitHubAuthenticationService, data.githubAuthenticationService);
setContext(StackService, stackService);
setNameNormalizationServiceContext(new IpcNameNormalizationService(invoke));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
<script lang="ts">
import StackTabs from '$components/StackTabs.svelte';
import { SettingsService } from '$lib/config/appSettingsV2';
import { getContext } from '@gitbutler/shared/context';
import Button from '@gitbutler/ui/Button.svelte';
import type { LayoutData } from '../../$types';
import type { PageData } from './$types';
import { goto } from '$app/navigation';
import { page } from '$app/state';
const settingsService = getContext(SettingsService);
const settingsStore = settingsService.appSettings;
const { data }: { data: LayoutData } = $props();
const { data }: { data: PageData } = $props();
const projectId = $derived(data.projectId);
const stackId = $derived(page.params.stackId);
// Redirect to board if we have switched away from V3 feature.
$effect(() => {
Expand All @@ -18,14 +22,14 @@
});
</script>

<section>
<div class="sidebar">
<div class="sidebar-header">
<div class="workspace">
<div class="left">
<div class="left-header">
<div class="text-14 text-semibold">Uncommitted changes</div>
<Button kind="ghost" icon="sidebar-unfold" />
</div>

<div class="sidebar-body">
<div class="left-body">
<svg
width="120"
height="100"
Expand Down Expand Up @@ -72,11 +76,14 @@
</div>
</div>
</div>
<div class="content">Tab Area</div>
</section>
<div class="right">
<StackTabs {projectId} selectedId={stackId} />
<div class="branch"></div>
</div>
</div>

<style>
section {
.workspace {
display: flex;
flex: 1;
align-items: stretch;
Expand All @@ -86,7 +93,7 @@
gap: 14px;
}
.sidebar {
.left {
display: flex;
flex-direction: column;
align-items: center;
Expand All @@ -97,32 +104,32 @@
border: 1px solid var(--clr-border-2);
}
.sidebar-header {
.left-header {
width: 100%;
display: flex;
align-items: center;
justify-content: space-between;
padding: 10px 8px 10px 14px;
}
.sidebar-body {
.left-body {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.content {
.right {
display: flex;
flex: 1;
padding: 8px;
border: 1px solid var(--clr-border-2);
border-radius: var(--radius-ml);
flex-direction: column;
}
background-color: #f3f3f2;
opacity: 0.4;
background-image: radial-gradient(#867e79 0.35000000000000003px, #f3f3f2 0.35000000000000003px);
background-size: 7px 7px;
.branch {
border: 1px solid var(--clr-border-2);
flex: 1;
border-radius: 0 var(--radius-ml) var(--radius-ml);
}
.helper-text {
Expand Down

0 comments on commit 7099a5f

Please sign in to comment.