1
0
mirror of https://github.com/ascribe/onion.git synced 2024-11-16 01:55:07 +01:00
onion/js/actions/piece_list_actions.js

61 lines
1.7 KiB
JavaScript
Raw Normal View History

'use strict';
import alt from '../alt';
import PieceListFetcher from '../fetchers/piece_list_fetcher';
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'
);
}
2015-05-22 11:33:38 +02:00
fetchPieceList(page, pageSize, search, orderBy, orderAsc) {
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,
search,
orderBy,
orderAsc,
'pieceList': [],
'pieceListCount': -1
});
// afterwards, we can load the list
2015-07-01 19:05:47 +02:00
return new Promise((resolve, reject) => {
PieceListFetcher
.fetch(page, pageSize, search, orderBy, orderAsc)
.then((res) => {
this.actions.updatePieceList({
page,
pageSize,
search,
orderBy,
orderAsc,
'pieceList': res.pieces,
'pieceListCount': res.count
});
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-07-01 19:05:47 +02:00
this.actions.updatePieceListRequestActions(res.piece_ids);
});
}
}
export default alt.createActions(PieceListActions);