Skip to content

Commit

Permalink
fix(archive): Fix blank screen when sorting
Browse files Browse the repository at this point in the history
* Add try/catch handler for exceptions
* Handle case when sorting data is falsy
  • Loading branch information
mickr committed Jan 16, 2020
1 parent a23deeb commit 3e0a5ec
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/lib/viewers/archive/ArchiveExplorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,27 @@ class ArchiveExplorer extends React.Component {
*/
sortItemList(itemList) {
const { sortBy, sortDirection } = this.state;
let sortedItems;

if (!sortBy.length) {
return itemList;
}

const sortedItems = itemList.sort((a, b) => {
if (typeof a[sortBy] === 'number' && typeof b[sortBy] === 'number') {
return a[sortBy] - b[sortBy];
}
try {
sortedItems = itemList.sort((a, b) => {
if (!a[sortBy] || !b[sortBy]) {
return -1;
}

return a[sortBy].localeCompare(b[sortBy]);
});
if (typeof a[sortBy] === 'number' && typeof b[sortBy] === 'number') {
return a[sortBy] - b[sortBy];
}

return a[sortBy].localeCompare(b[sortBy]);
});
} catch {
sortedItems = itemList;
}

return sortDirection === SortDirection.ASC ? sortedItems : sortedItems.reverse();
}
Expand Down

0 comments on commit 3e0a5ec

Please sign in to comment.