Skip to content

Commit e688e35

Browse files
committed
Branch listings: Display the author information + refresh the listing when needed
Display the gravatar image in the branch listing if present. Refresh the branch listing on every commit done to or undone from it.
1 parent d1c4296 commit e688e35

File tree

7 files changed

+29
-8
lines changed

7 files changed

+29
-8
lines changed

apps/desktop/src/lib/branches/branchListing.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ export class BranchListingService {
6363
return store;
6464
}
6565

66+
/**
67+
* Refresh the information for a particular branch.
68+
*
69+
* Will only fetch the information if the branch is already being tracked.
70+
*/
71+
refreshBranchListingDetails(branchName: string) {
72+
if (!this.branchListingDetails.has(branchName)) {
73+
return;
74+
}
75+
this.updateBranchListing(branchName);
76+
}
77+
6678
private accumulatedBranchListings: string[] = [];
6779
private updateBranchListingTimeout: ReturnType<typeof setTimeout> | undefined;
6880
// Accumulates multiple update calls
@@ -341,6 +353,8 @@ export class Author {
341353
name?: string | undefined;
342354
/** The email of the author as configured in the git config */
343355
email?: string | undefined;
356+
/** The gravatar id of the author */
357+
gravatarUrl?: string | undefined;
344358
}
345359

346360
/** Represents a fat struct with all the data associated with a branch */

apps/desktop/src/lib/commit/CommitCard.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
console.error('Unable to undo commit');
105105
return;
106106
}
107-
branchController.undoCommit(branch.id, commit.id);
107+
branchController.undoCommit(branch.id, branch.name, commit.id);
108108
}
109109
110110
let isUndoable = commit instanceof DetailedCommit && type !== 'remote';

apps/desktop/src/lib/commit/CommitDialog.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
try {
3434
await branchController.commitBranch(
3535
$branch.id,
36+
$branch.name,
3637
message.trim(),
3738
$selectedOwnership.toString(),
3839
$runCommitHooks

apps/desktop/src/lib/commit/StackingCommitCard.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
console.error('Unable to undo commit');
105105
return;
106106
}
107-
branchController.undoCommit(branch.id, commit.id);
107+
branchController.undoCommit(branch.id, branch.name, commit.id);
108108
}
109109
110110
let isUndoable = commit instanceof DetailedCommit && type !== 'remote';

apps/desktop/src/lib/navigation/BranchListingSidebarEntry.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
branchListingDetails.authors.map(async (author) => {
101101
return {
102102
name: author.name || unknownName,
103-
srcUrl: await gravatarUrlFromEmail(author.email || unknownEmail)
103+
srcUrl: author.gravatarUrl ?? (await gravatarUrlFromEmail(author.email || unknownEmail))
104104
};
105105
})
106106
);

apps/desktop/src/lib/vbranches/branchController.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { showError, showToast } from '$lib/notifications/toasts';
33
import * as toasts from '$lib/utils/toasts';
44
import posthog from 'posthog-js';
55
import type { BaseBranchService } from '$lib/baseBranch/baseBranchService';
6+
import type { BranchListingService } from '$lib/branches/branchListing';
67
import type { RemoteBranchService } from '$lib/stores/remoteBranches';
78
import type { BranchPushResult, ForgeIdentifier, Hunk, LocalFile, StackOrder } from './types';
89
import type { VirtualBranchService } from './virtualBranch';
@@ -14,7 +15,8 @@ export class BranchController {
1415
readonly projectId: string,
1516
readonly vbranchService: VirtualBranchService,
1617
readonly remoteBranchService: RemoteBranchService,
17-
readonly baseBranchService: BaseBranchService
18+
readonly baseBranchService: BaseBranchService,
19+
private readonly branchListingService: BranchListingService
1820
) {}
1921

2022
async setTarget(branch: string, pushRemote: string | undefined = undefined) {
@@ -51,19 +53,21 @@ export class BranchController {
5153
}
5254

5355
async commitBranch(
54-
branch: string,
56+
branchId: string,
57+
branchName: string,
5558
message: string,
5659
ownership: string | undefined = undefined,
5760
runHooks = false
5861
) {
5962
try {
6063
await invoke<void>('commit_virtual_branch', {
6164
projectId: this.projectId,
62-
branch,
65+
branch: branchId,
6366
message,
6467
ownership,
6568
runHooks: runHooks
6669
});
70+
this.branchListingService.refreshBranchListingDetails(branchName);
6771
posthog.capture('Commit Successful');
6872
} catch (err: any) {
6973
if (err.code === 'errors.commit.signing_failed') {
@@ -543,13 +547,14 @@ export class BranchController {
543547
}
544548
}
545549

546-
async undoCommit(branchId: string, commitOid: string) {
550+
async undoCommit(branchId: string, branchName: string, commitOid: string) {
547551
try {
548552
await invoke<void>('undo_commit', {
549553
projectId: this.projectId,
550554
branchId,
551555
commitOid
552556
});
557+
this.branchListingService.refreshBranchListingDetails(branchName);
553558
} catch (err: any) {
554559
showError('Failed to amend commit', err);
555560
}

apps/desktop/src/routes/[projectId]/+layout.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ export const load: LayoutLoad = async ({ params, parent }) => {
7979
projectId,
8080
vbranchService,
8181
remoteBranchService,
82-
baseBranchService
82+
baseBranchService,
83+
branchListingService
8384
);
8485

8586
const branchDragActionsFactory = new BranchDragActionsFactory(branchController);

0 commit comments

Comments
 (0)