feat: add toggle button to stash/unstash branch changes in the UI

This commit is contained in:
Mattias Granlund 2024-01-26 11:52:40 +01:00
parent 85ce4a7b40
commit 23e7cd7409
2 changed files with 21 additions and 47 deletions

View File

@ -1,15 +1,19 @@
<script lang="ts">
import { tooltip } from '$lib/utils/tooltip';
export let name = '';
export let small = false;
export let disabled = false;
export let checked = false;
export let value = '';
export let help = '';
</script>
<input
on:click|stopPropagation
on:change
use:tooltip={help}
type="checkbox"
class="toggle"
class:small

View File

@ -12,6 +12,7 @@
import Button from '$lib/components/Button.svelte';
import toast from 'svelte-french-toast';
import { tooltip } from '$lib/utils/tooltip';
import Toggle from '$lib/components/Toggle.svelte';
export let readonly = false;
export let branch: Branch;
@ -26,7 +27,6 @@
let meatballButton: HTMLDivElement;
let visible = false;
let container: HTMLDivElement;
let isApplying = false;
function handleBranchNameChange() {
branchController.updateBranchName(branch.id, branch.name);
@ -160,51 +160,20 @@
Set as default
</Button>
{/if}
{#if !readonly}
<Button
icon="cross-small"
color="primary"
kind="outlined"
help="Stashes these changes away from your working directory"
loading={isApplying}
on:click={async () => {
isApplying = true;
try {
await branchController.unapplyBranch(branch.id);
} catch (e) {
const err = 'Failed to apply branch';
toast.error(err);
console.error(err, e);
} finally {
isApplying = false;
}
}}
>
Unapply
</Button>
{:else}
<Button
help="Restores these changes into your working directory"
icon="plus-small"
color="primary"
kind="outlined"
loading={isApplying}
on:click={async () => {
isApplying = true;
try {
await branchController.applyBranch(branch.id);
} catch (e) {
const err = 'Failed to apply branch';
toast.error(err);
console.error(err, e);
} finally {
isApplying = false;
}
}}
>
Apply
</Button>
{/if}
<Toggle
checked={!readonly}
help="Toggle to stash branch"
on:change={async () => {
try {
if (readonly) await branchController.applyBranch(branch.id);
else await branchController.unapplyBranch(branch.id);
} catch (e) {
const err = 'Failed to apply/unapply branch';
toast.error(err);
console.error(err, e);
}
}}
/>
</div>
<div class="relative" bind:this={meatballButton}>
<Button
@ -288,7 +257,8 @@
.header__buttons {
display: flex;
position: relative;
gap: var(--space-4);
align-items: center;
gap: var(--space-10);
}
.header__label {
display: flex;