diff --git a/frontend/components/Layout/Layout.js b/frontend/components/Layout/Layout.js index af07a7e1c..b04a95469 100644 --- a/frontend/components/Layout/Layout.js +++ b/frontend/components/Layout/Layout.js @@ -10,7 +10,7 @@ import { Flex } from 'reflexbox'; import { textColor } from 'styles/constants.scss'; import DropdownMenu, { MenuItem } from 'components/DropdownMenu'; -import LoadingIndicator from 'components/LoadingIndicator'; +import { LoadingIndicatorBar } from 'components/LoadingIndicator'; import SidebarCollection from './components/SidebarCollection'; import SidebarCollectionList from './components/SidebarCollectionList'; @@ -27,7 +27,6 @@ type Props = { children?: ?React.Element, actions?: ?React.Element, title?: ?React.Element, - loading?: boolean, user: UserStore, auth: AuthStore, ui: UiStore, @@ -73,7 +72,7 @@ type Props = { ]} /> - {this.props.loading && } + {this.props.ui.progressBarVisible && } {this.props.notifications} diff --git a/frontend/components/LoadingIndicator/LoadingIndicator.js b/frontend/components/LoadingIndicator/LoadingIndicator.js index a82a85abd..05247430b 100644 --- a/frontend/components/LoadingIndicator/LoadingIndicator.js +++ b/frontend/components/LoadingIndicator/LoadingIndicator.js @@ -1,14 +1,19 @@ // @flow 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 = () => { - return ( -
-
-
- ); -}; + componentWillUnmount() { + this.props.ui.disableProgressBar(); + } -export default LoadingIndicator; + render() { + return null; + } +} + +export default inject('ui')(LoadingIndicator); diff --git a/frontend/components/LoadingIndicator/LoadingIndicator.scss b/frontend/components/LoadingIndicator/LoadingIndicator.scss deleted file mode 100644 index f7af32dc8..000000000 --- a/frontend/components/LoadingIndicator/LoadingIndicator.scss +++ /dev/null @@ -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%; } -} diff --git a/frontend/components/LoadingIndicator/LoadingIndicatorBar.js b/frontend/components/LoadingIndicator/LoadingIndicatorBar.js new file mode 100644 index 000000000..fb8743bf2 --- /dev/null +++ b/frontend/components/LoadingIndicator/LoadingIndicatorBar.js @@ -0,0 +1,34 @@ +// @flow +import React from 'react'; +import styled, { keyframes } from 'styled-components'; + +const LoadingIndicatorBar = () => { + return ( + + + + ); +}; + +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; diff --git a/frontend/components/LoadingIndicator/index.js b/frontend/components/LoadingIndicator/index.js index df904e0a9..fe3e594bf 100644 --- a/frontend/components/LoadingIndicator/index.js +++ b/frontend/components/LoadingIndicator/index.js @@ -1,3 +1,5 @@ // @flow import LoadingIndicator from './LoadingIndicator'; +import LoadingIndicatorBar from './LoadingIndicatorBar'; export default LoadingIndicator; +export { LoadingIndicatorBar }; diff --git a/frontend/scenes/Document/Document.js b/frontend/scenes/Document/Document.js index 1cbdc9a56..edcf7c251 100644 --- a/frontend/scenes/Document/Document.js +++ b/frontend/scenes/Document/Document.js @@ -11,6 +11,7 @@ import DocumentsStore from 'stores/DocumentsStore'; import Menu from './components/Menu'; import Editor from 'components/Editor'; import { HeaderAction, SaveAction } from 'components/Layout'; +import LoadingIndicator from 'components/LoadingIndicator'; import PublishingInfo from 'components/PublishingInfo'; import DocumentViews from 'components/DocumentViews'; import PreviewLoading from 'components/PreviewLoading'; @@ -34,6 +35,10 @@ type Props = { @observer class Document extends Component { props: Props; + state = { + isLoading: false, + }; + componentDidMount() { this.loadDocument(this.props); } @@ -79,7 +84,9 @@ type Props = { const document = this.document; if (!document) return; + this.setState({ isLoading: true }); await document.save(); + this.setState({ isLoading: false }); this.props.ui.disableEditMode(); if (redirect) { @@ -88,11 +95,11 @@ type Props = { }; onImageUploadStart() { - // TODO: How to set loading bar on layout? + this.setState({ isLoading: true }); } onImageUploadStop() { - // TODO: How to set loading bar on layout? + this.setState({ isLoading: false }); } onChange = text => { @@ -113,6 +120,7 @@ type Props = { return ( {titleText && } + {this.state.isLoading && } {isFetching && diff --git a/frontend/stores/UiStore.js b/frontend/stores/UiStore.js index 48327a7bd..6345af8b0 100644 --- a/frontend/stores/UiStore.js +++ b/frontend/stores/UiStore.js @@ -5,6 +5,7 @@ import Collection from 'models/Collection'; class UiStore { @observable activeDocument: ?Document; + @observable progressBarVisible: boolean = false; @observable editMode: boolean = false; /* Computed */ @@ -30,6 +31,14 @@ class UiStore { @action disableEditMode() { this.editMode = false; } + + @action enableProgressBar() { + this.progressBarVisible = true; + } + + @action disableProgressBar() { + this.progressBarVisible = false; + } } export default UiStore;