1
0
mirror of https://github.com/ascribe/onion.git synced 2024-11-15 09:35:10 +01:00
onion/js/actions/piece_list_actions.js

67 lines
1.9 KiB
JavaScript
Raw Normal View History

'use strict';
import { alt } from '../alt';
2015-07-24 13:44:28 +02:00
import Q from 'q';
import PieceListFetcher from '../fetchers/piece_list_fetcher';
2015-08-06 18:03:13 +02:00
class PieceListActions {
constructor() {
this.generateActions(
2015-07-01 19:05:47 +02:00
'updatePieceList',
2015-07-09 15:44:20 +02:00
'updatePieceListRequestActions',
2015-07-10 13:54:25 +02:00
'updatePropertyForPiece'
);
}
fetchPieceList(page, pageSize, search, orderBy, orderAsc, filterBy) {
2015-07-13 19:12:24 +02:00
// To prevent flickering on a pagination request,
// we overwrite the piecelist with an empty list before
// pieceListCount === -1 defines the loading state
this.actions.updatePieceList({
page,
pageSize,
orderBy,
orderAsc,
filterBy,
search: '',
pieceList: [],
pieceListCount: -1,
unfilteredPieceListCount: -1
2015-07-13 19:12:24 +02:00
});
// afterwards, we can load the list
2015-07-24 13:44:28 +02:00
return Q.Promise((resolve, reject) => {
2015-07-01 19:05:47 +02:00
PieceListFetcher
.fetch(page, pageSize, search, orderBy, orderAsc, filterBy)
2015-07-01 19:05:47 +02:00
.then((res) => {
this.actions.updatePieceList({
page,
pageSize,
search,
orderBy,
orderAsc,
filterBy,
pieceList: res.pieces,
pieceListCount: res.count,
unfilteredPieceListCount: res.unfiltered_count
2015-07-01 19:05:47 +02:00
});
resolve();
2015-07-07 09:22:46 +02:00
})
.catch((err) => reject(err));
2015-07-01 19:05:47 +02:00
});
}
2015-07-09 15:44:20 +02:00
2015-07-01 19:05:47 +02:00
fetchPieceRequestActions() {
PieceListFetcher
2015-07-01 19:05:47 +02:00
.fetchRequestActions()
.then((res) => {
2015-08-28 15:24:32 +02:00
this.actions.updatePieceListRequestActions(res);
2015-07-17 15:41:09 +02:00
})
.catch((err) => console.logGlobal(err));
}
}
export default alt.createActions(PieceListActions);