Declarative loading indicator

This commit is contained in:
Jori Lallo
2017-06-29 22:44:15 -07:00
parent fb2f50999b
commit 9c80c0c400
7 changed files with 57 additions and 34 deletions

View File

@ -10,7 +10,7 @@ import { Flex } from 'reflexbox';
import { textColor } from 'styles/constants.scss'; import { textColor } from 'styles/constants.scss';
import DropdownMenu, { MenuItem } from 'components/DropdownMenu'; import DropdownMenu, { MenuItem } from 'components/DropdownMenu';
import LoadingIndicator from 'components/LoadingIndicator'; import { LoadingIndicatorBar } from 'components/LoadingIndicator';
import SidebarCollection from './components/SidebarCollection'; import SidebarCollection from './components/SidebarCollection';
import SidebarCollectionList from './components/SidebarCollectionList'; import SidebarCollectionList from './components/SidebarCollectionList';
@ -72,7 +72,7 @@ type Props = {
]} ]}
/> />
{this.props.ui.progressBarVisible && <LoadingIndicator />} {this.props.ui.progressBarVisible && <LoadingIndicatorBar />}
{this.props.notifications} {this.props.notifications}

View File

@ -1,14 +1,15 @@
// @flow // @flow
import React from 'react'; import React from 'react';
import { inject, observer } from 'mobx-react';
import styles from './LoadingIndicator.scss'; @observer class LoadingIndicator extends React.Component {
componentDidMount() {
this.props.ui.enableProgressBar();
}
const LoadingIndicator = () => { componentWillUnmount() {
return ( this.props.ui.disableProgressBar();
<div className={styles.loading}> }
<div className={styles.loader} /> }
</div>
);
};
export default LoadingIndicator; export default inject('ui')(LoadingIndicator);

View File

@ -1,20 +0,0 @@
.loader {
width: 100%;
height: 2px;
background-color: #03A9F4;
}
.loading {
position: fixed;
top: 0;
z-index: 9999;
background-color: #03A9F4;
width: 100%;
animation: loading 4s ease-in-out infinite;
}
@keyframes loading {
from {margin-left: -100%; z-index:100;}
to {margin-left: 100%; }
}

View File

@ -0,0 +1,34 @@
// @flow
import React from 'react';
import styled, { keyframes } from 'styled-components';
const LoadingIndicatorBar = () => {
return (
<Container>
<Loader />
</Container>
);
};
const loadingFrame = keyframes`
from {margin-left: -100%; z-index:100;}
to {margin-left: 100%; }
`;
const Container = styled.div`
position: fixed;
top: 0;
z-index: 9999;
background-color: #03A9F4;
width: 100%;
animation: ${loadingFrame} 4s ease-in-out infinite;
`;
const Loader = styled.div`
width: 100%;
height: 2px;
background-color: #03A9F4;
`;
export default LoadingIndicatorBar;

View File

@ -1,3 +1,5 @@
// @flow // @flow
import LoadingIndicator from './LoadingIndicator'; import LoadingIndicator from './LoadingIndicator';
import LoadingIndicatorBar from './LoadingIndicatorBar';
export default LoadingIndicator; export default LoadingIndicator;
export { LoadingIndicatorBar };

View File

@ -11,6 +11,7 @@ import DocumentsStore from 'stores/DocumentsStore';
import Menu from './components/Menu'; import Menu from './components/Menu';
import Editor from 'components/Editor'; import Editor from 'components/Editor';
import { HeaderAction, SaveAction } from 'components/Layout'; import { HeaderAction, SaveAction } from 'components/Layout';
import LoadingIndicator from 'components/LoadingIndicator';
import PublishingInfo from 'components/PublishingInfo'; import PublishingInfo from 'components/PublishingInfo';
import DocumentViews from 'components/DocumentViews'; import DocumentViews from 'components/DocumentViews';
import PreviewLoading from 'components/PreviewLoading'; import PreviewLoading from 'components/PreviewLoading';
@ -34,6 +35,10 @@ type Props = {
@observer class Document extends Component { @observer class Document extends Component {
props: Props; props: Props;
state = {
loading: false,
};
componentDidMount() { componentDidMount() {
this.loadDocument(this.props); this.loadDocument(this.props);
} }
@ -90,11 +95,11 @@ type Props = {
}; };
onImageUploadStart() { onImageUploadStart() {
this.props.ui.enableProgressBar(); this.setState({ loading: true });
} }
onImageUploadStop() { onImageUploadStop() {
this.props.ui.disableProgressBar(); this.setState({ loading: false });
} }
onChange = text => { onChange = text => {
@ -115,6 +120,7 @@ type Props = {
return ( return (
<Container column auto> <Container column auto>
{titleText && <PageTitle title={titleText} />} {titleText && <PageTitle title={titleText} />}
{this.state.loading && <LoadingIndicator />}
{isFetching && {isFetching &&
<CenteredContent> <CenteredContent>
<PreviewLoading /> <PreviewLoading />

View File

@ -5,7 +5,7 @@ import Collection from 'models/Collection';
class UiStore { class UiStore {
@observable activeDocument: ?Document; @observable activeDocument: ?Document;
@observable progressBarVisible: boolean = true; @observable progressBarVisible: boolean = false;
@observable editMode: boolean = false; @observable editMode: boolean = false;
/* Computed */ /* Computed */