Handle empty torrent list response

This commit is contained in:
John Furrow
2016-06-02 21:06:37 -07:00
parent ced4685163
commit 2d6d696bf4
8 changed files with 73 additions and 10 deletions
+19 -1
View File
@@ -1,5 +1,6 @@
$torrent-list--background: #fff;
$torrent-list--border: rgba($background, 0.15);
$torrent-list--offset: 10px;
$torrent--primary--foreground: #5b6d7c;
$torrent--primary--foreground--error: #e95779;
@@ -14,6 +15,7 @@ $torrent--tertiary--foreground: #8899a8;
$torrent--tertiary--foreground--stopped: rgba(#8899a8, 0.5);
$torrent--tertiary--foreground--selected: rgba(#fff, 0.9);
$torrent--tertiary--foreground--selected--stopped: rgba(#fff, 0.5);
$torrent--notification--foreground: $torrent--tertiary--foreground--stopped;
$torrent--background--hover: #f6f8fa;
$torrent--background--selected: $blue;
@@ -34,7 +36,7 @@ $more-info--border: $textbox-repeater--button--border;
box-shadow: -1px 0 0 0 $torrent-list--border;
content: '';
height: auto;
left: 10px;
left: $torrent-list--offset;
position: absolute;
right: 0;
top: 0;
@@ -46,6 +48,22 @@ $more-info--border: $textbox-repeater--button--border;
top: 50%;
transform: translate(-50%, -50%);
}
&__notification {
color: $torrent--notification--foreground;
text-align: center;
&__wrapper {
justify-content: center;
align-items: center;
bottom: 0;
display: flex;
left: $torrent-list--offset;
position: absolute;
right: 0;
top: 0;
}
}
}
.torrent {
@@ -93,7 +93,7 @@ const TorrentActions = {
});
})
.catch((error) => {
console.log(error);
console.trace(error);
AppDispatcher.dispatchServerAction({
type: ActionTypes.CLIENT_FETCH_TORRENTS_ERROR,
data: {
@@ -114,6 +114,10 @@ export default class TrackerFilters extends React.Component {
render() {
let filters = this.getFilters();
if (filters.length === 0) {
return null;
}
return (
<ul className="sidebar-filter sidebar__item">
<li className="sidebar-filter__item sidebar-filter__item--heading">
@@ -19,17 +19,18 @@ import UIStore from '../../stores/UIStore';
const METHODS_TO_BIND = [
'bindExternalPriorityChangeHandler',
'onReceiveTorrentsError',
'onReceiveTorrentsSuccess',
'getListPadding',
'getViewportLimits',
'handleContextMenuItemClick',
'handleDetailsClick',
'handleRightClick',
'handleTorrentClick',
'onContextMenuChange',
'onEmptyTorrentResponse',
'onReceiveTorrentsError',
'onReceiveTorrentsSuccess',
'onTorrentFilterChange',
'onTorrentSelectionChange',
'getListPadding',
'getViewportLimits',
'setScrollPosition',
'setViewportHeight'
];
@@ -39,6 +40,7 @@ export default class TorrentListContainer extends React.Component {
super();
this.state = {
emptyTorrentList: false,
handleTorrentPriorityChange: null,
contextMenu: null,
maxTorrentIndex: 10,
@@ -46,7 +48,7 @@ export default class TorrentListContainer extends React.Component {
scrollPosition: 0,
torrentCount: 0,
torrentHeight: 72,
torrents: null,
torrents: [],
torrentRequestError: false,
torrentRequestSuccess: false,
viewportHeight: 0
@@ -72,6 +74,7 @@ export default class TorrentListContainer extends React.Component {
TorrentStore.listen(EventTypes.UI_TORRENT_SELECTION_CHANGE, this.onTorrentSelectionChange);
TorrentStore.listen(EventTypes.CLIENT_TORRENTS_REQUEST_SUCCESS, this.onReceiveTorrentsSuccess);
TorrentStore.listen(EventTypes.CLIENT_TORRENTS_REQUEST_ERROR, this.onReceiveTorrentsError);
TorrentStore.listen(EventTypes.CLIENT_TORRENTS_EMPTY, this.onEmptyTorrentResponse);
TorrentFilterStore.listen(EventTypes.UI_TORRENTS_FILTER_CHANGE, this.onTorrentFilterChange);
UIStore.listen(EventTypes.UI_CONTEXT_MENU_CHANGE, this.onContextMenuChange);
TorrentStore.fetchTorrents();
@@ -84,6 +87,7 @@ export default class TorrentListContainer extends React.Component {
TorrentStore.unlisten(EventTypes.UI_TORRENT_SELECTION_CHANGE, this.onTorrentSelectionChange);
TorrentStore.unlisten(EventTypes.CLIENT_TORRENTS_REQUEST_SUCCESS, this.onReceiveTorrentsSuccess);
TorrentStore.unlisten(EventTypes.CLIENT_TORRENTS_REQUEST_ERROR, this.onReceiveTorrentsError);
TorrentStore.unlisten(EventTypes.CLIENT_TORRENTS_EMPTY, this.onEmptyTorrentResponse);
TorrentFilterStore.unlisten(EventTypes.UI_TORRENTS_FILTER_CHANGE, this.onTorrentFilterChange);
UIStore.unlisten(EventTypes.UI_CONTEXT_MENU_CHANGE, this.onContextMenuChange);
}
@@ -194,6 +198,18 @@ export default class TorrentListContainer extends React.Component {
this.setState({contextMenu: UIStore.getActiveContextMenu()});
}
onEmptyTorrentResponse() {
this.setState({
emptyTorrentList: true,
torrentRequestError: false,
torrentRequestSuccess: true
});
if (!UIStore.hasSatisfiedDependencies()) {
UIStore.satisfyDependency('torrent-list');
}
}
onReceiveTorrentsError() {
this.setState({torrentRequestError: true, torrentRequestSuccess: false});
}
@@ -221,6 +237,16 @@ export default class TorrentListContainer extends React.Component {
this.forceUpdate();
}
getEmptyTorrentListNotification() {
return (
<div className="torrents__notification__wrapper">
<div className="torrents__notification">
No torrents to display.
</div>
</div>
);
}
getListPadding(minTorrentIndex, maxTorrentIndex, torrentCount) {
// Calculate the number of pixels to pad the visible item list.
// If the minimum item index is less than 0, then we're already at the top
@@ -345,6 +371,10 @@ export default class TorrentListContainer extends React.Component {
);
}
if (this.state.emptyTorrentList) {
content = this.getEmptyTorrentListNotification();
}
return (
<div className="torrent__list__wrapper">
<CustomScrollbars className="torrent__list__wrapper--custom-scroll"
@@ -10,6 +10,7 @@ const EventTypes = {
CLIENT_TORRENT_STATUS_COUNT_REQUEST_ERROR: 'CLIENT_TORRENT_STATUS_COUNT_REQUEST_ERROR',
CLIENT_TORRENT_TRACKER_COUNT_CHANGE: 'CLIENT_TORRENT_TRACKER_COUNT_CHANGE',
CLIENT_TORRENT_TRACKER_COUNT_REQUEST_ERROR: 'CLIENT_TORRENT_TRACKER_COUNT_REQUEST_ERROR',
CLIENT_TORRENTS_EMPTY: 'CLIENT_TORRENTS_EMPTY',
CLIENT_TORRENTS_REQUEST_SUCCESS: 'CLIENT_TORRENTS_REQUEST_SUCCESS',
CLIENT_TORRENT_DETAILS_CHANGE: 'CLIENT_TORRENT_DETAILS_CHANGE',
CLIENT_TRANSFER_DATA_REQUEST_SUCCESS: 'CLIENT_TRANSFER_DATA_REQUEST_SUCCESS',
+8 -2
View File
@@ -178,15 +178,21 @@ class TorrentStoreClass extends BaseStore {
}
handleFetchTorrentsError(error) {
console.log(error);
console.trace(error);
}
handleFetchTorrentsSuccess(torrents) {
this.resolveRequest('fetch-torrents');
if (torrents == null) {
this.emit(EventTypes.CLIENT_TORRENTS_EMPTY);
return;
}
this.sortTorrents(torrents);
this.filterTorrents();
this.emit(EventTypes.CLIENT_TORRENTS_REQUEST_SUCCESS);
this.resolveRequest('fetch-torrents');
}
handleRemoveTorrentsSuccess(response) {
+4
View File
@@ -91,6 +91,10 @@ var client = {
request.add('getTorrentList',
{props: clientUtil.defaults.torrentPropertyMethods});
request.postProcess((data) => {
if (!data || data[0][0].length === 0) {
return null;
}
// TODO: Remove this nasty nested array business.
_torrentCollection.updateTorrents(data[0][0]);
_statusCount = _torrentCollection.statusCount;
+1 -1
View File
@@ -220,7 +220,7 @@ var clientUtil = {
},
// TODO clean this up, write comments...
mapClientProps: (props, data, includeIndex) => {
mapClientProps: (props, data) => {
var index = 0;
var mappedObject = [];