Skip to content

Commit

Permalink
feat: wire up updateSeriesDescription
Browse files Browse the repository at this point in the history
  • Loading branch information
ndom91 committed Oct 4, 2024
1 parent eb1870e commit fdb7dc2
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 19 deletions.
3 changes: 1 addition & 2 deletions apps/desktop/src/lib/branch/StackingBranchDescription.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
interface Props {
value: string;
disabled?: boolean;
onChange?: (value: string) => void;
class?: string;
onChange?: (value: string) => Promise<void>;
}
let { value, disabled = false, onChange }: Props = $props();
Expand Down
24 changes: 13 additions & 11 deletions apps/desktop/src/lib/branch/StackingBranchHeader.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@
interface Props {
name: string;
description?: string;
upstreamName?: string;
commits: DetailedCommit[];
}
const { name, upstreamName, commits }: Props = $props();
const { name, description, upstreamName, commits }: Props = $props();
let isLoading = $state(false);
let descriptionVisible = $state(false);
let descriptionVisible = $state(!!description);
const branchStore = getContextStore(VirtualBranch);
const branch = $derived($branchStore);
Expand Down Expand Up @@ -162,12 +163,15 @@
branchController.updateBranchName(branch.id, title);
}
function editDescription(_description: string) {
// branchController.updateBranchDescription(branch.id, description);
async function editDescription(description: string) {
await branchController.updateSeriesDescription(branch.id, name, description);
}
function addDescription() {
descriptionVisible = true;
async function toggleDescription() {
descriptionVisible = !descriptionVisible;
if (!descriptionVisible) {
await branchController.updateSeriesDescription(branch.id, name, '');
}
}
</script>

Expand Down Expand Up @@ -203,17 +207,15 @@
bind:contextMenuEl={contextMenu}
target={meatballButtonEl}
headName={name}
{addDescription}
{description}
{toggleDescription}
/>
</div>
</div>
{#if descriptionVisible}
<div class="branch-info__description">
<div class="branch-action__line" style:--bg-color={lineColor}></div>
<StackingBranchDescription
value={branch.description}
onChange={(description) => editDescription(description)}
/>
<StackingBranchDescription value={description ?? ''} onChange={editDescription} />
</div>
{/if}
<div class="branch-action">
Expand Down
19 changes: 14 additions & 5 deletions apps/desktop/src/lib/branch/StackingBranchHeaderContextMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@
contextMenuEl?: ReturnType<typeof ContextMenu>;
target?: HTMLElement;
headName: string;
addDescription: () => void;
description?: string;
toggleDescription: () => Promise<void>;
}
let { contextMenuEl = $bindable(), target, headName, addDescription }: Props = $props();
let {
contextMenuEl = $bindable(),
target,
headName,
description,
toggleDescription
}: Props = $props();
const branchStore = getContextStore(VirtualBranch);
const branchController = getContext(BranchController);
Expand All @@ -25,16 +32,18 @@
let renameSeriesModal: Modal;
let newHeadName: string = $state(headName);
let isDeleting = $state(false);
let showDescription = $state(!!description);
const branch = $derived($branchStore);
</script>

<ContextMenu bind:this={contextMenuEl} {target}>
<ContextMenuSection>
<ContextMenuItem
label="Add description"
on:click={() => {
addDescription();
label={`${!showDescription ? 'Add' : 'Remove'} description`}
on:click={async () => {
await toggleDescription();
showDescription = !showDescription;
contextMenuEl?.close();
}}
/>
Expand Down
1 change: 1 addition & 0 deletions apps/desktop/src/lib/stack/StackSeries.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<StackingBranchHeader
commits={currentSeries.patches}
name={currentSeries.branchName}
description={currentSeries.description}
upstreamName={currentSeries.name}
/>
<StackingCommitList
Expand Down
15 changes: 14 additions & 1 deletion apps/desktop/src/lib/vbranches/branchController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,20 @@ export class BranchController {
newHeadName
});
} catch (err) {
showError('Failed to update remote name', err);
showError('Failed to update series name', err);
}
}

async updateSeriesDescription(branchId: string, headName: string, description: string) {
try {
await invoke<void>('update_series_description', {
projectId: this.projectId,
branchId,
headName,
description
});
} catch (err) {
showError('Failed to update series description', err);
}
}

Expand Down

0 comments on commit fdb7dc2

Please sign in to comment.