-
Notifications
You must be signed in to change notification settings - Fork 558
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic tabs to the V3 workspace page
- Loading branch information
Showing
6 changed files
with
103 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<script module> | ||
</script> | ||
|
||
<script lang="ts"> | ||
import { StackService } from '$lib/stacks/stackService.svelte'; | ||
import { getContext } from '@gitbutler/shared/context'; | ||
import type { Tab } from '$lib/tabs/tab'; | ||
type Props = { | ||
projectId: string; | ||
selectedId: string | undefined; | ||
tabs: Tab[]; | ||
}; | ||
const { projectId, selectedId, tabs }: Props = $props(); | ||
const stackService = getContext(StackService); | ||
</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; | ||
&.first { | ||
border-radius: 10px 0 0 0; | ||
} | ||
} | ||
.new-stack { | ||
border: 1px solid var(--clr-border-2); | ||
border-radius: 0 10px 0 0; | ||
padding: 14px 20px; | ||
} | ||
.selected { | ||
background-color: cadetblue; | ||
background: var(--clr-stack-tab-active); | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<script lang="ts"> | ||
import StackTabs from './StackTabs.svelte'; | ||
import { DesktopRedux } from '$lib/redux/store.svelte'; | ||
import { stacksToTabs } from '$lib/tabs/mapping'; | ||
import { getContext } from '@gitbutler/shared/context'; | ||
import { StackService } from '$lib/stacks/stackService.svelte'; | ||
const { projectId, stackId }: { projectId: string; stackId?: string } = $props(); | ||
const stackService = getContext(StackService); | ||
const desktopState = getContext(DesktopRedux); | ||
const rootState = $derived(desktopState.rootState$); | ||
stackService.poll(projectId); | ||
const { data: stacks } = $derived(stackService.select(projectId)(rootState)); | ||
const tabs = $derived(stacksToTabs(stacks)); | ||
$inspect(rootState); | ||
</script> | ||
|
||
<StackTabs {projectId} {tabs} selectedId={stackId} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export type Tab = { | ||
id: string; | ||
name: string; | ||
anchors: string[]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters