wip: filter twig component pre-select options
This commit is contained in:
@@ -20,6 +20,8 @@ export default class extends Controller {
|
||||
"provider": "",
|
||||
}
|
||||
|
||||
userPreferences = []
|
||||
|
||||
static outlets = ['movie-results', 'tv-results']
|
||||
static targets = ['resolution', 'codec', 'language', 'provider', 'season', 'selectAll', 'downloadSelected']
|
||||
static values = {
|
||||
@@ -28,22 +30,11 @@ export default class extends Controller {
|
||||
}
|
||||
|
||||
async connect() {
|
||||
await fetch('/api/preferences/media')
|
||||
.then(response => response.json())
|
||||
.then(response => {
|
||||
this.addResolutions(response['resolution']);
|
||||
this.addCodecs(response['codec']);
|
||||
});
|
||||
|
||||
await fetch('/api/user/preferences/values')
|
||||
.then(response => response.json())
|
||||
.then(response => {
|
||||
this.activeFilter = response;
|
||||
if (this.mediaTypeValue === "tvshows") {
|
||||
this.activeFilter['season'] = 1;
|
||||
}
|
||||
console.log(this.activeFilter);
|
||||
})
|
||||
this.userPreferences = await(await fetch('/api/user/preferences/values')).json();
|
||||
if (this.mediaTypeValue === "tvshows") {
|
||||
this.activeFilter['season'] = 1;
|
||||
}
|
||||
await this.filter();
|
||||
}
|
||||
|
||||
async movieResultsOutletConnected(outlet) {
|
||||
@@ -67,14 +58,24 @@ export default class extends Controller {
|
||||
addResolutions(resolutions) {
|
||||
this.resolutionTarget.innerHTML = '<option value="">n/a</option>';
|
||||
this.resolutionTarget.innerHTML += resolutions.preferenceOptions
|
||||
.map((resolution) => '<option value="'+resolution.name.toLowerCase()+'">'+resolution.name+'</option>')
|
||||
.map((resolution) => {
|
||||
if ('resolution' in this.userPreferences) {
|
||||
return '<option value="' + resolution.name.toLowerCase() + '" selected>' + resolution.name + '</option>';
|
||||
}
|
||||
return '<option value="' + resolution.name.toLowerCase() + '">' + resolution.name + '</option>';
|
||||
})
|
||||
.join();
|
||||
}
|
||||
|
||||
addCodecs(codecs) {
|
||||
this.codecTarget.innerHTML = '<option value="">n/a</option>';
|
||||
this.codecTarget.innerHTML += codecs.preferenceOptions
|
||||
.map((codec) => '<option value="'+codec.name.toLowerCase()+'">'+codec.name+'</option>')
|
||||
.map((codec) => {
|
||||
if ('codec' in this.userPreferences) {
|
||||
return '<option value="' + codec.name.toLowerCase() + '" selected>' + codec.name + '</option>';
|
||||
}
|
||||
return '<option value="' + codec.name.toLowerCase() + '">' + codec.name + '</option>'
|
||||
})
|
||||
.join();
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,8 @@ export default class extends Controller {
|
||||
}
|
||||
|
||||
async setOptions() {
|
||||
if (true === this.activeValue) {
|
||||
if (true === this.activeValue && this.optionsLoaded === false) {
|
||||
this.optionsLoaded = true;
|
||||
await fetch(`/torrentio/tvshows/${this.tmdbIdValue}/${this.imdbIdValue}/${this.seasonValue}/${this.episodeValue}`)
|
||||
.then(res => res.text())
|
||||
.then(response => {
|
||||
@@ -38,7 +39,6 @@ export default class extends Controller {
|
||||
} else {
|
||||
this.episodeSelectorTarget.disabled = true;
|
||||
}
|
||||
this.optionsLoaded = true;
|
||||
this.loadingIconOutlet.increaseCount();
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user