Skip to content

Commit

Permalink
Toggle UI suspension based on plugin setting
Browse files Browse the repository at this point in the history
  • Loading branch information
kgryte committed May 18, 2020
1 parent 6a93b34 commit f58b51f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
3 changes: 3 additions & 0 deletions src/components/GitPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ export class GitPanel extends React.Component<
model={this.props.model}
branching={!disableBranching}
refresh={this._onRefresh}
suspend={
this.props.settings.composite['blockWhileCommandExecutes'] as boolean
}
/>
);
}
Expand Down
44 changes: 25 additions & 19 deletions src/components/Toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ export interface IToolbarProps {
*/
branching: boolean;

/**
* Boolean indicating whether to enable UI suspension.
*/
suspend: boolean;

/**
* Callback to invoke in order to refresh a repository.
*
Expand Down Expand Up @@ -306,7 +311,7 @@ export class Toolbar extends React.Component<IToolbarProps, IToolbarState> {
* @returns React element
*/
private _renderFeedback(): React.ReactElement | null {
if (this.state.suspend === false) {
if (this.props.suspend === false || this.state.suspend === false) {
return null;
}
return (
Expand Down Expand Up @@ -346,26 +351,35 @@ export class Toolbar extends React.Component<IToolbarProps, IToolbarState> {
});
}

/**
* Sets the suspension state.
*
* @param bool - boolean indicating whether to suspend UI interaction
*/
private _suspend(bool: boolean): void {
if (this.props.suspend) {
this.setState({
suspend: bool
});
}
}

/**
* Callback invoked upon clicking a button to pull the latest changes.
*
* @param event - event object
* @returns a promise which resolves upon pulling the latest changes
*/
private _onPullClick = async (): Promise<void> => {
this.setState({
suspend: true
});
this._suspend(true);
try {
await showGitOperationDialog(this.props.model, Operation.Pull);
} catch (error) {
console.error(
`Encountered an error when pulling changes. Error: ${error}`
);
}
this.setState({
suspend: false
});
this._suspend(false);
};

/**
Expand All @@ -375,19 +389,15 @@ export class Toolbar extends React.Component<IToolbarProps, IToolbarState> {
* @returns a promise which resolves upon pushing the latest changes
*/
private _onPushClick = async (): Promise<void> => {
this.setState({
suspend: true
});
this._suspend(true);
try {
await showGitOperationDialog(this.props.model, Operation.Push);
} catch (error) {
console.error(
`Encountered an error when pushing changes. Error: ${error}`
);
}
this.setState({
suspend: false
});
this._suspend(false);
};

/**
Expand Down Expand Up @@ -421,12 +431,8 @@ export class Toolbar extends React.Component<IToolbarProps, IToolbarState> {
* @returns a promise which resolves upon refreshing a repository
*/
private _onRefreshClick = async (): Promise<void> => {
this.setState({
suspend: true
});
this._suspend(true);
await Promise.all([sleep(1000), this.props.refresh()]);
this.setState({
suspend: false
});
this._suspend(false);
};
}

0 comments on commit f58b51f

Please sign in to comment.