Animate dashboard loading to make it smoother (#38)

pull/39/head
Uku Taht 7 years ago committed by GitHub
parent ddd7640de8
commit e21b59fa4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,7 +1,7 @@
@tailwind preflight;
@tailwind components;
@import "modal.css";
@import "coffee_cup.css";
@import "loader.css";
@import "tooltip.css";
.button {
@ -253,5 +253,5 @@ a {
}
.fade-enter-active {
opacity: 1;
transition: opacity 200ms ease-in;
transition: opacity 100ms ease-in;
}

@ -1,6 +1,7 @@
.loading {
width: 50px;
height: 50px;
animation: loaderFadein .2s ease-in;
}
.loading div {
@ -20,3 +21,9 @@
@-webkit-keyframes spin {
to { -webkit-transform: rotate(360deg); }
}
@keyframes loaderFadein {
0% { opacity: 0; }
50% { opacity: 0; }
100% { opacity: 1; }
}

@ -7,11 +7,20 @@
}
.modal[aria-hidden="false"] .modal__overlay {
animation: mmfadeIn .2s cubic-bezier(0.0, 0.0, 0.2, 1);
animation: mmfadeIn .2s ease-in;
}
.modal[aria-hidden="true"] .modal__overlay {
animation: mmfadeOut .2s cubic-bezier(0.0, 0.0, 0.2, 1);
animation: mmfadeOut .2s ease-in;
}
.modal-enter {
opacity: 0;
}
.modal-enter-active {
opacity: 1;
transition: opacity 100ms ease-in;
}
.modal__overlay {
@ -26,6 +35,17 @@
overflow-y: auto;
}
.modal__loader {
margin: 300px auto 0 auto;
animation: loaderFadein .4s ease-in;
}
@keyframes loaderFadein {
0% { opacity: 0; }
50% { opacity: 0; }
100% { opacity: 1; }
}
.modal__container {
background-color: #fff;
padding: 1rem 2rem;
@ -34,6 +54,7 @@
margin: 50px auto;
box-sizing: border-box;
min-height: 509px;
transition: height 200ms ease-in;
}
.modal__header {
@ -54,9 +75,7 @@
.modal__close:before { content: "\2715"; }
.modal__content {
margin-top: 2rem;
margin-bottom: 2rem;
line-height: 1.5;
}
@keyframes mmfadeIn {

@ -0,0 +1,8 @@
import React from 'react';
export default function FadeIn({show, children}) {
const className = show ? "fade-enter-active" : "fade-enter"
return <div className={className}>{children}</div>
}

@ -1,6 +1,7 @@
import React from 'react';
import Datamap from 'datamaps'
import FadeIn from '../fade-in'
import Bar from './bar'
import MoreLink from './more-link'
import * as api from '../api'
@ -79,21 +80,26 @@ export default class Countries extends React.Component {
});
}
render() {
if (this.state.loading) {
return (
<div className="stats-item bg-white shadow-xl rounded p-4" style={{height: '436px'}}>
<div className="loading my-32 mx-auto"><div></div></div>
</div>
)
} else if (this.state.countries) {
renderBody() {
if (this.state.countries) {
return (
<div className="stats-item bg-white shadow-xl rounded p-4" style={{height: '436px'}}>
<React.Fragment>
<h3>Countries</h3>
<div className="mt-6 mx-auto" style={{width: '100%', maxWidth: '475px', height: '320px'}} id="map-container"></div>
<MoreLink site={this.props.site} list={this.state.countries} endpoint="countries" />
</div>
</React.Fragment>
)
}
}
render() {
return (
<div className="stats-item bg-white shadow-xl rounded p-4" style={{height: '436px'}}>
{ this.state.loading && <div className="loading my-32 mx-auto"><div></div></div> }
<FadeIn show={!this.state.loading}>
{ this.renderBody() }
</FadeIn>
</div>
)
}
}

@ -74,15 +74,18 @@ class ScreenSizes extends React.Component {
render() {
return (
<FadeIn show={!this.state.loading}>
<React.Fragment>
<div className="flex items-center mt-4 mb-2 justify-between text-grey-dark text-xs font-bold tracking-wide">
<span>Screen size</span>
<span>Visitors</span>
</div>
{ this.state.sizes && this.state.sizes.map(this.renderScreenSize.bind(this)) }
</React.Fragment>
</FadeIn>
<React.Fragment>
{ this.state.loading && <div className="loading my-32 mx-auto"><div></div></div> }
<FadeIn show={!this.state.loading}>
<React.Fragment>
<div className="flex items-center mt-4 mb-2 justify-between text-grey-dark text-xs font-bold tracking-wide">
<span>Screen size</span>
<span>Visitors</span>
</div>
{ this.state.sizes && this.state.sizes.map(this.renderScreenSize.bind(this)) }
</React.Fragment>
</FadeIn>
</React.Fragment>
)
}
}
@ -123,15 +126,18 @@ class Browsers extends React.Component {
render() {
return (
<FadeIn show={!this.state.loading}>
<div>
<div className="flex items-center mt-4 mb-2 justify-between text-grey-dark text-xs font-bold tracking-wide">
<span>Browser</span>
<span>Visitors</span>
</div>
{ this.state.browsers && this.state.browsers.map(this.renderBrowser.bind(this)) }
</div>
</FadeIn>
<React.Fragment>
{ this.state.loading && <div className="loading my-32 mx-auto"><div></div></div> }
<FadeIn show={!this.state.loading}>
<React.Fragment>
<div className="flex items-center mt-4 mb-2 justify-between text-grey-dark text-xs font-bold tracking-wide">
<span>Browser</span>
<span>Visitors</span>
</div>
{ this.state.browsers && this.state.browsers.map(this.renderBrowser.bind(this)) }
</React.Fragment>
</FadeIn>
</React.Fragment>
)
}
}
@ -172,15 +178,18 @@ class OperatingSystems extends React.Component {
render() {
return (
<FadeIn show={!this.state.loading}>
<React.Fragment>
<div className="flex items-center mt-4 mb-2 justify-between text-grey-dark text-xs font-bold tracking-wide">
<span>Operating system</span>
<span>Visitors</span>
</div>
{ this.state.operatingSystems && this.state.operatingSystems.map(this.renderOperatingSystem.bind(this)) }
</React.Fragment>
</FadeIn>
<React.Fragment>
{ this.state.loading && <div className="loading my-32 mx-auto"><div></div></div> }
<FadeIn show={!this.state.loading}>
<React.Fragment>
<div className="flex items-center mt-4 mb-2 justify-between text-grey-dark text-xs font-bold tracking-wide">
<span>Operating system</span>
<span>Visitors</span>
</div>
{ this.state.operatingSystems && this.state.operatingSystems.map(this.renderOperatingSystem.bind(this)) }
</React.Fragment>
</FadeIn>
</React.Fragment>
)
}
}

@ -30,11 +30,7 @@ class CountriesModal extends React.Component {
}
renderBody() {
if (this.state.loading) {
return (
<div className="loading my-32 mx-auto"><div></div></div>
)
} else if (this.state.countries) {
if (this.state.countries) {
return (
<React.Fragment>
<header className="modal__header">
@ -63,7 +59,7 @@ class CountriesModal extends React.Component {
render() {
return (
<Modal site={this.props.site}>
<Modal site={this.props.site} show={!this.state.loading}>
{ this.renderBody() }
</Modal>
)

@ -93,11 +93,7 @@ class GoogleKeywordsModal extends React.Component {
}
renderBody() {
if (this.state.loading) {
return (
<div className="loading my-32 mx-auto"><div></div></div>
)
} else {
if (!this.state.loading) {
return (
<React.Fragment>
<header className="modal__header">
@ -107,7 +103,7 @@ class GoogleKeywordsModal extends React.Component {
<div className="my-4 border-b border-grey-light"></div>
<main className="modal__content mt-0">
<h1>{this.state.totalVisitors} new visitors from Google</h1>
<h1 className="text-grey-darker" style={{transform: 'translateY(-1rem)'}}>{toHuman(this.state.query)}</h1>
<h1 className="text-grey-darker mt-2" style={{transform: 'translateY(-1rem)'}}>{toHuman(this.state.query)}</h1>
{ this.renderKeywords() }
</main>
</React.Fragment>
@ -117,7 +113,7 @@ class GoogleKeywordsModal extends React.Component {
render() {
return (
<Modal site={this.props.site}>
<Modal site={this.props.site} show={!this.state.loading}>
{ this.renderBody() }
</Modal>
)

@ -2,6 +2,12 @@ import React from "react";
import { createPortal } from "react-dom";
import { withRouter } from 'react-router-dom';
function SlideIn({show, children}) {
const className = show ? "modal-enter-active" : "modal-enter"
return <div className={className}>{children}</div>
}
class Modal extends React.Component {
constructor(props) {
super(props)
@ -47,9 +53,16 @@ class Modal extends React.Component {
<div className="modal is-open" onClick={this.props.onClick}>
<div className="modal__overlay">
<button className="modal__close"></button>
<div ref={this.node} className="modal__container">
{this.props.children}
</div>
{ !this.props.show &&
<div className="modal__loader loading"><div></div></div>
}
<SlideIn show={this.props.show}>
<div ref={this.node} className="modal__container">
{this.props.children}
</div>
</SlideIn>
</div>
</div>,
document.getElementById("modal_root"),

@ -45,11 +45,7 @@ class PagesModal extends React.Component {
}
renderBody() {
if (this.state.loading) {
return (
<div className="loading my-32 mx-auto"><div></div></div>
)
} else if (this.state.pages) {
if (this.state.pages) {
return (
<React.Fragment>
<header className="modal__header">
@ -78,7 +74,7 @@ class PagesModal extends React.Component {
render() {
return (
<Modal site={this.props.site}>
<Modal site={this.props.site} show={!this.state.loading}>
{ this.renderBody() }
</Modal>
)

@ -113,11 +113,7 @@ class ReferrerDrilldownModal extends React.Component {
}
renderBody() {
if (this.state.loading) {
return (
<div className="loading my-32 mx-auto"><div></div></div>
)
} else if (this.state.referrers) {
if (this.state.referrers) {
return (
<React.Fragment>
<header className="modal__header">
@ -149,7 +145,7 @@ class ReferrerDrilldownModal extends React.Component {
render() {
return (
<Modal site={this.props.site}>
<Modal site={this.props.site} show={!this.state.loading}>
{ this.renderBody() }
</Modal>
)

@ -1,6 +1,7 @@
import React from "react";
import { Link, withRouter } from 'react-router-dom'
import FadeIn from '../../fade-in'
import Modal from './modal'
import * as api from '../../api'
import numberFormatter from '../../number-formatter'
@ -52,11 +53,7 @@ class ReferrersModal extends React.Component {
}
renderBody() {
if (this.state.loading) {
return (
<div className="loading my-32 mx-auto"><div></div></div>
)
} else if (this.state.referrers) {
if (this.state.referrers) {
return (
<React.Fragment>
<header className="modal__header">
@ -85,7 +82,7 @@ class ReferrersModal extends React.Component {
render() {
return (
<Modal site={this.props.site}>
<Modal site={this.props.site} show={!this.state.loading}>
{ this.renderBody() }
</Modal>
)

@ -1,5 +1,6 @@
import React from 'react';
import FadeIn from '../fade-in'
import Bar from './bar'
import MoreLink from './more-link'
import numberFormatter from '../number-formatter'
@ -42,16 +43,10 @@ export default class Pages extends React.Component {
)
}
render() {
if (this.state.loading) {
return (
<div className="stats-item bg-white shadow-xl rounded p-4" style={{height: '436px'}}>
<div className="loading my-32 mx-auto"><div></div></div>
</div>
)
} else if (this.state.pages) {
renderContent() {
if (this.state.pages) {
return (
<div className="stats-item bg-white shadow-xl rounded p-4" style={{height: '436px'}}>
<React.Fragment>
<h3>Top Pages</h3>
<div className="flex items-center mt-4 mb-2 justify-between text-grey-dark text-xs font-bold tracking-wide">
@ -61,8 +56,19 @@ export default class Pages extends React.Component {
{ this.state.pages.map(this.renderPage.bind(this)) }
<MoreLink site={this.props.site} list={this.state.pages} endpoint="pages" />
</div>
</React.Fragment>
)
}
}
render() {
return (
<div className="stats-item bg-white shadow-xl rounded p-4" style={{height: '436px'}}>
{ this.state.loading && <div className="loading my-32 mx-auto"><div></div></div> }
<FadeIn show={!this.state.loading}>
{ this.renderContent() }
</FadeIn>
</div>
)
}
}

@ -1,6 +1,7 @@
import React from 'react';
import { Link } from 'react-router-dom'
import FadeIn from '../fade-in'
import Bar from './bar'
import MoreLink from './more-link'
import numberFormatter from '../number-formatter'
@ -46,11 +47,10 @@ export default class Referrers extends React.Component {
}
renderContent() {
if (this.state.loading) {
return <div className="loading my-32 mx-auto"><div></div></div>
} else {
if (this.state.referrers) {
return (
<React.Fragment>
<h3>Top Referrers</h3>
<div className="flex items-center mt-4 mb-2 justify-between text-grey-dark text-xs font-bold tracking-wide">
<span>Referrer</span>
@ -67,8 +67,10 @@ export default class Referrers extends React.Component {
render() {
return (
<div className="stats-item bg-white shadow-xl rounded p-4" style={{height: '436px'}}>
<h3>Top Referrers</h3>
{ this.renderContent() }
{ this.state.loading && <div className="loading my-32 mx-auto"><div></div></div> }
<FadeIn show={!this.state.loading}>
{ this.renderContent() }
</FadeIn>
</div>
)
}

@ -1,6 +1,7 @@
import React from 'react';
import { withRouter } from 'react-router-dom'
import Chart from 'chart.js'
import FadeIn from '../fade-in'
import { eventName } from '../query'
import numberFormatter from '../number-formatter'
import { isToday, shiftMonths, formatMonth } from '../date'
@ -335,19 +336,20 @@ export default class VisitorGraph extends React.Component {
}
renderInner() {
if (this.state.loading) {
if (this.state.graphData) {
return (
<div className="loading pt-24 sm:pt-32 md:pt-48 mx-auto"><div></div></div>
<LineGraph graphData={this.state.graphData} site={this.props.site} query={this.props.query} />
)
} else if (this.state.graphData) {
return <LineGraph graphData={this.state.graphData} site={this.props.site} query={this.props.query} />
}
}
render() {
return (
<div className="w-full bg-white shadow-xl rounded mt-6 main-graph">
{ this.renderInner() }
{ this.state.loading && <div className="loading pt-24 sm:pt-32 md:pt-48 mx-auto"><div></div></div> }
<FadeIn show={!this.state.loading}>
{ this.renderInner() }
</FadeIn>
</div>
)
}

Loading…
Cancel
Save