mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-04 10:02:40 +01:00
Fxed: Manual Import Movie filter error due to Fuse Worker updates
This commit is contained in:
parent
79a96bb43f
commit
69f4f1c168
@ -17,8 +17,6 @@ import translate from 'Utilities/String/translate';
|
|||||||
import SelectMovieRow from './SelectMovieRow';
|
import SelectMovieRow from './SelectMovieRow';
|
||||||
import styles from './SelectMovieModalContent.css';
|
import styles from './SelectMovieModalContent.css';
|
||||||
|
|
||||||
const workerInstance = new FuseWorker();
|
|
||||||
|
|
||||||
class SelectMovieModalContent extends Component {
|
class SelectMovieModalContent extends Component {
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -27,16 +25,31 @@ class SelectMovieModalContent extends Component {
|
|||||||
constructor(props, context) {
|
constructor(props, context) {
|
||||||
super(props, context);
|
super(props, context);
|
||||||
|
|
||||||
|
this._worker = null;
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
scroller: null,
|
scroller: null,
|
||||||
filter: '',
|
filter: '',
|
||||||
showLoading: false,
|
loading: false,
|
||||||
suggestions: props.items
|
suggestions: props.items
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentWillUnmount() {
|
||||||
workerInstance.addEventListener('message', this.onSuggestionsReceived, false);
|
if (this._worker) {
|
||||||
|
this._worker.removeEventListener('message', this.onSuggestionsReceived, false);
|
||||||
|
this._worker.terminate();
|
||||||
|
this._worker = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getWorker() {
|
||||||
|
if (!this._worker) {
|
||||||
|
this._worker = new FuseWorker();
|
||||||
|
this._worker.addEventListener('message', this.onSuggestionsReceived, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this._worker;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -71,13 +84,13 @@ class SelectMovieModalContent extends Component {
|
|||||||
onFilterChange = ({ value }) => {
|
onFilterChange = ({ value }) => {
|
||||||
if (value) {
|
if (value) {
|
||||||
this.setState({
|
this.setState({
|
||||||
showLoading: true,
|
loading: true,
|
||||||
filter: value.toLowerCase()
|
filter: value.toLowerCase()
|
||||||
});
|
});
|
||||||
this.requestSuggestions(value);
|
this.requestSuggestions(value);
|
||||||
} else {
|
} else {
|
||||||
this.setState({
|
this.setState({
|
||||||
showLoading: false,
|
loading: false,
|
||||||
filter: '',
|
filter: '',
|
||||||
suggestions: this.props.items
|
suggestions: this.props.items
|
||||||
});
|
});
|
||||||
@ -86,26 +99,58 @@ class SelectMovieModalContent extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
requestSuggestions = _.debounce((value) => {
|
requestSuggestions = _.debounce((value) => {
|
||||||
const payload = {
|
if (!this.state.loading) {
|
||||||
value,
|
return;
|
||||||
movies: this.props.items
|
}
|
||||||
};
|
|
||||||
|
|
||||||
workerInstance.postMessage(payload);
|
const requestLoading = this.state.requestLoading;
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
requestValue: value,
|
||||||
|
requestLoading: true
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!requestLoading) {
|
||||||
|
const payload = {
|
||||||
|
value,
|
||||||
|
movies: this.props.items
|
||||||
|
};
|
||||||
|
|
||||||
|
this.getWorker().postMessage(payload);
|
||||||
|
}
|
||||||
}, 250);
|
}, 250);
|
||||||
|
|
||||||
onSuggestionsReceived = (message) => {
|
onSuggestionsReceived = (message) => {
|
||||||
this.setState((state, props) => {
|
const {
|
||||||
// this guards against setting a stale set of suggestions returned
|
value,
|
||||||
// after the filter has been cleared
|
suggestions
|
||||||
if (state.filter !== '') {
|
} = message.data;
|
||||||
return {
|
|
||||||
showLoading: false,
|
if (!this.state.loading) {
|
||||||
suggestions: message.data.map((suggestion) => suggestion.item)
|
this.setState({
|
||||||
};
|
requestValue: null,
|
||||||
}
|
requestLoading: false
|
||||||
return {};
|
});
|
||||||
});
|
} else if (value === this.state.requestValue) {
|
||||||
|
this.setState({
|
||||||
|
suggestions: suggestions.map((suggestion) => suggestion.item),
|
||||||
|
requestValue: null,
|
||||||
|
requestLoading: false,
|
||||||
|
loading: false
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.setState({
|
||||||
|
suggestions: suggestions.map((suggestion) => suggestion.item),
|
||||||
|
requestLoading: true
|
||||||
|
});
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
value: this.state.requestValue,
|
||||||
|
movies: this.props.items
|
||||||
|
};
|
||||||
|
|
||||||
|
this.getWorker().postMessage(payload);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -120,7 +165,7 @@ class SelectMovieModalContent extends Component {
|
|||||||
const {
|
const {
|
||||||
scroller,
|
scroller,
|
||||||
filter,
|
filter,
|
||||||
showLoading,
|
loading,
|
||||||
suggestions
|
suggestions
|
||||||
} = this.state;
|
} = this.state;
|
||||||
|
|
||||||
@ -152,7 +197,7 @@ class SelectMovieModalContent extends Component {
|
|||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
{
|
{
|
||||||
showLoading || !scroller ?
|
loading || !scroller ?
|
||||||
<LoadingIndicator /> :
|
<LoadingIndicator /> :
|
||||||
<VirtualTable
|
<VirtualTable
|
||||||
header={
|
header={
|
||||||
|
Loading…
Reference in New Issue
Block a user