Skip to content

Commit

Permalink
Updates Launchpad when Launchpad actions are taken
Browse files Browse the repository at this point in the history
  • Loading branch information
d13 committed Dec 10, 2024
1 parent cdf398f commit d14ace1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/webviews/apps/plus/home/components/launchpad.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { consume } from '@lit/context';
import { SignalWatcher } from '@lit-labs/signals';
import { signal, SignalWatcher } from '@lit-labs/signals';
import type { TemplateResult } from 'lit';
import { css, html, LitElement, nothing } from 'lit';
import { customElement, state } from 'lit/decorators.js';
import type { LaunchpadCommandArgs } from '../../../../../plus/launchpad/launchpad';
import { createCommandLink } from '../../../../../system/commands';
import { pluralize } from '../../../../../system/string';
import type { GetLaunchpadSummaryResponse, State } from '../../../../home/protocol';
import { GetLaunchpadSummary } from '../../../../home/protocol';
import { DidChangeLaunchpad, GetLaunchpadSummary } from '../../../../home/protocol';
import { stateContext } from '../../../home/context';
import { AsyncComputedState } from '../../../shared/components/signal-utils';
import { ipcContext } from '../../../shared/context';
Expand Down Expand Up @@ -102,7 +102,9 @@ export class GlLaunchpad extends SignalWatcher(LitElement) {

@consume({ context: ipcContext })
private _ipc!: HostIpc;
private _disposable: Disposable | undefined;
private _disposable: Disposable[] = [];

private _summary = signal<GetLaunchpadSummaryResponse | undefined>(undefined);

private _summaryState = new AsyncComputedState<LaunchpadSummary>(async _abortSignal => {
const rsp = await this._ipc.sendRequest(GetLaunchpadSummary, {});
Expand All @@ -120,18 +122,28 @@ export class GlLaunchpad extends SignalWatcher(LitElement) {
override connectedCallback() {
super.connectedCallback();

this._disposable.push(
this._ipc.onReceiveMessage(msg => {
switch (true) {
case DidChangeLaunchpad.is(msg):
this._summaryState.run(true);
break;
}
}),
);

this._summaryState.run();
}

override disconnectedCallback() {
super.disconnectedCallback();

this._disposable?.dispose();
this._disposable.forEach(d => d.dispose());
}

override render() {
return html`
<gl-section>
<gl-section ?loading=${this._summaryState.computed.status === 'pending'}>
<span slot="heading">GitLens Launchpad</span>
<div class="summary">${this.renderSummaryResult()}</div>
<button-container gap="wide">
Expand Down
10 changes: 10 additions & 0 deletions src/webviews/home/homeWebview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import {
ChangeOverviewRepository,
CollapseSectionCommand,
DidChangeIntegrationsConnections,
DidChangeLaunchpad,
DidChangeOrgSettings,
DidChangeOverviewFilter,
DidChangePreviewEnabled,
Expand Down Expand Up @@ -112,6 +113,7 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
this.container.integrations.onDidChangeConnectionState(this.onChangeConnectionState, this),
this.container.walkthrough.onProgressChanged(this.onWalkthroughChanged, this),
configuration.onDidChange(this.onDidChangeConfig, this),
this.container.launchpad.onDidChange(this.onDidLaunchpadChange, this),
);
}

Expand Down Expand Up @@ -222,6 +224,10 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
}
}

private onDidLaunchpadChange() {
this.notifyDidChangeLaunchpad();
}

private async push(force = false) {
const repo = this.getSelectedRepository();
if (repo) {
Expand Down Expand Up @@ -794,6 +800,10 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
});
}

private notifyDidChangeLaunchpad() {
void this.host.notify(DidChangeLaunchpad, undefined);
}

private notifyDidChangeOnboardingIntegration() {
// force rechecking
const isConnected = this.isAnyIntegrationConnected(true);
Expand Down
2 changes: 2 additions & 0 deletions src/webviews/home/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ export const DidChangeIntegrationsConnections = new IpcNotification<DidChangeInt
'integrations/didChange',
);

export const DidChangeLaunchpad = new IpcNotification<undefined>(scope, 'launchpad/didChange');

export interface DidChangeSubscriptionParams {
subscription: Subscription;
avatar: string;
Expand Down

0 comments on commit d14ace1

Please sign in to comment.