mirror of
https://github.com/Sonarr/Sonarr.git
synced 2026-04-25 22:46:31 -04:00
Better selection of jump bar items
Show first, last and most common items
This commit is contained in:
@@ -47,7 +47,7 @@ class SeriesIndex extends Component {
|
||||
|
||||
this.state = {
|
||||
contentBody: null,
|
||||
jumpBarItems: [],
|
||||
jumpBarItems: { order: [] },
|
||||
jumpToCharacter: null,
|
||||
isPosterOptionsModalOpen: false,
|
||||
isOverviewOptionsModalOpen: false,
|
||||
@@ -95,28 +95,39 @@ class SeriesIndex extends Component {
|
||||
|
||||
// Reset if not sorting by sortTitle
|
||||
if (sortKey !== 'sortTitle') {
|
||||
this.setState({ jumpBarItems: [] });
|
||||
this.setState({ jumpBarItems: { order: [] } });
|
||||
return;
|
||||
}
|
||||
|
||||
const characters = _.reduce(items, (acc, item) => {
|
||||
const firstCharacter = item.sortTitle.charAt(0);
|
||||
let char = item.sortTitle.charAt(0);
|
||||
|
||||
if (isNaN(firstCharacter)) {
|
||||
acc.push(firstCharacter);
|
||||
if (!isNaN(char)) {
|
||||
char = '#';
|
||||
}
|
||||
|
||||
if (char in acc) {
|
||||
acc[char] = acc[char] + 1;
|
||||
} else {
|
||||
acc.push('#');
|
||||
acc[char] = 1;
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, []).sort();
|
||||
}, {});
|
||||
|
||||
const order = Object.keys(characters).sort();
|
||||
|
||||
// Reverse if sorting descending
|
||||
if (sortDirection === sortDirections.DESCENDING) {
|
||||
characters.reverse();
|
||||
order.reverse();
|
||||
}
|
||||
|
||||
this.setState({ jumpBarItems: _.sortedUniq(characters) });
|
||||
const jumpBarItems = {
|
||||
characters,
|
||||
order
|
||||
};
|
||||
|
||||
this.setState({ jumpBarItems });
|
||||
}
|
||||
|
||||
//
|
||||
@@ -340,7 +351,7 @@ class SeriesIndex extends Component {
|
||||
</PageContentBodyConnector>
|
||||
|
||||
{
|
||||
isLoaded && !!jumpBarItems.length &&
|
||||
isLoaded && !!jumpBarItems.order.length &&
|
||||
<PageJumpBar
|
||||
items={jumpBarItems}
|
||||
onItemPress={this.onJumpBarItemPress}
|
||||
|
||||
Reference in New Issue
Block a user