diff --git a/assets/components/download-option-tr.js b/assets/components/download-option-tr.js index 84265c0..26818f8 100644 --- a/assets/components/download-option-tr.js +++ b/assets/components/download-option-tr.js @@ -3,6 +3,7 @@ export default class DownloadOptionTr extends HTMLTableRowElement { H265_CODECS = ['h265', 'h.265', 'x265', 'hevc'] #downloadBtnEl; + #selectEpisodeInputEl; url; size; @@ -37,8 +38,10 @@ export default class DownloadOptionTr extends HTMLTableRowElement { this.season = this.getAttribute('season') ?? null; this.episode = this.getAttribute('episode') ?? null; this.episodeId = this.getAttribute('episode-id') ?? null; - this.#downloadBtnEl = this.querySelector('.download-btn'); + this.#selectEpisodeInputEl = this.querySelector('input[type="checkbox"]'); + console.log(this.#selectEpisodeInputEl) + this.#downloadBtnEl.addEventListener('click', () => this.download()); // document.addEventListener('filterDownloadOptions', this.filter.bind(this)); } @@ -46,6 +49,14 @@ export default class DownloadOptionTr extends HTMLTableRowElement { } + get isSelected() { + return this.#selectEpisodeInputEl.checked; + } + + set isSelected(value) { + this.#selectEpisodeInputEl.checked = value; + } + // attribute change attributeChangedCallback(property, oldValue, newValue) { if (oldValue === newValue) return; diff --git a/assets/components/episode-container.js b/assets/components/episode-container.js index 5cc3422..9e0ec07 100644 --- a/assets/components/episode-container.js +++ b/assets/components/episode-container.js @@ -24,6 +24,7 @@ export default class EpisodeContainer extends HTMLElement { this.#resultsCountBadgeEl.addEventListener('click', () => this.toggleResults()); document.addEventListener('filterDownloadOptions', this.filter.bind(this)); + document.addEventListener('downloadSelectedEpisodes', this.downloadSelectedResults.bind(this)); document.addEventListener('selectEpisodeForDownload', (e) => this.selectEpisodeForDownload(e.detail.select)); } connectedCallback() { @@ -52,6 +53,20 @@ export default class EpisodeContainer extends HTMLElement { } } + downloadSelectedResults() { + if (this.#episodeSelectorEl.disabled === false && + this.#episodeSelectorEl.checked === true + ) { + console.log('episode is selected') + this.options.forEach(option => { + if (option.isSelected === true) { + option.download(); + } + option.isSelected = false; + }) + } + } + filter({ detail: { activeFilter } }) { let firstIncluded = true; let count = 0; diff --git a/assets/controllers/result_filter_controller.js b/assets/controllers/result_filter_controller.js index f3141c5..6ce734a 100644 --- a/assets/controllers/result_filter_controller.js +++ b/assets/controllers/result_filter_controller.js @@ -164,10 +164,6 @@ export default class extends Controller { this.tvEpisodeListOutlet.setSeason(event.target.value); } - uncheckSelectAllBtn() { - this.selectAllTarget.checked = false; - } - downloadSeason() { fetch(`/api/download/season/${this.imdbIdValue}/${this.activeFilter['season']}`, { headers: { @@ -177,11 +173,6 @@ export default class extends Controller { } downloadSelectedEpisodes() { - this.tvResultsOutlets.forEach(episode => { - if (episode.isActive() && episode.isSelected()) { - episode.download(); - } - }); - this.selectAllTarget.checked = false; + document.dispatchEvent(new CustomEvent('downloadSelectedEpisodes', {})); } }