Add loading view while waiting for a result

This commit is contained in:
Grégoire Delattre 2017-01-06 23:47:56 +01:00
parent df58a80125
commit 70321d2aaf
8 changed files with 68 additions and 1 deletions

View File

@ -16,6 +16,7 @@
"react": "^15.3.2", "react": "^15.3.2",
"react-bootstrap": "^0.30.6", "react-bootstrap": "^0.30.6",
"react-dom": "^15.3.2", "react-dom": "^15.3.2",
"react-loading": "^0.0.9",
"react-redux": "^4.4.6", "react-redux": "^4.4.6",
"react-redux-form": "^1.2.4", "react-redux-form": "^1.2.4",
"react-router": "^3.0.0", "react-router": "^3.0.0",

View File

@ -0,0 +1,17 @@
import React from 'react'
import Loading from 'react-loading'
export default function Loader() {
return (
<div className="row" id="container">
<div className="col-md-6 col-md-offset-3">
<Loading
type="bars"
height="100%"
width="100%"
color="#EBEBEB"
/>
</div>
</div>
)
}

View File

@ -2,6 +2,7 @@ import React from 'react'
import ListPosters from '../list/posters' import ListPosters from '../list/posters'
import ListDetails from '../list/details' import ListDetails from '../list/details'
import Loader from '../loader/loader'
class MovieButtons extends React.Component { class MovieButtons extends React.Component {
constructor(props) { constructor(props) {
@ -80,6 +81,12 @@ export default class MovieList extends React.Component {
index = 0; index = 0;
} }
const selectedMovie = movies[index]; const selectedMovie = movies[index];
// Loading
if (this.props.movieStore.loading) {
return (<Loader />);
}
return ( return (
<div className="row" id="container"> <div className="row" id="container">
<ListPosters <ListPosters

View File

@ -1,10 +1,15 @@
import React from 'react' import React from 'react'
import Loader from '../loader/loader'
export default class ShowDetails extends React.Component { export default class ShowDetails extends React.Component {
componentWillMount() { componentWillMount() {
this.props.fetchShowDetails(this.props.params.imdbId); this.props.fetchShowDetails(this.props.params.imdbId);
} }
render() { render() {
// Loading
if (this.props.showStore.loading) {
return (<Loader />);
}
return ( return (
<div className="row" id="container"> <div className="row" id="container">
<Header data={this.props.showStore.show} /> <Header data={this.props.showStore.show} />

View File

@ -3,6 +3,7 @@ import { Link } from 'react-router'
import ListDetails from '../list/details' import ListDetails from '../list/details'
import ListPosters from '../list/posters' import ListPosters from '../list/posters'
import Loader from '../loader/loader'
function ShowButtons(props) { function ShowButtons(props) {
const imdbLink = `http://www.imdb.com/title/${props.show.imdb_id}`; const imdbLink = `http://www.imdb.com/title/${props.show.imdb_id}`;
@ -47,6 +48,12 @@ export default class ShowList extends React.Component {
index = 0; index = 0;
} }
const selectedShow = shows[index]; const selectedShow = shows[index];
// Loading
if (this.props.showStore.loading) {
return (<Loader />);
}
return ( return (
<div className="row" id="container"> <div className="row" id="container">
<ListPosters <ListPosters

View File

@ -1,4 +1,5 @@
const defaultState = { const defaultState = {
loading: false,
movies: [], movies: [],
filter: "", filter: "",
perPage: 30, perPage: 30,
@ -9,6 +10,10 @@ const defaultState = {
export default function movieStore(state = defaultState, action) { export default function movieStore(state = defaultState, action) {
switch (action.type) { switch (action.type) {
case 'MOVIE_LIST_FETCH_PENDING':
return Object.assign({}, state, {
loading: true,
})
case 'MOVIE_LIST_FETCH_FULFILLED': case 'MOVIE_LIST_FETCH_FULFILLED':
let selectedImdbId = ""; let selectedImdbId = "";
// Select the first movie // Select the first movie
@ -18,10 +23,16 @@ export default function movieStore(state = defaultState, action) {
return Object.assign({}, state, { return Object.assign({}, state, {
movies: action.payload.data, movies: action.payload.data,
selectedImdbId: selectedImdbId, selectedImdbId: selectedImdbId,
loading: false,
})
case 'SEARCH_MOVIES_PENDING':
return Object.assign({}, state, {
loading: true,
}) })
case 'SEARCH_MOVIES_FULFILLED': case 'SEARCH_MOVIES_FULFILLED':
return Object.assign({}, state, { return Object.assign({}, state, {
movies: action.payload.data, movies: action.payload.data,
loading: false,
}) })
case 'MOVIE_GET_DETAILS_PENDING': case 'MOVIE_GET_DETAILS_PENDING':
return Object.assign({}, state, { return Object.assign({}, state, {

View File

@ -1,4 +1,5 @@
const defaultState = { const defaultState = {
loading: false,
shows: [], shows: [],
filter: "", filter: "",
perPage: 30, perPage: 30,
@ -11,6 +12,10 @@ const defaultState = {
export default function showStore(state = defaultState, action) { export default function showStore(state = defaultState, action) {
switch (action.type) { switch (action.type) {
case 'SHOW_LIST_FETCH_PENDING':
return Object.assign({}, state, {
loading: true,
})
case 'SHOW_LIST_FETCH_FULFILLED': case 'SHOW_LIST_FETCH_FULFILLED':
let selectedImdbId = ""; let selectedImdbId = "";
// Select the first show // Select the first show
@ -20,15 +25,25 @@ export default function showStore(state = defaultState, action) {
return Object.assign({}, state, { return Object.assign({}, state, {
shows: action.payload.data, shows: action.payload.data,
selectedImdbId: selectedImdbId, selectedImdbId: selectedImdbId,
loading: false,
})
case 'SHOW_FETCH_DETAILS_PENDING':
return Object.assign({}, state, {
loading: true,
}) })
case 'SHOW_FETCH_DETAILS_FULFILLED': case 'SHOW_FETCH_DETAILS_FULFILLED':
return Object.assign({}, state, { return Object.assign({}, state, {
show: sortEpisodes(action.payload.data), show: sortEpisodes(action.payload.data),
loading: false,
})
case 'SEARCH_SHOWS_PENDING':
return Object.assign({}, state, {
loading: true,
}) })
return state;
case 'SEARCH_SHOWS_FULFILLED': case 'SEARCH_SHOWS_FULFILLED':
return Object.assign({}, state, { return Object.assign({}, state, {
shows: action.payload.data, shows: action.payload.data,
loading: false,
}) })
case 'SELECT_SHOW': case 'SELECT_SHOW':
// Don't select the show if we're fetching another show's details // Don't select the show if we're fetching another show's details

View File

@ -3081,6 +3081,10 @@ react-dom@^15.3.2:
version "15.3.2" version "15.3.2"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-15.3.2.tgz#c46b0aa5380d7b838e7a59c4a7beff2ed315531f" resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-15.3.2.tgz#c46b0aa5380d7b838e7a59c4a7beff2ed315531f"
react-loading:
version "0.0.9"
resolved "https://registry.yarnpkg.com/react-loading/-/react-loading-0.0.9.tgz#e9fba6948915ba7742a508193828b6c73eb04956"
react-overlays@^0.6.10: react-overlays@^0.6.10:
version "0.6.10" version "0.6.10"
resolved "https://registry.yarnpkg.com/react-overlays/-/react-overlays-0.6.10.tgz#e7e52dad47f00a0fc784eb044428c3a9e874bfa3" resolved "https://registry.yarnpkg.com/react-overlays/-/react-overlays-0.6.10.tgz#e7e52dad47f00a0fc784eb044428c3a9e874bfa3"