Lint routes.js

This commit is contained in:
Grégoire Delattre 2017-06-02 21:23:28 +02:00
parent 2beb872de9
commit 6075767960

View File

@ -1,31 +1,29 @@
import React from 'react' import MovieList from "./components/movies/list"
import ShowList from "./components/shows/list"
import ShowDetails from "./components/shows/details"
import UserLoginForm from "./components/users/login"
import UserEdit from "./components/users/edit"
import UserSignUp from "./components/users/signup"
import TorrentList from "./components/torrents/list"
import MovieList from './components/movies/list' import { fetchTorrents } from "./actions/torrents"
import ShowList from './components/shows/list' import { userLogout, getUserInfos } from "./actions/users"
import ShowDetails from './components/shows/details' import { fetchMovies, getMovieExploreOptions } from "./actions/movies"
import UserLoginForm from './components/users/login' import { fetchShows, fetchShowDetails, getShowExploreOptions } from "./actions/shows"
import UserEdit from './components/users/edit'
import UserSignUp from './components/users/signup'
import TorrentList from './components/torrents/list'
import { fetchTorrents } from './actions/torrents' import store from "./store"
import { userLogout, getUserInfos } from './actions/users'
import { fetchMovies, getMovieExploreOptions } from './actions/movies'
import { fetchShows, fetchShowDetails, getShowExploreOptions } from './actions/shows'
import store from './store'
// This function returns true if the user is logged in, false otherwise // This function returns true if the user is logged in, false otherwise
function isLoggedIn() { function isLoggedIn() {
const state = store.getState(); const state = store.getState();
const isLogged = state.userStore.isLogged; const isLogged = state.userStore.isLogged;
let token = localStorage.getItem('token'); let token = localStorage.getItem("token");
// Let's check if the user has a token, if he does let's assume he's logged // Let's check if the user has a token, if he does let's assume he's logged
// in. If that's not the case he will be logged out on the fisrt query // in. If that's not the case he will be logged out on the fisrt query
if (token && token !== "") { if (token && token !== "") {
store.dispatch({ store.dispatch({
type: 'USER_SET_TOKEN', type: "USER_SET_TOKEN",
payload: { payload: {
token: token, token: token,
}, },
@ -43,7 +41,7 @@ var pollingTorrentsId;
const loginCheck = function(nextState, replace, next, f = null) { const loginCheck = function(nextState, replace, next, f = null) {
const loggedIn = isLoggedIn(); const loggedIn = isLoggedIn();
if (!loggedIn) { if (!loggedIn) {
replace('/users/login'); replace("/users/login");
} else { } else {
if (f) { if (f) {
f(); f();
@ -61,19 +59,19 @@ const loginCheck = function(nextState, replace, next, f = null) {
next(); next();
} }
const defaultRoute = '/movies/explore/yts/seeds'; const defaultRoute = "/movies/explore/yts/seeds";
export default function getRoutes(App) { export default function getRoutes(App) {
return { return {
path: '/', path: "/",
component: App, component: App,
indexRoute: {onEnter: ({params}, replace) => replace(defaultRoute)}, indexRoute: {onEnter: ({params}, replace) => replace(defaultRoute)},
childRoutes: [ childRoutes: [
{ {
path: '/users/signup', path: "/users/signup",
component: UserSignUp component: UserSignUp
}, },
{ {
path: '/users/login', path: "/users/login",
component: UserLoginForm, component: UserLoginForm,
onEnter: function(nextState, replace, next) { onEnter: function(nextState, replace, next) {
if (isLoggedIn()) { if (isLoggedIn()) {
@ -84,7 +82,7 @@ export default function getRoutes(App) {
}, },
}, },
{ {
path: '/users/edit', path: "/users/edit",
component: UserEdit, component: UserEdit,
onEnter: function(nextState, replace, next) { onEnter: function(nextState, replace, next) {
loginCheck(nextState, replace, next, function() { loginCheck(nextState, replace, next, function() {
@ -93,7 +91,7 @@ export default function getRoutes(App) {
}, },
}, },
{ {
path: '/users/logout', path: "/users/logout",
onEnter: function(nextState, replace, next) { onEnter: function(nextState, replace, next) {
// Stop polling // Stop polling
if (pollingTorrentsId !== null) { if (pollingTorrentsId !== null) {
@ -101,12 +99,12 @@ export default function getRoutes(App) {
pollingTorrentsId = null; pollingTorrentsId = null;
} }
store.dispatch(userLogout()); store.dispatch(userLogout());
replace('/users/login'); replace("/users/login");
next(); next();
}, },
}, },
{ {
path: '/movies/search/:search', path: "/movies/search/:search",
component: MovieList, component: MovieList,
onEnter: function(nextState, replace, next) { onEnter: function(nextState, replace, next) {
loginCheck(nextState, replace, next, function() { loginCheck(nextState, replace, next, function() {
@ -115,22 +113,22 @@ export default function getRoutes(App) {
}, },
}, },
{ {
path: '/movies/polochon', path: "/movies/polochon",
component: MovieList, component: MovieList,
onEnter: function(nextState, replace, next) { onEnter: function(nextState, replace, next) {
loginCheck(nextState, replace, next, function() { loginCheck(nextState, replace, next, function() {
store.dispatch(fetchMovies('/movies/polochon')); store.dispatch(fetchMovies("/movies/polochon"));
}); });
}, },
}, },
{ {
path: '/movies/explore/:source/:category', path: "/movies/explore/:source/:category",
component: MovieList, component: MovieList,
onEnter: function(nextState, replace, next) { onEnter: function(nextState, replace, next) {
loginCheck(nextState, replace, next, function() { loginCheck(nextState, replace, next, function() {
var state = store.getState(); var state = store.getState();
// Fetch the explore options // Fetch the explore options
if (state.movieStore.get('exploreOptions').size === 0) { if (state.movieStore.get("exploreOptions").size === 0) {
store.dispatch(getMovieExploreOptions()); store.dispatch(getMovieExploreOptions());
} }
store.dispatch(fetchMovies( store.dispatch(fetchMovies(
@ -140,16 +138,16 @@ export default function getRoutes(App) {
}, },
}, },
{ {
path: '/movies/wishlist', path: "/movies/wishlist",
component: MovieList, component: MovieList,
onEnter: function(nextState, replace, next) { onEnter: function(nextState, replace, next) {
loginCheck(nextState, replace, next, function() { loginCheck(nextState, replace, next, function() {
store.dispatch(fetchMovies('/wishlist/movies')); store.dispatch(fetchMovies("/wishlist/movies"));
}); });
}, },
}, },
{ {
path: '/shows/search/:search', path: "/shows/search/:search",
component: ShowList, component: ShowList,
onEnter: function(nextState, replace, next) { onEnter: function(nextState, replace, next) {
loginCheck(nextState, replace, next, function() { loginCheck(nextState, replace, next, function() {
@ -158,25 +156,25 @@ export default function getRoutes(App) {
}, },
}, },
{ {
path: '/shows/polochon', path: "/shows/polochon",
component: ShowList, component: ShowList,
onEnter: function(nextState, replace, next) { onEnter: function(nextState, replace, next) {
loginCheck(nextState, replace, next, function() { loginCheck(nextState, replace, next, function() {
store.dispatch(fetchShows('/shows/polochon')); store.dispatch(fetchShows("/shows/polochon"));
}); });
}, },
}, },
{ {
path: '/shows/wishlist', path: "/shows/wishlist",
component: ShowList, component: ShowList,
onEnter: function(nextState, replace, next) { onEnter: function(nextState, replace, next) {
loginCheck(nextState, replace, next, function() { loginCheck(nextState, replace, next, function() {
store.dispatch(fetchShows('/wishlist/shows')); store.dispatch(fetchShows("/wishlist/shows"));
}); });
}, },
}, },
{ {
path: '/shows/details/:imdbId', path: "/shows/details/:imdbId",
component: ShowDetails, component: ShowDetails,
onEnter: function(nextState, replace, next) { onEnter: function(nextState, replace, next) {
loginCheck(nextState, replace, next, function() { loginCheck(nextState, replace, next, function() {
@ -185,13 +183,13 @@ export default function getRoutes(App) {
}, },
}, },
{ {
path: '/shows/explore/:source/:category', path: "/shows/explore/:source/:category",
component: ShowList, component: ShowList,
onEnter: function(nextState, replace, next) { onEnter: function(nextState, replace, next) {
loginCheck(nextState, replace, next, function() { loginCheck(nextState, replace, next, function() {
var state = store.getState(); var state = store.getState();
// Fetch the explore options // Fetch the explore options
if (state.showsStore.get('exploreOptions').size === 0) { if (state.showsStore.get("exploreOptions").size === 0) {
store.dispatch(getShowExploreOptions()); store.dispatch(getShowExploreOptions());
} }
store.dispatch(fetchShows( store.dispatch(fetchShows(
@ -201,7 +199,7 @@ export default function getRoutes(App) {
}, },
}, },
{ {
path: '/torrents', path: "/torrents",
component: TorrentList, component: TorrentList,
onEnter: function(nextState, replace, next) { onEnter: function(nextState, replace, next) {
loginCheck(nextState, replace, next, function() { loginCheck(nextState, replace, next, function() {