Skip to content

Commit c2f7e0f

Browse files
committed
Improves rendering existing state in home
1 parent 5b1c7f6 commit c2f7e0f

File tree

7 files changed

+68
-42
lines changed

7 files changed

+68
-42
lines changed

src/webviews/apps/home/home.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { html } from 'lit';
55
import { customElement, query } from 'lit/decorators.js';
66
import { when } from 'lit/directives/when.js';
77
import type { State } from '../../home/protocol';
8-
import { DidChangeOverviewFilter, DidFocusAccount } from '../../home/protocol';
8+
import { DidFocusAccount } from '../../home/protocol';
99
import { OverviewState, overviewStateContext } from '../plus/home/components/overviewState';
1010
import type { GLHomeAccountContent } from '../plus/shared/components/home-account-content';
1111
import { GlApp } from '../shared/app';
@@ -51,11 +51,6 @@ export class GlHomeApp extends GlApp<State> {
5151
case DidFocusAccount.is(msg):
5252
this.accountContentEl.show();
5353
break;
54-
case DidChangeOverviewFilter.is(msg):
55-
this._overviewState.filter.recent = msg.params.filter.recent;
56-
this._overviewState.filter.stale = msg.params.filter.stale;
57-
this._overviewState.run(true);
58-
break;
5954
}
6055
});
6156
}
@@ -81,7 +76,7 @@ export class GlHomeApp extends GlApp<State> {
8176
<gl-launchpad></gl-launchpad>
8277
<gl-overview></gl-overview>
8378
`,
84-
() => html` <gl-feature-nav .badgeSource=${this.badgeSource}></gl-feature-nav> `,
79+
() => html`<gl-feature-nav .badgeSource=${this.badgeSource}></gl-feature-nav>`,
8580
)}
8681
</main>
8782

src/webviews/apps/plus/home/components/active-work.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,13 @@ export class GlActiveWork extends SignalWatcher(LitElement) {
4949
}
5050

5151
private renderPending() {
52-
return html`
53-
<h3 class="section-heading">Active</h3>
54-
<skeleton-loader lines="3"></skeleton-loader>
55-
`;
52+
if (this._overviewState.state == null) {
53+
return html`
54+
<h3 class="section-heading">Active</h3>
55+
<skeleton-loader lines="3"></skeleton-loader>
56+
`;
57+
}
58+
return this.renderComplete(this._overviewState.state);
5659
}
5760

5861
private renderComplete(overview: Overview) {

src/webviews/apps/plus/home/components/launchpad.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,10 @@ export class GlLaunchpad extends SignalWatcher(LitElement) {
100100
return rsp;
101101
});
102102

103-
private get _summary() {
104-
return this._summaryState.state.value;
103+
override connectedCallback() {
104+
super.connectedCallback();
105+
106+
this._summaryState.run();
105107
}
106108

107109
override disconnectedCallback() {
@@ -123,10 +125,6 @@ export class GlLaunchpad extends SignalWatcher(LitElement) {
123125
}
124126

125127
private renderSummaryResult() {
126-
if (this._summary == null) {
127-
this._summaryState.run();
128-
}
129-
130128
return this._summaryState.render({
131129
pending: () => this.renderPending(),
132130
complete: summary => this.renderSummary(summary),
@@ -135,12 +133,15 @@ export class GlLaunchpad extends SignalWatcher(LitElement) {
135133
}
136134

137135
private renderPending() {
138-
return html`
139-
<div class="loader">
140-
<skeleton-loader lines="1"></skeleton-loader>
141-
<skeleton-loader lines="1"></skeleton-loader>
142-
</div>
143-
`;
136+
if (this._summaryState.state == null) {
137+
return html`
138+
<div class="loader">
139+
<skeleton-loader lines="1"></skeleton-loader>
140+
<skeleton-loader lines="1"></skeleton-loader>
141+
</div>
142+
`;
143+
}
144+
return this.renderSummary(this._summaryState.state);
144145
}
145146

146147
private renderSummary(summary: LaunchpadSummary | undefined) {

src/webviews/apps/plus/home/components/overview.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,13 @@ export class GlOverview extends SignalWatcher(LitElement) {
4949
}
5050

5151
private renderPending() {
52-
return html`
53-
<h3 class="section-heading">Recent</h3>
54-
<skeleton-loader lines="3"></skeleton-loader>
55-
`;
52+
if (this._overviewState.state == null) {
53+
return html`
54+
<h3 class="section-heading">Recent</h3>
55+
<skeleton-loader lines="3"></skeleton-loader>
56+
`;
57+
}
58+
return this.renderComplete(this._overviewState.state);
5659
}
5760

5861
@consume({ context: ipcContext })

src/webviews/apps/plus/home/components/overviewState.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { createContext } from '@lit/context';
22
import { signalObject } from 'signal-utils/object';
33
import type { GetOverviewResponse, OverviewFilters } from '../../../../home/protocol';
4-
import { DidChangeRepositoryWip, GetOverview, GetOverviewFilterState } from '../../../../home/protocol';
4+
import {
5+
DidChangeOverviewFilter,
6+
DidChangeRepositoryWip,
7+
GetOverview,
8+
GetOverviewFilterState,
9+
} from '../../../../home/protocol';
510
import { AsyncComputedState } from '../../../shared/components/signal-utils';
611
import type { Disposable } from '../../../shared/events';
712
import type { HostIpc } from '../../../shared/ipc';
@@ -29,6 +34,11 @@ export class OverviewState extends AsyncComputedState<Overview> {
2934
case DidChangeRepositoryWip.is(msg):
3035
this.run(true);
3136
break;
37+
case DidChangeOverviewFilter.is(msg):
38+
this.filter.recent = msg.params.filter.recent;
39+
this.filter.stale = msg.params.filter.stale;
40+
this.run(true);
41+
break;
3242
}
3343
});
3444
void this._ipc.sendRequest(GetOverviewFilterState, undefined).then(rsp => {

src/webviews/apps/shared/components/signal-utils.ts

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,30 @@ export const renderAsyncComputed = <T, R = unknown>(
2929

3030
export class AsyncComputedState<T, R = unknown> {
3131
private _invalidate = signal(0);
32-
private _initial?: T;
33-
private _state?: AsyncComputed<T>;
32+
private _computed?: AsyncComputed<T>;
33+
private _state = signal<T | undefined>(undefined);
3434
get state() {
35-
this._state ??= new AsyncComputed(
36-
(abortSignal: AbortSignal) => {
37-
this._invalidate.get();
38-
return this._fetch(abortSignal);
39-
},
40-
this._initial ? { initialValue: this._initial } : undefined,
41-
);
42-
return this._state;
35+
this.computed.run();
36+
return this._state.get();
37+
}
38+
39+
get computed() {
40+
if (this._computed == null) {
41+
const initial = this._state.get();
42+
this._computed = new AsyncComputed(
43+
async (abortSignal: AbortSignal) => {
44+
this._invalidate.get();
45+
46+
const state = await this._fetch(abortSignal);
47+
this._state.set(state);
48+
49+
return state;
50+
},
51+
initial ? { initialValue: initial } : undefined,
52+
);
53+
}
54+
55+
return this._computed;
4356
}
4457

4558
constructor(
@@ -50,7 +63,8 @@ export class AsyncComputedState<T, R = unknown> {
5063
},
5164
) {
5265
if (options != null) {
53-
this._initial = options.initial;
66+
this._state.set(options.initial);
67+
5468
if (options.autoRun === true) {
5569
this.run();
5670
}
@@ -60,7 +74,7 @@ export class AsyncComputedState<T, R = unknown> {
6074
if (force) {
6175
this.invalidate();
6276
}
63-
this.state.run();
77+
this.computed.run();
6478
}
6579

6680
invalidate() {
@@ -73,6 +87,6 @@ export class AsyncComputedState<T, R = unknown> {
7387
complete?: (value: T | undefined) => R;
7488
error?: (error: unknown) => R;
7589
}) {
76-
return renderAsyncComputed(this.state, config);
90+
return renderAsyncComputed(this.computed, config);
7791
}
7892
}

src/webviews/home/registration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function registerHomeWebviewView(controller: WebviewsController) {
1414
type: 'home',
1515
plusFeature: false,
1616
webviewHostOptions: {
17-
retainContextWhenHidden: false,
17+
retainContextWhenHidden: true,
1818
},
1919
},
2020
async (container, host) => {

0 commit comments

Comments
 (0)