Skip to content

Commit

Permalink
Wait 100ms to show the preparing spinner
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeasday committed Mar 18, 2022
1 parent 6a6af92 commit 2af2ad4
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/preview-web/src/WebView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { Story } from '@storybook/store';

const { document } = global;

const PREPARING_DELAY = 100;

const layoutClassMap = {
centered: 'sb-main-centered',
fullscreen: 'sb-main-fullscreen',
Expand Down Expand Up @@ -39,6 +41,8 @@ export class WebView {

testing = false;

preparingTimeout: ReturnType<typeof setTimeout> = null;

constructor() {
// Special code for testing situations
const { __SPECIAL_TEST_PARAMETER__ } = qs.parse(document.location.search, {
Expand Down Expand Up @@ -111,6 +115,7 @@ export class WebView {
}

showMode(mode: Mode) {
clearTimeout(this.preparingTimeout);
Object.keys(Mode).forEach((otherMode) => {
if (otherMode === mode) {
document.body.classList.add(classes[otherMode]);
Expand Down Expand Up @@ -146,11 +151,13 @@ export class WebView {
}

showPreparingStory() {
this.showMode(Mode.PREPARING_STORY);
clearTimeout(this.preparingTimeout);
this.preparingTimeout = setTimeout(() => this.showMode(Mode.PREPARING_STORY), PREPARING_DELAY);
}

showPreparingDocs() {
this.showMode(Mode.PREPARING_DOCS);
clearTimeout(this.preparingTimeout);
this.preparingTimeout = setTimeout(() => this.showMode(Mode.PREPARING_DOCS), PREPARING_DELAY);
}

showMain() {
Expand Down

0 comments on commit 2af2ad4

Please sign in to comment.