mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-09-17 17:14:18 +02:00
New: Many UI Updates and Performance Tweaks
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import React, { Component } from 'react';
|
||||
import Autosuggest from 'react-autosuggest';
|
||||
import jdu from 'jdu';
|
||||
import Fuse from 'fuse.js';
|
||||
import { icons } from 'Helpers/Props';
|
||||
import Icon from 'Components/Icon';
|
||||
import keyboardShortcuts, { shortcuts } from 'Components/keyboardShortcuts';
|
||||
@@ -10,6 +10,21 @@ import styles from './MovieSearchInput.css';
|
||||
|
||||
const ADD_NEW_TYPE = 'addNew';
|
||||
|
||||
const fuseOptions = {
|
||||
shouldSort: true,
|
||||
includeMatches: true,
|
||||
threshold: 0.3,
|
||||
location: 0,
|
||||
distance: 100,
|
||||
maxPatternLength: 32,
|
||||
minMatchCharLength: 1,
|
||||
keys: [
|
||||
'title',
|
||||
'alternateTitles.title',
|
||||
'tags.label'
|
||||
]
|
||||
};
|
||||
|
||||
class MovieSearchInput extends Component {
|
||||
|
||||
//
|
||||
@@ -69,16 +84,15 @@ class MovieSearchInput extends Component {
|
||||
|
||||
return (
|
||||
<MovieSearchResult
|
||||
query={query}
|
||||
cleanQuery={jdu.replace(query).toLowerCase()}
|
||||
{...item}
|
||||
{...item.item}
|
||||
match={item.matches[0]}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
goToMovie(movie) {
|
||||
goToMovie(item) {
|
||||
this.setState({ value: '' });
|
||||
this.props.onGoToMovie(movie.titleSlug);
|
||||
this.props.onGoToMovie(item.item.titleSlug);
|
||||
}
|
||||
|
||||
reset() {
|
||||
@@ -140,26 +154,8 @@ class MovieSearchInput extends Component {
|
||||
}
|
||||
|
||||
onSuggestionsFetchRequested = ({ value }) => {
|
||||
const lowerCaseValue = jdu.replace(value).toLowerCase();
|
||||
|
||||
const suggestions = this.props.movie.filter((movie) => {
|
||||
// Check the title first and if there isn't a match fallback to
|
||||
// the alternate titles and finally the tags.
|
||||
|
||||
if (value.length === 1) {
|
||||
return (
|
||||
movie.cleanTitle.startsWith(lowerCaseValue) ||
|
||||
movie.alternateTitles.some((alternateTitle) => alternateTitle.cleanTitle.startsWith(lowerCaseValue)) ||
|
||||
movie.tags.some((tag) => tag.cleanLabel.startsWith(lowerCaseValue))
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
movie.cleanTitle.contains(lowerCaseValue) ||
|
||||
movie.alternateTitles.some((alternateTitle) => alternateTitle.cleanTitle.contains(lowerCaseValue)) ||
|
||||
movie.tags.some((tag) => tag.cleanLabel.contains(lowerCaseValue))
|
||||
);
|
||||
});
|
||||
const fuse = new Fuse(this.props.movies, fuseOptions);
|
||||
const suggestions = fuse.search(value);
|
||||
|
||||
this.setState({ suggestions });
|
||||
}
|
||||
@@ -209,7 +205,7 @@ class MovieSearchInput extends Component {
|
||||
const inputProps = {
|
||||
ref: this.setInputRef,
|
||||
className: styles.input,
|
||||
name: 'seriesSearch',
|
||||
name: 'movieSearch',
|
||||
value,
|
||||
placeholder: 'Search',
|
||||
autoComplete: 'off',
|
||||
@@ -255,7 +251,7 @@ class MovieSearchInput extends Component {
|
||||
}
|
||||
|
||||
MovieSearchInput.propTypes = {
|
||||
movie: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||
movies: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||
onGoToMovie: PropTypes.func.isRequired,
|
||||
onGoToAddNewMovie: PropTypes.func.isRequired,
|
||||
bindShortcut: PropTypes.func.isRequired
|
||||
|
@@ -1,35 +1,14 @@
|
||||
import { connect } from 'react-redux';
|
||||
import { push } from 'react-router-redux';
|
||||
import { push } from 'connected-react-router';
|
||||
import { createSelector } from 'reselect';
|
||||
import jdu from 'jdu';
|
||||
import createAllMoviesSelector from 'Store/Selectors/createAllMoviesSelector';
|
||||
import createTagsSelector from 'Store/Selectors/createTagsSelector';
|
||||
import MovieSearchInput from './MovieSearchInput';
|
||||
|
||||
function createCleanTagsSelector() {
|
||||
return createSelector(
|
||||
createTagsSelector(),
|
||||
(tags) => {
|
||||
return tags.map((tag) => {
|
||||
const {
|
||||
id,
|
||||
label
|
||||
} = tag;
|
||||
|
||||
return {
|
||||
id,
|
||||
label,
|
||||
cleanLabel: jdu.replace(label).toLowerCase()
|
||||
};
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function createCleanMovieSelector() {
|
||||
return createSelector(
|
||||
createAllMoviesSelector(),
|
||||
createCleanTagsSelector(),
|
||||
createTagsSelector(),
|
||||
(allMovies, allTags) => {
|
||||
return allMovies.map((movie) => {
|
||||
const {
|
||||
@@ -46,27 +25,11 @@ function createCleanMovieSelector() {
|
||||
titleSlug,
|
||||
sortTitle,
|
||||
images,
|
||||
cleanTitle: jdu.replace(title).toLowerCase(),
|
||||
alternateTitles: alternateTitles.map((alternateTitle) => {
|
||||
return {
|
||||
title: alternateTitle.title,
|
||||
sortTitle: alternateTitle.sortTitle,
|
||||
cleanTitle: jdu.replace(alternateTitle.title).toLowerCase()
|
||||
};
|
||||
}),
|
||||
alternateTitles,
|
||||
tags: tags.map((id) => {
|
||||
return allTags.find((tag) => tag.id === id);
|
||||
})
|
||||
};
|
||||
}).sort((a, b) => {
|
||||
if (a.sortTitle < b.sortTitle) {
|
||||
return -1;
|
||||
}
|
||||
if (a.sortTitle > b.sortTitle) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
);
|
||||
@@ -75,9 +38,9 @@ function createCleanMovieSelector() {
|
||||
function createMapStateToProps() {
|
||||
return createSelector(
|
||||
createCleanMovieSelector(),
|
||||
(movie) => {
|
||||
(movies) => {
|
||||
return {
|
||||
movie
|
||||
movies
|
||||
};
|
||||
}
|
||||
);
|
||||
|
@@ -5,38 +5,22 @@ import Label from 'Components/Label';
|
||||
import MoviePoster from 'Movie/MoviePoster';
|
||||
import styles from './MovieSearchResult.css';
|
||||
|
||||
function findMatchingAlternateTitle(alternateTitles, cleanQuery) {
|
||||
return alternateTitles.find((alternateTitle) => {
|
||||
return alternateTitle.cleanTitle.contains(cleanQuery);
|
||||
});
|
||||
}
|
||||
|
||||
function getMatchingTag(tags, cleanQuery) {
|
||||
return tags.find((tag) => {
|
||||
return tag.cleanLabel.contains(cleanQuery);
|
||||
});
|
||||
}
|
||||
|
||||
function MovieSearchResult(props) {
|
||||
const {
|
||||
cleanQuery,
|
||||
match,
|
||||
title,
|
||||
cleanTitle,
|
||||
images,
|
||||
alternateTitles,
|
||||
tags
|
||||
} = props;
|
||||
|
||||
const titleContains = cleanTitle.contains(cleanQuery);
|
||||
let alternateTitle = null;
|
||||
let tag = null;
|
||||
|
||||
if (!titleContains) {
|
||||
alternateTitle = findMatchingAlternateTitle(alternateTitles, cleanQuery);
|
||||
}
|
||||
|
||||
if (!titleContains && !alternateTitle) {
|
||||
tag = getMatchingTag(tags, cleanQuery);
|
||||
if (match.key === 'alternateTitles.cleanTitle') {
|
||||
alternateTitle = alternateTitles[match.arrayIndex];
|
||||
} else if (match.key === 'tags.label') {
|
||||
tag = tags[match.arrayIndex];
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -55,14 +39,15 @@ function MovieSearchResult(props) {
|
||||
</div>
|
||||
|
||||
{
|
||||
!!alternateTitle &&
|
||||
alternateTitle ?
|
||||
<div className={styles.alternateTitle}>
|
||||
{alternateTitle.title}
|
||||
</div>
|
||||
</div> :
|
||||
null
|
||||
}
|
||||
|
||||
{
|
||||
!!tag &&
|
||||
tag ?
|
||||
<div className={styles.tagContainer}>
|
||||
<Label
|
||||
key={tag.id}
|
||||
@@ -70,7 +55,8 @@ function MovieSearchResult(props) {
|
||||
>
|
||||
{tag.label}
|
||||
</Label>
|
||||
</div>
|
||||
</div> :
|
||||
null
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
@@ -78,12 +64,11 @@ function MovieSearchResult(props) {
|
||||
}
|
||||
|
||||
MovieSearchResult.propTypes = {
|
||||
cleanQuery: PropTypes.string.isRequired,
|
||||
title: PropTypes.string.isRequired,
|
||||
cleanTitle: PropTypes.string.isRequired,
|
||||
images: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||
alternateTitles: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||
tags: PropTypes.arrayOf(PropTypes.object).isRequired
|
||||
tags: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||
match: PropTypes.object.isRequired
|
||||
};
|
||||
|
||||
export default MovieSearchResult;
|
||||
|
@@ -38,7 +38,7 @@
|
||||
}
|
||||
|
||||
.donate {
|
||||
composes: link from 'Components/Link/Link.css';
|
||||
composes: link from '~Components/Link/Link.css';
|
||||
|
||||
width: 30px;
|
||||
color: $themeRed;
|
||||
|
Reference in New Issue
Block a user