From a626b786168795ea27a1e0f29f5bb37a10830846 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sun, 19 Nov 2017 21:50:42 -0800 Subject: [PATCH] Improved loading state --- .../LoadingListPlaceholder.js | 40 ----------------- .../LoadingListPlaceholder/index.js | 3 -- app/scenes/Collection/Collection.js | 45 ++++++++++++------- 3 files changed, 29 insertions(+), 59 deletions(-) delete mode 100644 app/components/LoadingListPlaceholder/LoadingListPlaceholder.js delete mode 100644 app/components/LoadingListPlaceholder/index.js diff --git a/app/components/LoadingListPlaceholder/LoadingListPlaceholder.js b/app/components/LoadingListPlaceholder/LoadingListPlaceholder.js deleted file mode 100644 index 2f81df862..000000000 --- a/app/components/LoadingListPlaceholder/LoadingListPlaceholder.js +++ /dev/null @@ -1,40 +0,0 @@ -// @flow -import React from 'react'; -import styled from 'styled-components'; -import { pulsate } from 'shared/styles/animations'; -import { color } from 'shared/styles/constants'; -import Flex from 'shared/components/Flex'; -import Fade from 'components/Fade'; - -import { randomInteger } from 'shared/random'; - -const randomValues = Array.from( - new Array(5), - () => `${randomInteger(85, 100)}%` -); - -export default (props: Object) => { - return ( - - - - - - - - - - - ); -}; - -const Item = styled(Flex)` - padding: 18px 0; -`; - -const Mask = styled(Flex)` - height: ${props => (props.header ? 28 : 18)}px; - margin-bottom: ${props => (props.header ? 18 : 0)}px; - background-color: ${color.smoke}; - animation: ${pulsate} 1.3s infinite; -`; diff --git a/app/components/LoadingListPlaceholder/index.js b/app/components/LoadingListPlaceholder/index.js deleted file mode 100644 index 17588c5a6..000000000 --- a/app/components/LoadingListPlaceholder/index.js +++ /dev/null @@ -1,3 +0,0 @@ -// @flow -import LoadingListPlaceholder from './LoadingListPlaceholder'; -export default LoadingListPlaceholder; diff --git a/app/scenes/Collection/Collection.js b/app/scenes/Collection/Collection.js index f26503379..f176004b3 100644 --- a/app/scenes/Collection/Collection.js +++ b/app/scenes/Collection/Collection.js @@ -14,7 +14,7 @@ import Collection from 'models/Collection'; import Search from 'scenes/Search'; import CenteredContent from 'components/CenteredContent'; import CollectionIcon from 'components/Icon/CollectionIcon'; -import LoadingListPlaceholder from 'components/LoadingListPlaceholder'; +import { ListPlaceholder } from 'components/LoadingPlaceholder'; import Button from 'components/Button'; import HelpText from 'components/HelpText'; import DocumentList from 'components/DocumentList'; @@ -48,7 +48,7 @@ class CollectionScene extends Component { loadContent = async (id: string) => { const { collections } = this.props; - const collection = await collections.fetch(id); + const collection = collections.getById(id) || (await collections.fetch(id)); if (collection) { this.props.ui.setActiveCollection(collection); @@ -89,23 +89,36 @@ class CollectionScene extends Component { } render() { - if (this.isFetching) return ; - if (!this.collection) return this.renderNotFound(); - if (this.collection.isEmpty) return this.renderEmptyCollection(); + if (!this.isFetching && !this.collection) { + return this.renderNotFound(); + } + if (this.collection && this.collection.isEmpty) { + return this.renderEmptyCollection(); + } return ( - - - {' '} - {this.collection.name} - - Recently edited - + {this.collection ? ( + + + + {' '} + {this.collection.name} + + Recently edited + + + ) : ( + + )} ); }