From 3e09f4191b716726eacf4f22d385745a370f2268 Mon Sep 17 00:00:00 2001 From: ltctceplrm <14954927+ltctceplrm@users.noreply.github.com> Date: Wed, 31 Dec 2025 02:19:29 +0100 Subject: [PATCH] Moved season selection to a separate section --- src/main.ts | 110 ++++++++++++++++++++++++++++------------------------ 1 file changed, 59 insertions(+), 51 deletions(-) diff --git a/src/main.ts b/src/main.ts index 9be9faa..c564b35 100644 --- a/src/main.ts +++ b/src/main.ts @@ -234,57 +234,7 @@ export default class MediaDbPlugin extends Plugin { } // Only show the season select modal if the user searches for seasons - if (types.length === 1 && types[0] === 'season' && selectResults.length === 1 && selectResults[0].dataSource === 'TMDBSeasonAPI') { - // Dynamically import the modal - const { MediaDbSeasonSelectModal } = await import('./modals/MediaDbSeasonSelectModal'); - const TMDBSeasonAPI = this.apiManager.getApiByName('TMDBSeasonAPI') as import('./api/apis/TMDBSeasonAPI').TMDBSeasonAPI; - if (!TMDBSeasonAPI) { - new Notice('TMDBSeasonAPI not found.'); - return; - } - // Fetch all seasons for the selected series - const allSeasons = await TMDBSeasonAPI.getSeasonsForSeries(selectResults[0].id); - if (!allSeasons || allSeasons.length === 0) { - new Notice('No seasons found for this series.'); - return; - } - // Pass the original series title from the search result - const seriesName = selectResults[0]?.englishTitle || selectResults[0]?.title || ''; - const modal = new MediaDbSeasonSelectModal( - this, - allSeasons.map(s => ({ - season_number: s.seasonNumber, - name: s.seasonTitle || s.title, - episode_count: s.episodes || 0, - air_date: s.year, - poster_path: s.image, - })), - true, - seriesName, - ); - const selectedSeasons: any[] = await new Promise(resolve => { - modal.setSubmitCallback(resolve); - modal.open(); - }); - if (!selectedSeasons || selectedSeasons.length === 0) { - return; - } - // Fetch full metadata for each selected seasond and create the note - await Promise.all( - selectedSeasons.map(async season => { - const orig = allSeasons.find(s => s.seasonNumber === season.season_number); - if (orig) { - // Fetch full metadata using getById - const TMDBSeasonAPI = this.apiManager.getApiByName('TMDBSeasonAPI') as import('./api/apis/TMDBSeasonAPI').TMDBSeasonAPI; - if (TMDBSeasonAPI) { - const fullMeta = await TMDBSeasonAPI.getById(orig.id); - await this.createMediaDbNotes([fullMeta]); - } else { - await this.createMediaDbNotes([orig]); - } - } - }), - ); + if (await this.handleSeasonSelectModal(types, selectResults)) { return; } @@ -300,6 +250,64 @@ export default class MediaDbPlugin extends Plugin { await this.createMediaDbNotes(selectResults!); } + // Season select modal + private async handleSeasonSelectModal(types: string[], selectResults: MediaTypeModel[]): Promise { + if (types.length === 1 && types[0] === 'season' && selectResults.length === 1 && selectResults[0].dataSource === 'TMDBSeasonAPI') { + // Dynamically import the modal + const { MediaDbSeasonSelectModal } = await import('./modals/MediaDbSeasonSelectModal'); + const TMDBSeasonAPI = this.apiManager.getApiByName('TMDBSeasonAPI') as import('./api/apis/TMDBSeasonAPI').TMDBSeasonAPI; + if (!TMDBSeasonAPI) { + new Notice('TMDBSeasonAPI not found.'); + return true; + } + // Fetch all seasons for the selected series + const allSeasons = await TMDBSeasonAPI.getSeasonsForSeries(selectResults[0].id); + if (!allSeasons || allSeasons.length === 0) { + new Notice('No seasons found for this series.'); + return true; + } + // Pass the original series title from the search result + const seriesName = selectResults[0]?.englishTitle || selectResults[0]?.title || ''; + const modal = new MediaDbSeasonSelectModal( + this, + allSeasons.map(s => ({ + season_number: s.seasonNumber, + name: s.seasonTitle || s.title, + episode_count: s.episodes || 0, + air_date: s.year, + poster_path: s.image, + })), + true, + seriesName, + ); + const selectedSeasons: any[] = await new Promise(resolve => { + modal.setSubmitCallback(resolve); + modal.open(); + }); + if (!selectedSeasons || selectedSeasons.length === 0) { + return true; + } + // Fetch full metadata for each selected season and create the note + await Promise.all( + selectedSeasons.map(async season => { + const orig = allSeasons.find(s => s.seasonNumber === season.season_number); + if (orig) { + // Fetch full metadata using getById + const TMDBSeasonAPI = this.apiManager.getApiByName('TMDBSeasonAPI') as import('./api/apis/TMDBSeasonAPI').TMDBSeasonAPI; + if (TMDBSeasonAPI) { + const fullMeta = await TMDBSeasonAPI.getById(orig.id); + await this.createMediaDbNotes([fullMeta]); + } else { + await this.createMediaDbNotes([orig]); + } + } + }), + ); + return true; + } + return false; + } + async createEntryWithAdvancedSearchModal(): Promise { const apiSearchResults = await this.modalHelper.openAdvancedSearchModal({}, async advancedSearchModalData => { return await this.apiManager.query(advancedSearchModalData.query, advancedSearchModalData.apis);