Split actions to separate file
Only use the necessary actions for each component
This commit is contained in:
parent
1d1e239709
commit
9ba4af9d7d
@ -1,293 +0,0 @@
|
||||
import { configureAxios, request } from '../requests'
|
||||
|
||||
// ======================
|
||||
// Alerts
|
||||
// ======================
|
||||
|
||||
export function addAlertError(message) {
|
||||
return {
|
||||
type: 'ADD_ALERT_ERROR',
|
||||
payload: {
|
||||
message,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function addAlertOk(message) {
|
||||
return {
|
||||
type: 'ADD_ALERT_OK',
|
||||
payload: {
|
||||
message,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function dismissAlert() {
|
||||
return {
|
||||
type: 'DISMISS_ALERT',
|
||||
}
|
||||
}
|
||||
|
||||
// ======================
|
||||
// Users
|
||||
// ======================
|
||||
|
||||
export function userLogout() {
|
||||
return {
|
||||
type: 'USER_LOGOUT',
|
||||
}
|
||||
}
|
||||
|
||||
export function loginUser(username, password) {
|
||||
return request(
|
||||
'USER_LOGIN',
|
||||
configureAxios().post(
|
||||
'/users/login',
|
||||
{
|
||||
username: username,
|
||||
password: password,
|
||||
},
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
export function updateUser(config) {
|
||||
return request(
|
||||
'USER_UPDATE',
|
||||
configureAxios().post('/users/edit', config),
|
||||
[
|
||||
addAlertOk("User updated"),
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
export function userSignUp(config) {
|
||||
return request(
|
||||
'USER_SIGNUP',
|
||||
configureAxios().post('/users/signup', config)
|
||||
)
|
||||
}
|
||||
|
||||
export function getUserInfos() {
|
||||
return request(
|
||||
'GET_USER',
|
||||
configureAxios().get('/users/details')
|
||||
)
|
||||
}
|
||||
|
||||
// ======================
|
||||
// Movies
|
||||
// ======================
|
||||
|
||||
export function updateLastMovieFetchUrl(url) {
|
||||
return {
|
||||
type: 'UPDATE_LAST_MOVIE_FETCH_URL',
|
||||
payload: {
|
||||
url: url,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export function selectMovie(imdbId) {
|
||||
return {
|
||||
type: 'SELECT_MOVIE',
|
||||
imdbId
|
||||
}
|
||||
}
|
||||
|
||||
export function getMovieExploreOptions() {
|
||||
return request(
|
||||
'MOVIE_GET_EXPLORE_OPTIONS',
|
||||
configureAxios().get('/movies/explore/options')
|
||||
)
|
||||
}
|
||||
|
||||
export function getMovieDetails(imdbId) {
|
||||
return request(
|
||||
'MOVIE_GET_DETAILS',
|
||||
configureAxios().post(`/movies/${imdbId}/refresh`)
|
||||
)
|
||||
}
|
||||
|
||||
export function deleteMovie(imdbId, lastFetchUrl) {
|
||||
return request(
|
||||
'MOVIE_DELETE',
|
||||
configureAxios().delete(`/movies/${imdbId}`),
|
||||
[
|
||||
fetchMovies(lastFetchUrl),
|
||||
addAlertOk("Movie deleted"),
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
export function addMovieToWishlist(imdbId) {
|
||||
return request(
|
||||
'MOVIE_ADD_TO_WISHLIST',
|
||||
configureAxios().post(`/wishlist/movies/${imdbId}`),
|
||||
[
|
||||
addAlertOk("Movie added to the wishlist"),
|
||||
updateMovieWishlistStore(imdbId, true),
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
export function deleteMovieFromWishlist(imdbId) {
|
||||
return request(
|
||||
'MOVIE_DELETE_FROM_WISHLIST',
|
||||
configureAxios().delete(`/wishlist/movies/${imdbId}`),
|
||||
[
|
||||
addAlertOk("Movie deleted from the wishlist"),
|
||||
updateMovieWishlistStore(imdbId, false),
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
export function updateMovieWishlistStore(imdbId, wishlisted) {
|
||||
return {
|
||||
type: 'MOVIE_UPDATE_STORE_WISHLIST',
|
||||
payload: {
|
||||
imdbId,
|
||||
wishlisted,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function fetchMovies(url) {
|
||||
return request(
|
||||
'MOVIE_LIST_FETCH',
|
||||
configureAxios().get(url),
|
||||
[
|
||||
updateLastMovieFetchUrl(url),
|
||||
]
|
||||
)
|
||||
}
|
||||
|
||||
// ======================
|
||||
// Shows
|
||||
// ======================
|
||||
|
||||
export function fetchShows(url) {
|
||||
return request(
|
||||
'SHOW_LIST_FETCH',
|
||||
configureAxios().get(url),
|
||||
[
|
||||
updateLastShowsFetchUrl(url),
|
||||
]
|
||||
)
|
||||
}
|
||||
|
||||
export function getShowDetails(imdbId) {
|
||||
return request(
|
||||
'SHOW_GET_DETAILS',
|
||||
configureAxios().post(`/shows/${imdbId}/refresh`)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
export function getEpisodeDetails(imdbId, season, episode) {
|
||||
return request(
|
||||
'EPISODE_GET_DETAILS',
|
||||
configureAxios().post(`/shows/${imdbId}/seasons/${season}/episodes/${episode}`),
|
||||
)
|
||||
}
|
||||
|
||||
export function updateEpisodeDetailsStore(imdbId, season, episode) {
|
||||
return {
|
||||
type: 'EPISODE_GET_DETAILS',
|
||||
payload: {
|
||||
imdbId,
|
||||
season,
|
||||
episode,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export function fetchShowDetails(imdbId) {
|
||||
return request(
|
||||
'SHOW_FETCH_DETAILS',
|
||||
configureAxios().get(`/shows/${imdbId}`)
|
||||
)
|
||||
}
|
||||
|
||||
export function addShowToWishlist(imdbId, season = null, episode = null) {
|
||||
return request(
|
||||
'SHOW_ADD_TO_WISHLIST',
|
||||
configureAxios().post(`/wishlist/shows/${imdbId}`, {
|
||||
season: season,
|
||||
episode: episode,
|
||||
}),
|
||||
[
|
||||
addAlertOk("Show added to the wishlist"),
|
||||
updateShowWishlistStore(imdbId, true, season, episode),
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
export function deleteShowFromWishlist(imdbId) {
|
||||
return request(
|
||||
'SHOW_DELETE_FROM_WISHLIST',
|
||||
configureAxios().delete(`/wishlist/shows/${imdbId}`),
|
||||
[
|
||||
addAlertOk("Show deleted from the wishlist"),
|
||||
updateShowWishlistStore(imdbId, false),
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
export function updateShowWishlistStore(imdbId, wishlisted, season = null, episode = null) {
|
||||
return {
|
||||
type: 'SHOW_UPDATE_STORE_WISHLIST',
|
||||
payload: {
|
||||
wishlisted: wishlisted,
|
||||
imdbId,
|
||||
season,
|
||||
episode,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function getShowExploreOptions() {
|
||||
return request(
|
||||
'SHOW_GET_EXPLORE_OPTIONS',
|
||||
configureAxios().get('/shows/explore/options')
|
||||
)
|
||||
}
|
||||
|
||||
export function selectShow(imdbId) {
|
||||
return {
|
||||
type: 'SELECT_SHOW',
|
||||
imdbId
|
||||
}
|
||||
}
|
||||
|
||||
export function updateLastShowsFetchUrl(url) {
|
||||
return {
|
||||
type: 'UPDATE_LAST_SHOWS_FETCH_URL',
|
||||
payload: {
|
||||
url: url,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// ======================
|
||||
// AddTorrent
|
||||
// ======================
|
||||
|
||||
export function addTorrent(url) {
|
||||
return request(
|
||||
'ADD_TORRENT',
|
||||
configureAxios().post('/torrents', {
|
||||
url: url,
|
||||
}),
|
||||
[
|
||||
addAlertOk("Torrent added"),
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
export function fetchTorrents() {
|
||||
return request(
|
||||
'TORRENTS_FETCH',
|
||||
configureAxios().get('/torrents')
|
||||
)
|
||||
}
|
23
src/public/js/actions/alerts.js
Normal file
23
src/public/js/actions/alerts.js
Normal file
@ -0,0 +1,23 @@
|
||||
export function addAlertError(message) {
|
||||
return {
|
||||
type: 'ADD_ALERT_ERROR',
|
||||
payload: {
|
||||
message,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function addAlertOk(message) {
|
||||
return {
|
||||
type: 'ADD_ALERT_OK',
|
||||
payload: {
|
||||
message,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function dismissAlert() {
|
||||
return {
|
||||
type: 'DISMISS_ALERT',
|
||||
}
|
||||
}
|
86
src/public/js/actions/movies.js
Normal file
86
src/public/js/actions/movies.js
Normal file
@ -0,0 +1,86 @@
|
||||
import { configureAxios, request } from '../requests'
|
||||
|
||||
import { addAlertOk } from './alerts'
|
||||
|
||||
export function updateLastMovieFetchUrl(url) {
|
||||
return {
|
||||
type: 'UPDATE_LAST_MOVIE_FETCH_URL',
|
||||
payload: {
|
||||
url: url,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export function selectMovie(imdbId) {
|
||||
return {
|
||||
type: 'SELECT_MOVIE',
|
||||
imdbId
|
||||
}
|
||||
}
|
||||
|
||||
export function getMovieExploreOptions() {
|
||||
return request(
|
||||
'MOVIE_GET_EXPLORE_OPTIONS',
|
||||
configureAxios().get('/movies/explore/options')
|
||||
)
|
||||
}
|
||||
|
||||
export function getMovieDetails(imdbId) {
|
||||
return request(
|
||||
'MOVIE_GET_DETAILS',
|
||||
configureAxios().post(`/movies/${imdbId}/refresh`)
|
||||
)
|
||||
}
|
||||
|
||||
export function deleteMovie(imdbId, lastFetchUrl) {
|
||||
return request(
|
||||
'MOVIE_DELETE',
|
||||
configureAxios().delete(`/movies/${imdbId}`),
|
||||
[
|
||||
fetchMovies(lastFetchUrl),
|
||||
addAlertOk("Movie deleted"),
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
export function addMovieToWishlist(imdbId) {
|
||||
return request(
|
||||
'MOVIE_ADD_TO_WISHLIST',
|
||||
configureAxios().post(`/wishlist/movies/${imdbId}`),
|
||||
[
|
||||
addAlertOk("Movie added to the wishlist"),
|
||||
updateMovieWishlistStore(imdbId, true),
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
export function deleteMovieFromWishlist(imdbId) {
|
||||
return request(
|
||||
'MOVIE_DELETE_FROM_WISHLIST',
|
||||
configureAxios().delete(`/wishlist/movies/${imdbId}`),
|
||||
[
|
||||
addAlertOk("Movie deleted from the wishlist"),
|
||||
updateMovieWishlistStore(imdbId, false),
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
export function updateMovieWishlistStore(imdbId, wishlisted) {
|
||||
return {
|
||||
type: 'MOVIE_UPDATE_STORE_WISHLIST',
|
||||
payload: {
|
||||
imdbId,
|
||||
wishlisted,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function fetchMovies(url) {
|
||||
return request(
|
||||
'MOVIE_LIST_FETCH',
|
||||
configureAxios().get(url),
|
||||
[
|
||||
updateLastMovieFetchUrl(url),
|
||||
]
|
||||
)
|
||||
}
|
106
src/public/js/actions/shows.js
Normal file
106
src/public/js/actions/shows.js
Normal file
@ -0,0 +1,106 @@
|
||||
import { configureAxios, request } from '../requests'
|
||||
|
||||
import { addAlertOk } from './alerts'
|
||||
|
||||
export function fetchShows(url) {
|
||||
return request(
|
||||
'SHOW_LIST_FETCH',
|
||||
configureAxios().get(url),
|
||||
[
|
||||
updateLastShowsFetchUrl(url),
|
||||
]
|
||||
)
|
||||
}
|
||||
|
||||
export function getShowDetails(imdbId) {
|
||||
return request(
|
||||
'SHOW_GET_DETAILS',
|
||||
configureAxios().post(`/shows/${imdbId}/refresh`)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
export function getEpisodeDetails(imdbId, season, episode) {
|
||||
return request(
|
||||
'EPISODE_GET_DETAILS',
|
||||
configureAxios().post(`/shows/${imdbId}/seasons/${season}/episodes/${episode}`),
|
||||
)
|
||||
}
|
||||
|
||||
export function updateEpisodeDetailsStore(imdbId, season, episode) {
|
||||
return {
|
||||
type: 'EPISODE_GET_DETAILS',
|
||||
payload: {
|
||||
imdbId,
|
||||
season,
|
||||
episode,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export function fetchShowDetails(imdbId) {
|
||||
return request(
|
||||
'SHOW_FETCH_DETAILS',
|
||||
configureAxios().get(`/shows/${imdbId}`)
|
||||
)
|
||||
}
|
||||
|
||||
export function addShowToWishlist(imdbId, season = null, episode = null) {
|
||||
return request(
|
||||
'SHOW_ADD_TO_WISHLIST',
|
||||
configureAxios().post(`/wishlist/shows/${imdbId}`, {
|
||||
season: season,
|
||||
episode: episode,
|
||||
}),
|
||||
[
|
||||
addAlertOk("Show added to the wishlist"),
|
||||
updateShowWishlistStore(imdbId, true, season, episode),
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
export function deleteShowFromWishlist(imdbId) {
|
||||
return request(
|
||||
'SHOW_DELETE_FROM_WISHLIST',
|
||||
configureAxios().delete(`/wishlist/shows/${imdbId}`),
|
||||
[
|
||||
addAlertOk("Show deleted from the wishlist"),
|
||||
updateShowWishlistStore(imdbId, false),
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
export function updateShowWishlistStore(imdbId, wishlisted, season = null, episode = null) {
|
||||
return {
|
||||
type: 'SHOW_UPDATE_STORE_WISHLIST',
|
||||
payload: {
|
||||
wishlisted: wishlisted,
|
||||
imdbId,
|
||||
season,
|
||||
episode,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function getShowExploreOptions() {
|
||||
return request(
|
||||
'SHOW_GET_EXPLORE_OPTIONS',
|
||||
configureAxios().get('/shows/explore/options')
|
||||
)
|
||||
}
|
||||
|
||||
export function selectShow(imdbId) {
|
||||
return {
|
||||
type: 'SELECT_SHOW',
|
||||
imdbId
|
||||
}
|
||||
}
|
||||
|
||||
export function updateLastShowsFetchUrl(url) {
|
||||
return {
|
||||
type: 'UPDATE_LAST_SHOWS_FETCH_URL',
|
||||
payload: {
|
||||
url: url,
|
||||
},
|
||||
}
|
||||
}
|
22
src/public/js/actions/torrents.js
Normal file
22
src/public/js/actions/torrents.js
Normal file
@ -0,0 +1,22 @@
|
||||
import { configureAxios, request } from '../requests'
|
||||
|
||||
import { addAlertOk } from './alerts'
|
||||
|
||||
export function addTorrent(url) {
|
||||
return request(
|
||||
'ADD_TORRENT',
|
||||
configureAxios().post('/torrents', {
|
||||
url: url,
|
||||
}),
|
||||
[
|
||||
addAlertOk("Torrent added"),
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
export function fetchTorrents() {
|
||||
return request(
|
||||
'TORRENTS_FETCH',
|
||||
configureAxios().get('/torrents')
|
||||
)
|
||||
}
|
46
src/public/js/actions/users.js
Normal file
46
src/public/js/actions/users.js
Normal file
@ -0,0 +1,46 @@
|
||||
import { configureAxios, request } from '../requests'
|
||||
|
||||
import { addAlertOk } from './alerts'
|
||||
|
||||
export function userLogout() {
|
||||
return {
|
||||
type: 'USER_LOGOUT',
|
||||
}
|
||||
}
|
||||
|
||||
export function loginUser(username, password) {
|
||||
return request(
|
||||
'USER_LOGIN',
|
||||
configureAxios().post(
|
||||
'/users/login',
|
||||
{
|
||||
username: username,
|
||||
password: password,
|
||||
},
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
export function updateUser(config) {
|
||||
return request(
|
||||
'USER_UPDATE',
|
||||
configureAxios().post('/users/edit', config),
|
||||
[
|
||||
addAlertOk("User updated"),
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
export function userSignUp(config) {
|
||||
return request(
|
||||
'USER_SIGNUP',
|
||||
configureAxios().post('/users/signup', config)
|
||||
)
|
||||
}
|
||||
|
||||
export function getUserInfos() {
|
||||
return request(
|
||||
'GET_USER',
|
||||
configureAxios().get('/users/details')
|
||||
)
|
||||
}
|
@ -28,7 +28,7 @@ import { Router } from 'react-router'
|
||||
import { routerActions } from 'react-router-redux'
|
||||
|
||||
// Action creators
|
||||
import { dismissAlert } from './actions/actionCreators'
|
||||
import { dismissAlert } from './actions/alerts'
|
||||
|
||||
// Store
|
||||
import store, { history } from './store'
|
||||
@ -41,9 +41,13 @@ import Alert from './components/alerts/alert'
|
||||
import getRoutes from './routes'
|
||||
|
||||
function mapStateToProps(state) {
|
||||
let torrentCount = 0;
|
||||
if (state.torrentStore.has('torrents')) {
|
||||
torrentCount = state.torrentStore.has('torrents').size;
|
||||
}
|
||||
return {
|
||||
username: state.userStore.username,
|
||||
torrentCount: state.torrentStore.get('torrents').size,
|
||||
torrentCount: torrentCount,
|
||||
alerts: state.alerts,
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
import React from 'react'
|
||||
import { connect } from 'react-redux'
|
||||
import { bindActionCreators } from 'redux'
|
||||
import { selectMovie, getMovieDetails, addTorrent,
|
||||
addMovieToWishlist, deleteMovieFromWishlist } from '../../actions/actionCreators'
|
||||
import { addTorrent } from '../../actions/torrents'
|
||||
import { addMovieToWishlist, deleteMovieFromWishlist,
|
||||
getMovieDetails, selectMovie } from '../../actions/movies'
|
||||
|
||||
import DownloadButton from '../buttons/download'
|
||||
import TorrentsButton from './torrents'
|
||||
|
@ -1,8 +1,9 @@
|
||||
import React from 'react'
|
||||
import { connect } from 'react-redux'
|
||||
import { bindActionCreators } from 'redux'
|
||||
import { addTorrent, addShowToWishlist, deleteFromWishlist,
|
||||
updateShowDetails, updateEpisodeDetailsStore, getEpisodeDetails } from '../../actions/actionCreators'
|
||||
import { addTorrent } from '../../actions/torrents'
|
||||
import { addShowToWishlist, deleteFromWishlist, getEpisodeDetails,
|
||||
updateEpisodeDetailsStore, updateShowDetails } from '../../actions/shows'
|
||||
|
||||
import Loader from '../loader/loader'
|
||||
import DownloadButton from '../buttons/download'
|
||||
|
@ -2,7 +2,7 @@ import React from 'react'
|
||||
import { connect } from 'react-redux'
|
||||
import { bindActionCreators } from 'redux'
|
||||
import { selectShow, addShowToWishlist,
|
||||
deleteFromWishlist, getShowDetails } from '../../actions/actionCreators'
|
||||
deleteFromWishlist, getShowDetails } from '../../actions/shows'
|
||||
|
||||
import ListDetails from '../list/details'
|
||||
import ListPosters from '../list/posters'
|
||||
|
@ -1,7 +1,7 @@
|
||||
import React from 'react'
|
||||
import { connect } from 'react-redux'
|
||||
import { bindActionCreators } from 'redux'
|
||||
import { addTorrent } from '../../actions/actionCreators'
|
||||
import { addTorrent } from '../../actions/torrents'
|
||||
|
||||
function mapStateToProps(state) {
|
||||
return { torrents: state.torrentStore.get('torrents') };
|
||||
|
@ -1,18 +1,25 @@
|
||||
import React from 'react'
|
||||
import { Control, Form } from 'react-redux-form';
|
||||
import { connect } from 'react-redux'
|
||||
import { bindActionCreators } from 'redux'
|
||||
|
||||
export default class UserEdit extends React.Component {
|
||||
componentWillMount() {
|
||||
this.props.getUserInfos();
|
||||
}
|
||||
import { Control, Form } from 'react-redux-form';
|
||||
import { updateUser } from '../../actions/users'
|
||||
|
||||
function mapStateToProps(state) {
|
||||
return { user: state.userStore };
|
||||
}
|
||||
const mapDispatchToProps = (dispatch) =>
|
||||
bindActionCreators({ updateUser }, dispatch)
|
||||
|
||||
class UserEdit extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.handleSubmit = this.handleSubmit.bind(this);
|
||||
}
|
||||
handleSubmit() {
|
||||
this.props.updateUser({
|
||||
'polochon_url': this.props.userStore.polochonUrl,
|
||||
'polochon_token': this.props.userStore.polochonToken,
|
||||
'polochon_url': this.props.user.polochonUrl,
|
||||
'polochon_token': this.props.user.polochonToken,
|
||||
'password': this.refs.newPassword.value,
|
||||
'password_confirm': this.refs.newPasswordConfirm.value,
|
||||
});
|
||||
@ -58,3 +65,4 @@ export default class UserEdit extends React.Component {
|
||||
);
|
||||
}
|
||||
}
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(UserEdit);
|
||||
|
@ -1,12 +1,22 @@
|
||||
import React from 'react'
|
||||
import { connect } from 'react-redux'
|
||||
import { bindActionCreators } from 'redux'
|
||||
|
||||
export default class UserLoginForm extends React.Component {
|
||||
import { loginUser } from '../../actions/users'
|
||||
|
||||
function mapStateToProps(state) {
|
||||
return { user: state.userStore };
|
||||
}
|
||||
const mapDispatchToProps = (dispatch) =>
|
||||
bindActionCreators({ loginUser }, dispatch)
|
||||
|
||||
class UserLoginForm extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.handleSubmit = this.handleSubmit.bind(this);
|
||||
}
|
||||
componentWillReceiveProps(nextProps) {
|
||||
if (!nextProps.userStore.isLogged) {
|
||||
if (!nextProps.user.isLogged) {
|
||||
return
|
||||
}
|
||||
if (!nextProps.location.query.redirect) {
|
||||
@ -19,7 +29,7 @@ export default class UserLoginForm extends React.Component {
|
||||
}
|
||||
handleSubmit(e) {
|
||||
e.preventDefault();
|
||||
if (this.props.userStore.userLoading) {
|
||||
if (this.props.user.userLoading) {
|
||||
return;
|
||||
}
|
||||
const username = this.refs.username.value;
|
||||
@ -47,12 +57,12 @@ export default class UserLoginForm extends React.Component {
|
||||
<p></p>
|
||||
</div>
|
||||
<div>
|
||||
{this.props.userStore.userLoading &&
|
||||
{this.props.user.userLoading &&
|
||||
<button className="btn btn-primary pull-right">
|
||||
<i className="fa fa-spinner fa-spin"></i>
|
||||
</button>
|
||||
}
|
||||
{this.props.userStore.userLoading ||
|
||||
{this.props.user.userLoading ||
|
||||
<input className="btn btn-primary pull-right" type="submit" value="Log in"/>
|
||||
}
|
||||
<br/>
|
||||
@ -64,3 +74,4 @@ export default class UserLoginForm extends React.Component {
|
||||
);
|
||||
}
|
||||
}
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(UserLoginForm);
|
||||
|
@ -1,6 +1,13 @@
|
||||
import React from 'react'
|
||||
import { connect } from 'react-redux'
|
||||
import { bindActionCreators } from 'redux'
|
||||
|
||||
export default class UserSignUp extends React.Component {
|
||||
import { userSignUp } from '../../actions/users'
|
||||
|
||||
const mapDispatchToProps = (dispatch) =>
|
||||
bindActionCreators({ userSignUp }, dispatch)
|
||||
|
||||
class UserSignUp extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.handleSubmit = this.handleSubmit.bind(this);
|
||||
@ -46,3 +53,4 @@ export default class UserSignUp extends React.Component {
|
||||
);
|
||||
}
|
||||
}
|
||||
export default connect(null, mapDispatchToProps)(UserSignUp);
|
||||
|
@ -8,7 +8,11 @@ import UserEdit from './components/users/edit'
|
||||
import UserSignUp from './components/users/signup'
|
||||
import TorrentList from './components/torrents/list'
|
||||
|
||||
import * as actionCreators from './actions/actionCreators'
|
||||
import { fetchTorrents } from './actions/torrents'
|
||||
import { userLogout, getUserInfos } from './actions/users'
|
||||
import { fetchMovies, getMovieExploreOptions } from './actions/movies'
|
||||
import { fetchShows, fetchShowDetails, getShowExploreOptions } from './actions/shows'
|
||||
|
||||
import store from './store'
|
||||
|
||||
function startPollingTorrents() {
|
||||
@ -56,7 +60,7 @@ const loginCheck = function(nextState, replace, next, f = null) {
|
||||
if (!pollingTorrentsId) {
|
||||
// Fetch the torrents every 10s
|
||||
pollingTorrentsId = setInterval(function() {
|
||||
store.dispatch(actionCreators.fetchTorrents());
|
||||
store.dispatch(fetchTorrents());
|
||||
}, 10000);
|
||||
}
|
||||
}
|
||||
@ -90,7 +94,9 @@ export default function getRoutes(App) {
|
||||
path: '/users/edit',
|
||||
component: UserEdit,
|
||||
onEnter: function(nextState, replace, next) {
|
||||
loginCheck(nextState, replace, next);
|
||||
loginCheck(nextState, replace, next, function() {
|
||||
store.dispatch(getUserInfos());
|
||||
});
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -101,7 +107,7 @@ export default function getRoutes(App) {
|
||||
clearInterval(pollingTorrentsId);
|
||||
pollingTorrentsId = null;
|
||||
}
|
||||
store.dispatch(actionCreators.userLogout());
|
||||
store.dispatch(userLogout());
|
||||
replace('/users/login');
|
||||
next();
|
||||
},
|
||||
@ -111,7 +117,7 @@ export default function getRoutes(App) {
|
||||
component: MovieList,
|
||||
onEnter: function(nextState, replace, next) {
|
||||
loginCheck(nextState, replace, next, function() {
|
||||
store.dispatch(actionCreators.fetchMovies(`/movies/search/${nextState.params.search}`));
|
||||
store.dispatch(fetchMovies(`/movies/search/${nextState.params.search}`));
|
||||
});
|
||||
},
|
||||
},
|
||||
@ -120,7 +126,7 @@ export default function getRoutes(App) {
|
||||
component: MovieList,
|
||||
onEnter: function(nextState, replace, next) {
|
||||
loginCheck(nextState, replace, next, function() {
|
||||
store.dispatch(actionCreators.fetchMovies('/movies/polochon'));
|
||||
store.dispatch(fetchMovies('/movies/polochon'));
|
||||
});
|
||||
},
|
||||
},
|
||||
@ -132,9 +138,9 @@ export default function getRoutes(App) {
|
||||
var state = store.getState();
|
||||
// Fetch the explore options
|
||||
if (Object.keys(state.movieStore.exploreOptions).length === 0) {
|
||||
store.dispatch(actionCreators.getMovieExploreOptions());
|
||||
store.dispatch(getMovieExploreOptions());
|
||||
}
|
||||
store.dispatch(actionCreators.fetchMovies(
|
||||
store.dispatch(fetchMovies(
|
||||
`/movies/explore?source=${encodeURI(nextState.params.source)}&category=${encodeURI(nextState.params.category)}`
|
||||
));
|
||||
});
|
||||
@ -145,7 +151,7 @@ export default function getRoutes(App) {
|
||||
component: MovieList,
|
||||
onEnter: function(nextState, replace, next) {
|
||||
loginCheck(nextState, replace, next, function() {
|
||||
store.dispatch(actionCreators.fetchMovies('/wishlist/movies'));
|
||||
store.dispatch(fetchMovies('/wishlist/movies'));
|
||||
});
|
||||
},
|
||||
},
|
||||
@ -154,7 +160,7 @@ export default function getRoutes(App) {
|
||||
component: ShowList,
|
||||
onEnter: function(nextState, replace, next) {
|
||||
loginCheck(nextState, replace, next, function() {
|
||||
store.dispatch(actionCreators.fetchShows(`/shows/search/${nextState.params.search}`));
|
||||
store.dispatch(fetchShows(`/shows/search/${nextState.params.search}`));
|
||||
});
|
||||
},
|
||||
},
|
||||
@ -163,7 +169,7 @@ export default function getRoutes(App) {
|
||||
component: ShowList,
|
||||
onEnter: function(nextState, replace, next) {
|
||||
loginCheck(nextState, replace, next, function() {
|
||||
store.dispatch(actionCreators.fetchShows('/shows/polochon'));
|
||||
store.dispatch(fetchShows('/shows/polochon'));
|
||||
});
|
||||
},
|
||||
},
|
||||
@ -172,7 +178,7 @@ export default function getRoutes(App) {
|
||||
component: ShowList,
|
||||
onEnter: function(nextState, replace, next) {
|
||||
loginCheck(nextState, replace, next, function() {
|
||||
store.dispatch(actionCreators.fetchShows('/wishlist/shows'));
|
||||
store.dispatch(fetchShows('/wishlist/shows'));
|
||||
});
|
||||
},
|
||||
},
|
||||
@ -181,7 +187,7 @@ export default function getRoutes(App) {
|
||||
component: ShowDetails,
|
||||
onEnter: function(nextState, replace, next) {
|
||||
loginCheck(nextState, replace, next, function() {
|
||||
store.dispatch(actionCreators.fetchShowDetails(nextState.params.imdbId));
|
||||
store.dispatch(fetchShowDetails(nextState.params.imdbId));
|
||||
});
|
||||
},
|
||||
},
|
||||
@ -193,9 +199,9 @@ export default function getRoutes(App) {
|
||||
var state = store.getState();
|
||||
// Fetch the explore options
|
||||
if (Object.keys(state.showStore.exploreOptions).length === 0) {
|
||||
store.dispatch(actionCreators.getShowExploreOptions());
|
||||
store.dispatch(getShowExploreOptions());
|
||||
}
|
||||
store.dispatch(actionCreators.fetchShows(
|
||||
store.dispatch(fetchShows(
|
||||
`/shows/explore?source=${encodeURI(nextState.params.source)}&category=${encodeURI(nextState.params.category)}`
|
||||
));
|
||||
});
|
||||
@ -206,7 +212,7 @@ export default function getRoutes(App) {
|
||||
component: TorrentList,
|
||||
onEnter: function(nextState, replace, next) {
|
||||
loginCheck(nextState, replace, next, function() {
|
||||
store.dispatch(actionCreators.fetchTorrents());
|
||||
store.dispatch(fetchTorrents());
|
||||
});
|
||||
},
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user