From a12aa325295b341b38ee177a62d8c2a3ae5e23eb Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Fri, 28 Jul 2017 15:18:06 -0700 Subject: [PATCH] Plugin refresh loading indicator --- app/ui/components/settings/plugins.js | 112 +++++++++++++++----------- 1 file changed, 66 insertions(+), 46 deletions(-) diff --git a/app/ui/components/settings/plugins.js b/app/ui/components/settings/plugins.js index f6db959d29..936223644c 100644 --- a/app/ui/components/settings/plugins.js +++ b/app/ui/components/settings/plugins.js @@ -11,6 +11,7 @@ import {reload} from '../../../templating/index'; import installPlugin from '../../../plugins/install'; import HelpTooltip from '../help-tooltip'; import Link from '../base/link'; +import {delay} from '../../../common/misc'; @autobind class Plugins extends React.PureComponent { @@ -18,7 +19,8 @@ class Plugins extends React.PureComponent { plugins: Array, npmPluginValue: string, error: string, - loading: boolean + isInstallingFromNpm: boolean, + isRefreshingPlugins: boolean }; constructor (props: any) { @@ -27,7 +29,8 @@ class Plugins extends React.PureComponent { plugins: [], npmPluginValue: '', error: '', - loading: false + isInstallingFromNpm: false, + isRefreshingPlugins: false }; } @@ -42,9 +45,9 @@ class Plugins extends React.PureComponent { async _handleAddFromNpm (e: Event): Promise { e.preventDefault(); - this.setState({loading: true}); + this.setState({isInstallingFromNpm: true}); - const newState = {loading: false, error: ''}; + const newState = {isInstallingFromNpm: false, error: ''}; try { await installPlugin(this.state.npmPluginValue); await this._handleRefreshPlugins(); @@ -55,16 +58,24 @@ class Plugins extends React.PureComponent { this.setState(newState); } - _handleOpenDirectory (directory: string) { + _handleOpenDirectory (directory: string): void { electron.remote.shell.showItemInFolder(directory); } - async _handleRefreshPlugins () { + async _handleRefreshPlugins (): Promise { + const start = Date.now(); + + this.setState({isRefreshingPlugins: true}); + // Get and reload plugins const plugins = await getPlugins(true); reload(); - this.setState({plugins}); + // Delay loading for at least 500ms. UX FTW! + const delta = Date.now() - start; + await delay(500 - delta); + + this.setState({plugins, isRefreshingPlugins: false}); trackEvent('Plugins', 'Refresh'); } @@ -73,7 +84,7 @@ class Plugins extends React.PureComponent { } render () { - const {plugins, error, loading} = this.state; + const {plugins, error, isInstallingFromNpm, isRefreshingPlugins} = this.state; return (
@@ -84,41 +95,45 @@ class Plugins extends React.PureComponent { Submit Feedback if you have any.

- - - - - - - - - - {plugins.map(plugin => ( - - - - + {plugins.length === 0 ? ( +
No Plugins Added
+ ) : ( +
NameVersionFolder
- {plugin.name} - {plugin.description && ( - {plugin.description} - )} - {plugin.version} - - Copy Path - - {' '} - -
+ + + + + - ))} - -
NameVersionFolder
+ + + {plugins.map(plugin => ( + + + {plugin.name} + {plugin.description && ( + {plugin.description} + )} + + {plugin.version} + + + Copy Path + + {' '} + + + + ))} + + + )} {error && (
@@ -133,13 +148,13 @@ class Plugins extends React.PureComponent {
-
@@ -149,9 +164,14 @@ class Plugins extends React.PureComponent {
-