Improve skeleton loading design
This commit is contained in:
parent
34729c763f
commit
565eacb725
|
@ -8,6 +8,7 @@ import AlbumSidebar from './sidebar/AlbumSidebar'
|
|||
|
||||
const Header = styled.h1`
|
||||
margin: 0 0 12px 0 !important;
|
||||
height: 36px;
|
||||
|
||||
& a {
|
||||
color: black;
|
||||
|
@ -34,7 +35,7 @@ const SettingsIcon = props => {
|
|||
}
|
||||
|
||||
const AlbumTitle = ({ album, disableLink = false }) => {
|
||||
if (!album) return null
|
||||
if (!album) return <div style={{ height: 36 }}></div>
|
||||
|
||||
let title = <span>{album.title}</span>
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import React from 'react'
|
||||
import React, { useState } from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import styled from 'styled-components'
|
||||
import { Link } from 'react-router-dom'
|
||||
|
@ -12,7 +12,13 @@ const AlbumBoxLink = styled(Link)`
|
|||
color: #222;
|
||||
`
|
||||
|
||||
const AlbumBoxImage = ({ src, ...props }) => {
|
||||
const ImageWrapper = styled.div`
|
||||
width: 240px;
|
||||
height: 220px;
|
||||
padding: 0 10px;
|
||||
position: relative;
|
||||
`
|
||||
|
||||
const Image = styled(ProtectedImage)`
|
||||
width: 220px;
|
||||
height: 220px;
|
||||
|
@ -28,10 +34,29 @@ const AlbumBoxImage = ({ src, ...props }) => {
|
|||
border-radius: 4%;
|
||||
margin: auto;
|
||||
background: linear-gradient(#f7f7f7 0%, #eee 100%);
|
||||
|
||||
${({ overlap, loaded }) =>
|
||||
overlap &&
|
||||
`
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 10px;
|
||||
opacity: ${loaded ? 0 : 1};
|
||||
|
||||
transition: opacity 200ms;
|
||||
`}
|
||||
`
|
||||
|
||||
const AlbumBoxImage = ({ src, ...props }) => {
|
||||
const [loaded, setLoaded] = useState(false)
|
||||
|
||||
if (src) {
|
||||
return <Image {...props} src={src} />
|
||||
return (
|
||||
<ImageWrapper>
|
||||
<Image {...props} onLoad={loaded => setLoaded(loaded)} src={src} />
|
||||
<Placeholder overlap loaded={loaded ? 1 : 0} />
|
||||
</ImageWrapper>
|
||||
)
|
||||
}
|
||||
|
||||
return <Placeholder />
|
||||
|
|
|
@ -23,14 +23,14 @@ const AlbumBoxes = ({ loading, error, albums, getCustomLink }) => {
|
|||
/>
|
||||
))
|
||||
} else {
|
||||
for (let i = 0; i < 8; i++) {
|
||||
for (let i = 0; i < 4; i++) {
|
||||
albumElements.push(<AlbumBox key={i} />)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Container>
|
||||
<Loader active={loading}>Loading albums</Loader>
|
||||
{/* <Loader active={loading}>Loading albums</Loader> */}
|
||||
{albumElements}
|
||||
</Container>
|
||||
)
|
||||
|
|
|
@ -65,13 +65,24 @@ const AlbumGallery = ({ album, loading = false, customAlbumLink }) => {
|
|||
/>
|
||||
)
|
||||
}
|
||||
} else {
|
||||
subAlbumElement = <AlbumBoxes loading={loading} />
|
||||
}
|
||||
|
||||
return (
|
||||
<Layout>
|
||||
<AlbumTitle album={album} disableLink />
|
||||
{subAlbumElement}
|
||||
{album && album.subAlbums.length > 0 && <h2>Images</h2>}
|
||||
{
|
||||
<h2
|
||||
style={{
|
||||
opacity: loading ? 0 : 1,
|
||||
display: album && album.subAlbums.length > 0 ? 'block' : 'none',
|
||||
}}
|
||||
>
|
||||
Images
|
||||
</h2>
|
||||
}
|
||||
<PhotoGallery
|
||||
loading={loading}
|
||||
photos={album && album.photos}
|
||||
|
|
|
@ -139,3 +139,12 @@ Photo.propTypes = {
|
|||
active: PropTypes.bool.isRequired,
|
||||
setPresenting: PropTypes.func.isRequired,
|
||||
}
|
||||
|
||||
export const PhotoThumbnail = styled.div`
|
||||
flex-grow: 1;
|
||||
height: 200px;
|
||||
width: 300px;
|
||||
margin: 4px;
|
||||
background-color: #eee;
|
||||
position: relative;
|
||||
`
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import React, { useEffect } from 'react'
|
||||
import styled from 'styled-components'
|
||||
import { Loader } from 'semantic-ui-react'
|
||||
import { Photo } from './Photo'
|
||||
import { Photo, PhotoThumbnail } from './Photo'
|
||||
import { PresentContainer, PresentPhoto } from './PresentView'
|
||||
import PropTypes from 'prop-types'
|
||||
import { SidebarConsumer } from '../sidebar/Sidebar'
|
||||
|
@ -11,6 +11,8 @@ const Gallery = styled.div`
|
|||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
min-height: 200px;
|
||||
position: relative;
|
||||
`
|
||||
|
||||
const PhotoFiller = styled.div`
|
||||
|
@ -62,7 +64,7 @@ const PhotoGallery = ({
|
|||
const activeImage = photos && activeIndex != -1 && photos[activeIndex]
|
||||
|
||||
const getPhotoElements = updateSidebar => {
|
||||
let photoElements = null
|
||||
let photoElements = []
|
||||
if (photos) {
|
||||
photos.filter(photo => photo.thumbnail)
|
||||
|
||||
|
@ -91,6 +93,10 @@ const PhotoGallery = ({
|
|||
/>
|
||||
)
|
||||
})
|
||||
} else {
|
||||
for (let i = 0; i < 6; i++) {
|
||||
photoElements.push(<PhotoThumbnail />)
|
||||
}
|
||||
}
|
||||
|
||||
return photoElements
|
||||
|
|
Loading…
Reference in New Issue