From 42d0ffe6ffc32f941a88f44da22c0a6e5f80fb73 Mon Sep 17 00:00:00 2001 From: roschaefer Date: Tue, 15 Oct 2019 18:42:15 +0200 Subject: [PATCH] docs: use setTimeout to show spinner --- .../components/LoginForm/LoginForm.story.js | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/webapp/components/LoginForm/LoginForm.story.js b/webapp/components/LoginForm/LoginForm.story.js index d04481496..618b2556c 100644 --- a/webapp/components/LoginForm/LoginForm.story.js +++ b/webapp/components/LoginForm/LoginForm.story.js @@ -1,7 +1,6 @@ import { storiesOf } from '@storybook/vue' import { withA11y } from '@storybook/addon-a11y' import { action } from '@storybook/addon-actions' -import Vue from 'vue' import Vuex from 'vuex' import helpers from '~/storybook/helpers' import LoginForm from './LoginForm.vue' @@ -13,14 +12,33 @@ const createStore = ({ loginSuccess }) => { modules: { auth: { namespaced: true, + state: () => ({ + pending: false, + }), + mutations: { + SET_PENDING(state, pending) { + state.pending = pending + }, + }, + getters: { + pending(state) { + return !!state.pending + }, + }, actions: { async login({ commit, dispatch }, args) { action('Vuex action `auth/login`')(args) - if (loginSuccess) { - return loginSuccess - } else { - throw new Error('Login unsuccessful') - } + return new Promise((resolve, reject) => { + commit('SET_PENDING', true) + setTimeout(() => { + commit('SET_PENDING', false) + if (loginSuccess) { + resolve(loginSuccess) + } else { + reject(new Error('Login unsuccessful')) + } + }, 1000) + }) }, }, },