wip-feat: populates filter from api options

This commit is contained in:
2025-04-29 22:10:47 -05:00
parent c3eaf109e3
commit 8a1a89f17d
9 changed files with 191 additions and 6 deletions

View File

@@ -27,10 +27,23 @@ export default class extends Controller {
'episodes': Array,
}
connect() {
if (this.mediaTypeValue === "tvshows") {
this.activeFilter['season'] = 1;
}
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);
})
}
async movieResultsOutletConnected(outlet) {
@@ -51,6 +64,20 @@ 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>')
.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>')
.join();
}
addLanguages(option, props) {
const languages = Object.assign([], JSON.parse(props['languages']));
languages.forEach((language) => {