Skip to content

Commit 43288a1

Browse files
d13eamodio
authored andcommitted
Updates show account view command to the account on home
1 parent 4550cd6 commit 43288a1

File tree

7 files changed

+85
-9
lines changed

7 files changed

+85
-9
lines changed

src/commands/showView.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Commands } from '../constants.commands';
22
import type { Container } from '../container';
33
import type { GraphWebviewShowingArgs } from '../plus/webviews/graph/registration';
44
import { command } from '../system/vscode/command';
5+
import type { HomeWebviewShowingArgs } from '../webviews/home/registration';
56
import type { CommandContext } from './base';
67
import { Command } from './base';
78

@@ -39,7 +40,10 @@ export class ShowViewCommand extends Command {
3940
const command = context.command as Commands;
4041
switch (command) {
4142
case Commands.ShowAccountView:
42-
return this.container.accountView.show();
43+
return this.container.homeView.show(
44+
undefined,
45+
...([{ focusAccount: true }, ...args] as HomeWebviewShowingArgs),
46+
);
4347
case Commands.ShowBranchesView:
4448
return this.container.branchesView.show();
4549
case Commands.ShowCommitDetailsView:
@@ -55,7 +59,7 @@ export class ShowViewCommand extends Command {
5559
case Commands.ShowGraphView:
5660
return this.container.graphView.show(undefined, ...(args as GraphWebviewShowingArgs));
5761
case Commands.ShowHomeView:
58-
return this.container.homeView.show();
62+
return this.container.homeView.show(undefined, ...(args as HomeWebviewShowingArgs));
5963
case Commands.ShowLaunchpadView:
6064
return this.container.launchpadView.show();
6165
case Commands.ShowLineHistoryView:

src/container.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ import {
9191
registerCommitDetailsWebviewView,
9292
registerGraphDetailsWebviewView,
9393
} from './webviews/commitDetails/registration';
94+
import type { HomeWebviewShowingArgs } from './webviews/home/registration';
9495
import { registerHomeWebviewView } from './webviews/home/registration';
9596
import { RebaseEditorProvider } from './webviews/rebase/rebaseEditor';
9697
import { registerSettingsWebviewCommands, registerSettingsWebviewPanel } from './webviews/settings/registration';
@@ -628,7 +629,7 @@ export class Container {
628629
return this._graphView;
629630
}
630631

631-
private readonly _homeView: WebviewViewProxy<[]>;
632+
private readonly _homeView: WebviewViewProxy<HomeWebviewShowingArgs>;
632633
get homeView() {
633634
return this._homeView;
634635
}

src/webviews/apps/home/home.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
/*global*/
22
import './home.scss';
33
import { html } from 'lit';
4-
import { customElement } from 'lit/decorators.js';
4+
import { customElement, query } from 'lit/decorators.js';
55
import type { State } from '../../home/protocol';
6+
import { DidFocusAccount } from '../../home/protocol';
7+
import type { GLHomeAccountContent } from '../plus/shared/components/home-account-content';
68
import { GlApp } from '../shared/app';
79
import { scrollableBase } from '../shared/components/styles/lit/base.css';
10+
import type { Disposable } from '../shared/events';
811
import type { HostIpc } from '../shared/ipc';
912
import { homeBaseStyles, homeStyles } from './home.css';
1013
import { HomeStateProvider } from './stateProvider';
@@ -17,13 +20,35 @@ import './components/onboarding';
1720
@customElement('gl-home-app')
1821
export class GlHomeApp extends GlApp<State> {
1922
static override styles = [homeBaseStyles, scrollableBase, homeStyles];
23+
private disposable: Disposable | undefined;
24+
25+
@query('#account-content')
26+
private accountContentEl!: GLHomeAccountContent;
2027

2128
private badgeSource = { source: 'home', detail: 'badge' };
2229

2330
protected override createStateProvider(state: State, ipc: HostIpc) {
2431
return new HomeStateProvider(this, state, ipc);
2532
}
2633

34+
override connectedCallback(): void {
35+
super.connectedCallback();
36+
37+
this.disposable = this._ipc.onReceiveMessage(msg => {
38+
switch (true) {
39+
case DidFocusAccount.is(msg):
40+
this.accountContentEl.show();
41+
break;
42+
}
43+
});
44+
}
45+
46+
override disconnectedCallback(): void {
47+
super.disconnectedCallback();
48+
49+
this.disposable?.dispose();
50+
}
51+
2752
override render() {
2853
return html`
2954
<div class="home scrollable">

src/webviews/apps/plus/shared/components/home-account-content.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { consume } from '@lit/context';
22
import { css, html, LitElement, nothing } from 'lit';
3-
import { customElement, state } from 'lit/decorators.js';
3+
import { customElement, query, state } from 'lit/decorators.js';
44
import { when } from 'lit/directives/when.js';
55
import { urls } from '../../../../../constants';
66
import type { Promo } from '../../../../../plus/gk/account/promos';
@@ -15,6 +15,7 @@ import {
1515
import { pluralize } from '../../../../../system/string';
1616
import type { State } from '../../../../home/protocol';
1717
import { stateContext } from '../../../home/context';
18+
import type { GlAccordion } from '../../../shared/components/accordion/accordion';
1819
import { elementBase, linkBase } from '../../../shared/components/styles/lit/base.css';
1920
import '../../../shared/components/accordion/accordion';
2021
import '../../../shared/components/button';
@@ -159,6 +160,9 @@ export class GLHomeAccountContent extends LitElement {
159160
`,
160161
];
161162

163+
@query('#accordion')
164+
private accordionEl!: GlAccordion;
165+
162166
@consume<State>({ context: stateContext, subscribe: true })
163167
@state()
164168
private _state!: State;
@@ -206,7 +210,7 @@ export class GLHomeAccountContent extends LitElement {
206210
}
207211

208212
override render() {
209-
return html`<gl-accordion>
213+
return html`<gl-accordion id="accordion">
210214
<div class="header" slot="header">
211215
${this.hasAccount && this._state.avatar
212216
? html`<img class="header__media" src=${this._state.avatar} />`
@@ -395,4 +399,13 @@ export class GLHomeAccountContent extends LitElement {
395399
private renderPromo(promo: Promo | undefined) {
396400
return html`<gl-promo .promo=${promo}></gl-promo>`;
397401
}
402+
403+
override focus() {
404+
this.accordionEl.focus();
405+
}
406+
407+
show() {
408+
this.accordionEl.open = true;
409+
this.accordionEl.focus();
410+
}
398411
}

src/webviews/home/homeWebview.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,28 @@ import type { SubscriptionChangeEvent } from '../../plus/gk/account/subscription
77
import { registerCommand } from '../../system/vscode/command';
88
import { getContext, onDidChangeContext } from '../../system/vscode/context';
99
import type { IpcMessage } from '../protocol';
10-
import type { WebviewHost, WebviewProvider } from '../webviewProvider';
10+
import type { WebviewHost, WebviewProvider, WebviewShowingArgs } from '../webviewProvider';
11+
import type { WebviewShowOptions } from '../webviewsController';
1112
import type { CollapseSectionParams, DidChangeRepositoriesParams, State } from './protocol';
1213
import {
1314
CollapseSectionCommand,
1415
DidChangeIntegrationsConnections,
1516
DidChangeOrgSettings,
1617
DidChangeRepositories,
1718
DidChangeSubscription,
19+
DidFocusAccount,
1820
} from './protocol';
21+
import type { HomeWebviewShowingArgs } from './registration';
1922

2023
const emptyDisposable = Object.freeze({
2124
dispose: () => {
2225
/* noop */
2326
},
2427
});
2528

26-
export class HomeWebviewProvider implements WebviewProvider<State> {
29+
export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWebviewShowingArgs> {
2730
private readonly _disposable: Disposable;
31+
private _pendingFocusAccount = false;
2832

2933
constructor(
3034
private readonly container: Container,
@@ -45,6 +49,23 @@ export class HomeWebviewProvider implements WebviewProvider<State> {
4549
this._disposable.dispose();
4650
}
4751

52+
onShowing(
53+
loading: boolean,
54+
_options?: WebviewShowOptions,
55+
...args: WebviewShowingArgs<HomeWebviewShowingArgs, State>
56+
) {
57+
const [arg] = args as HomeWebviewShowingArgs;
58+
if (arg?.focusAccount === true) {
59+
if (!loading && this.host.ready && this.host.visible) {
60+
queueMicrotask(() => void this.host.notify(DidFocusAccount, undefined));
61+
return true;
62+
}
63+
this._pendingFocusAccount = true;
64+
}
65+
66+
return true;
67+
}
68+
4869
private onChangeConnectionState() {
4970
this.notifyDidChangeOnboardingIntegration();
5071
}
@@ -73,6 +94,14 @@ export class HomeWebviewProvider implements WebviewProvider<State> {
7394
this.notifyDidChangeRepositories();
7495
}
7596

97+
onReady() {
98+
if (this._pendingFocusAccount === true) {
99+
this._pendingFocusAccount = false;
100+
101+
void this.host.notify(DidFocusAccount, undefined);
102+
}
103+
}
104+
76105
private onCollapseSection(params: CollapseSectionParams) {
77106
const collapsed = this.container.storage.get('home:sections:collapsed');
78107
if (collapsed == null) {

src/webviews/home/protocol.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,5 @@ export interface DidChangeOrgSettingsParams {
5454
orgSettings: State['orgSettings'];
5555
}
5656
export const DidChangeOrgSettings = new IpcNotification<DidChangeOrgSettingsParams>(scope, 'org/settings/didChange');
57+
58+
export const DidFocusAccount = new IpcNotification<undefined>(scope, 'account/didFocus');

src/webviews/home/registration.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import type { WebviewsController } from '../webviewsController';
22
import type { State } from './protocol';
33

4+
export type HomeWebviewShowingArgs = [{ focusAccount: boolean }];
5+
46
export function registerHomeWebviewView(controller: WebviewsController) {
5-
return controller.registerWebviewView<State>(
7+
return controller.registerWebviewView<State, State, HomeWebviewShowingArgs>(
68
{
79
id: 'gitlens.views.home',
810
fileName: 'home.html',

0 commit comments

Comments
 (0)