From 5900185d37c48153e749982e7e02b2637f324060 Mon Sep 17 00:00:00 2001 From: Kelvin Schoofs Date: Sat, 25 Mar 2023 22:58:29 +0100 Subject: [PATCH] Make Settings UI's StartScreen only fully reload configs when clicking Reload --- CHANGELOG.md | 3 +++ common/src/webviewMessages.ts | 1 + src/webview.ts | 6 +++--- webview/src/Startscreen.tsx | 11 ++++++----- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0dd2697..2fbc9f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,9 @@ - Add a new `extend` config option that allows a config to extend one or more other configs (#268) - The extension will automatically detect and report missing or cyclic dependencies, skipping them - Note that if a config tries to extend a non-existing config, it will be skipped and an error will also be shown +- Start screen of Settings UI will use the cached list of configs instead of reloading them + - This should make navigating to the start screen (especially when navigating back and forth between configs) faster + - The Refresh button is now renamed to Reload and will still reload the configs (from disk, remote workspaces, ...) ### Development changes diff --git a/common/src/webviewMessages.ts b/common/src/webviewMessages.ts index a685b8f..3df02bb 100644 --- a/common/src/webviewMessages.ts +++ b/common/src/webviewMessages.ts @@ -4,6 +4,7 @@ import type { ConfigLocation, FileSystemConfig } from './fileSystemConfig'; export interface RequestDataMessage { type: 'requestData'; + reload?: boolean; } export interface ResponseDataMessage { type: 'responseData'; diff --git a/src/webview.ts b/src/webview.ts index 86fbc1a..0bb093a 100644 --- a/src/webview.ts +++ b/src/webview.ts @@ -4,8 +4,8 @@ import type { Message, Navigation } from 'common/webviewMessages'; import * as fs from 'fs'; import * as path from 'path'; import * as vscode from 'vscode'; -import { deleteConfig, loadConfigs, updateConfig } from './config'; -import { DEBUG, Logging as _Logging, LOGGING_NO_STACKTRACE } from './logging'; +import { deleteConfig, getConfigs, loadConfigs, updateConfig } from './config'; +import { DEBUG, LOGGING_NO_STACKTRACE, Logging as _Logging } from './logging'; import { toPromise } from './utils'; const Logging = _Logging.scope('WebView'); @@ -89,7 +89,7 @@ async function handleMessage(message: Message): Promise { } switch (message.type) { case 'requestData': { - const configs = await loadConfigs(); + const configs = await (message.reload ? loadConfigs : getConfigs)(); const locations = getLocations(configs); return postMessage({ configs, locations, diff --git a/webview/src/Startscreen.tsx b/webview/src/Startscreen.tsx index 63b4aec..d751a55 100644 --- a/webview/src/Startscreen.tsx +++ b/webview/src/Startscreen.tsx @@ -12,7 +12,7 @@ interface StateProps { groupBy: string; } interface DispatchProps { - refresh(): void; + refresh(reload?: boolean): void; changeGroupBy(current: string): void; add(): void; } @@ -26,7 +26,7 @@ class Startscreen extends React.Component { const nextGroupBy = this.props.groupBy === 'group' ? 'location' : 'group'; return

Configurations

- + {grouped.map(([loc, configs]) => this.createGroup(loc, configs))} @@ -39,7 +39,8 @@ class Startscreen extends React.Component {
; } - public changeGroupBy = () => this.props.changeGroupBy(this.props.groupBy); + protected reload = () => this.props.refresh(true); + protected changeGroupBy = () => this.props.changeGroupBy(this.props.groupBy); } export default connect(Startscreen)( @@ -50,9 +51,9 @@ export default connect(Startscreen)( dispatch => ({ add: () => dispatch(openNewConfig()), changeGroupBy: (current: string) => dispatch(openStartScreen(current === 'group' ? 'location' : 'group')), - refresh: () => { + refresh: (reload?: boolean) => { dispatch(receivedData([], [])); - API.postMessage({ type: 'requestData' }); + API.postMessage({ type: 'requestData', reload }); }, }), );