44 lines
1.2 KiB
JavaScript
44 lines
1.2 KiB
JavaScript
import { Controller } from '@hotwired/stimulus';
|
|
|
|
/*
|
|
* The following line makes this controller "lazy": it won't be downloaded until needed
|
|
* See https://github.com/symfony/stimulus-bridge#lazy-controllers
|
|
*/
|
|
/* stimulusFetch: 'lazy' */
|
|
export default class extends Controller {
|
|
static values = {
|
|
title: String,
|
|
tmdbId: String,
|
|
imdbId: String
|
|
};
|
|
|
|
static targets = ['list']
|
|
|
|
options = []
|
|
|
|
async connect() {
|
|
await this.setOptions();
|
|
}
|
|
|
|
async setOptions() {
|
|
if (this.options.length === 0) {
|
|
await fetch(`/torrentio/movies/${this.tmdbIdValue}/${this.imdbIdValue}`)
|
|
.then(res => res.text())
|
|
.then(response => {
|
|
this.element.innerHTML = response;
|
|
this.options = this.element.querySelectorAll('tbody tr');
|
|
this.options.forEach((option) => option.querySelector('.download-btn').dataset['title'] = this.titleValue);
|
|
});
|
|
}
|
|
}
|
|
|
|
// Keeps compatible with Filter & TV Shows
|
|
isActive() {
|
|
return true;
|
|
}
|
|
|
|
listTargetConnected(target) {
|
|
// console.log(target);
|
|
}
|
|
}
|