Remove some isUnapplied booleans where not needed

This commit is contained in:
Caleb Owens 2024-07-11 12:10:06 +02:00
parent c982e78567
commit f4c817ed10
No known key found for this signature in database
6 changed files with 60 additions and 119 deletions

24
.vscode/settings.json vendored
View File

@ -6,10 +6,28 @@
"prettier.configPath": ".prettierrc.mjs",
"prettier.useEditorConfig": false,
"editor.defaultFormatter": null,
"rust-analyzer.check.command": "clippy",
"rust-analyzer.check.allTargets": true,
"rust-analyzer.check.features": "all",
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer"
},
"rust-analyzer.check.command": "clippy",
"rust-analyzer.check.allTargets": true,
"rust-analyzer.check.features": "all"
"[svelte]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[css]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}

View File

@ -30,7 +30,6 @@
import type { Persisted } from '$lib/persisted/persisted';
import type { Writable } from 'svelte/store';
export let isUnapplied = false;
export let isLaneCollapsed: Persisted<boolean>;
export let commitBoxOpen: Writable<boolean>;
@ -95,7 +94,6 @@
{#if $isLaneCollapsed}
<div class="collapsed-lane-container">
<BranchHeader
{isUnapplied}
uncommittedChanges={branch.files.length}
bind:isLaneCollapsed
on:action={(e) => {
@ -125,7 +123,6 @@
class="branch-card__contents"
>
<BranchHeader
{isUnapplied}
bind:isLaneCollapsed
on:action={(e) => {
if (e.detail === 'generate-branch-name') {
@ -143,8 +140,8 @@
<div class="branch-card__files">
<Dropzones>
<BranchFiles
isUnapplied={false}
files={branch.files}
{isUnapplied}
showCheckboxes={$commitBoxOpen}
allowMultiple
/>
@ -199,8 +196,8 @@
{/if}
<div class="card-commits">
<CommitList {isUnapplied} />
<BranchFooter {isUnapplied} />
<CommitList isUnapplied={false} />
<BranchFooter />
</div>
</div>
</div>

View File

@ -14,8 +14,6 @@
} from '$lib/vbranches/contexts';
import { Branch } from '$lib/vbranches/types';
export let isUnapplied: boolean;
const branchController = getContext(BranchController);
const promptService = getContext(PromptService);
const branch = getContextStore(Branch);
@ -38,7 +36,7 @@
$localCommits.length > 0 || $localAndRemoteCommits.length > 0 || $remoteCommits.length > 0;
</script>
{#if !isUnapplied && hasCommits}
{#if hasCommits}
<div
class="actions"
class:sticky={canBePushed}

View File

@ -3,11 +3,9 @@
import BranchLabel from './BranchLabel.svelte';
import BranchLaneContextMenu from './BranchLaneContextMenu.svelte';
import PullRequestButton from '../pr/PullRequestButton.svelte';
import { Project } from '$lib/backend/projects';
import { BranchService } from '$lib/branches/service';
import ContextMenu from '$lib/components/contextmenu/ContextMenu.svelte';
import { GitHubService } from '$lib/github/service';
import { showError } from '$lib/notifications/toasts';
import Button from '$lib/shared/Button.svelte';
import Icon from '$lib/shared/Icon.svelte';
import { getContext, getContextStore } from '$lib/utils/context';
@ -16,16 +14,13 @@
import { BaseBranch, Branch } from '$lib/vbranches/types';
import type { PullRequest } from '$lib/github/types';
import type { Persisted } from '$lib/persisted/persisted';
import { goto } from '$app/navigation';
export let uncommittedChanges = 0;
export let isUnapplied = false;
export let isLaneCollapsed: Persisted<boolean>;
const branchController = getContext(BranchController);
const githubService = getContext(GitHubService);
const branchStore = getContextStore(Branch);
const project = getContext(Project);
const branchService = getContext(BranchService);
const baseBranch = getContextStore(BaseBranch);
@ -35,8 +30,6 @@
let contextMenu: ContextMenu;
let meatballButtonEl: HTMLDivElement;
let isApplying = false;
let isDeleting = false;
let isLoading: boolean;
let isTargetBranchAnimated = false;
@ -121,7 +114,6 @@
<div class="collapsed-lane__info__details">
<ActiveBranchStatus
{isUnapplied}
{hasIntegratedCommits}
remoteExists={!!branch.upstream}
isLaneCollapsed={$isLaneCollapsed}
@ -143,21 +135,17 @@
class:header_target-branch-animation={isTargetBranchAnimated && branch.selectedForChanges}
>
<div class="header__info-wrapper">
{#if !isUnapplied}
<div class="draggable" data-drag-handle>
<Icon name="draggable" />
</div>
{/if}
<div class="draggable" data-drag-handle>
<Icon name="draggable" />
</div>
<div class="header__info">
<BranchLabel
name={branch.name}
on:change={(e) => handleBranchNameChange(e.detail.name)}
disabled={isUnapplied}
/>
<div class="header__remote-branch">
<ActiveBranchStatus
{isUnapplied}
{hasIntegratedCommits}
remoteExists={!!branch.upstream}
isLaneCollapsed={$isLaneCollapsed}
@ -189,7 +177,6 @@
help="New changes will land here"
icon="target"
clickable={false}
disabled={isUnapplied}
>
Default branch
</Button>
@ -199,7 +186,6 @@
outline
help="When selected, new changes will land here"
icon="target"
disabled={isUnapplied}
on:click={async () => {
isTargetBranchAnimated = true;
await branchController.setSelectedForChanges(branch.id);
@ -211,73 +197,24 @@
</div>
<div class="relative">
{#if isUnapplied}
<div class="header__buttons">
{#if !hasPullRequest}
<PullRequestButton
on:exec={async (e) => await createPr({ draft: e.detail.action === 'draft' })}
loading={isLoading}
/>
{/if}
<Button
bind:el={meatballButtonEl}
style="ghost"
outline
help="Deletes the local virtual branch (only)"
icon="bin-small"
loading={isDeleting}
on:click={async () => {
isDeleting = true;
try {
await branchController.deleteBranch(branch.id);
goto(`/${project.id}/board`);
} catch (err) {
showError('Failed to delete branch', err);
console.error(err);
} finally {
isDeleting = false;
}
icon="kebab"
on:click={() => {
contextMenu.toggle();
}}
>
Delete
</Button>
<Button
style="ghost"
outline
help="Restores these changes into your working directory"
icon="plus-small"
loading={isApplying}
on:click={async () => {
isApplying = true;
try {
await branchController.applyBranch(branch.id);
goto(`/${project.id}/board`);
} catch (err) {
showError('Failed to apply branch', err);
console.error(err);
} finally {
isApplying = false;
}
}}
>
Apply
</Button>
{:else}
<div class="header__buttons">
{#if !hasPullRequest}
<PullRequestButton
on:exec={async (e) => await createPr({ draft: e.detail.action === 'draft' })}
loading={isLoading}
/>
{/if}
<Button
bind:el={meatballButtonEl}
style="ghost"
outline
icon="kebab"
on:click={() => {
contextMenu.toggle();
}}
/>
<BranchLaneContextMenu
bind:contextMenuEl={contextMenu}
{isUnapplied}
target={meatballButtonEl}
/>
</div>
{/if}
/>
<BranchLaneContextMenu bind:contextMenuEl={contextMenu} target={meatballButtonEl} />
</div>
</div>
</div>
</div>

View File

@ -23,7 +23,6 @@
import { slide } from 'svelte/transition';
export let branch: Branch;
export let isUnapplied = false;
const ownershipStore = createContextStore(Ownership, Ownership.fromBranch(branch));
// TODO: Update store here rather than reset it
@ -72,7 +71,7 @@
</script>
<div class="wrapper" data-tauri-drag-region>
<BranchCard {isUnapplied} {commitBoxOpen} bind:isLaneCollapsed />
<BranchCard {commitBoxOpen} bind:isLaneCollapsed />
{#await $selectedFile then selected}
{#if selected}
@ -83,11 +82,11 @@
style:width={`${fileWidth || $defaultFileWidthRem}rem`}
>
<FileCard
isUnapplied={false}
conflicted={selected.conflicted}
file={selected}
{isUnapplied}
readonly={selected instanceof RemoteFile}
selectable={$commitBoxOpen && !isUnapplied}
selectable={$commitBoxOpen}
on:close={() => {
fileIdSelection.clear();
}}

View File

@ -20,7 +20,6 @@
export let contextMenuEl: ContextMenu;
export let target: HTMLElement;
export let isUnapplied = false;
const user = getContextStore(User);
const project = getContext(Project);
@ -167,26 +166,22 @@
<ContextMenu bind:this={contextMenuEl} {target}>
<ContextMenuSection>
{#if !isUnapplied}
<ContextMenuItem
label="Collapse lane"
on:click={() => {
dispatch('action', 'collapse');
contextMenuEl.close();
}}
/>
{/if}
<ContextMenuItem
label="Collapse lane"
on:click={() => {
dispatch('action', 'collapse');
contextMenuEl.close();
}}
/>
</ContextMenuSection>
<ContextMenuSection>
{#if !isUnapplied}
<ContextMenuItem
label="Unapply"
on:click={() => {
tryUnapplyBranch();
contextMenuEl.close();
}}
/>
{/if}
<ContextMenuItem
label="Unapply"
on:click={() => {
tryUnapplyBranch();
contextMenuEl.close();
}}
/>
<ContextMenuItem
label="Delete"
@ -210,16 +205,13 @@
dispatch('action', 'generate-branch-name');
contextMenuEl.close();
}}
disabled={isUnapplied ||
!($aiGenEnabled && aiConfigurationValid) ||
branch.files?.length === 0}
disabled={!($aiGenEnabled && aiConfigurationValid) || branch.files?.length === 0}
/>
</ContextMenuSection>
<ContextMenuSection>
<ContextMenuItem
label="Set remote branch name"
disabled={isUnapplied}
on:click={() => {
console.log('Set remote branch name');