Moved season selection to a separate section
This commit is contained in:
parent
64e79265b8
commit
3e09f4191b
1 changed files with 59 additions and 51 deletions
110
src/main.ts
110
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<boolean> {
|
||||
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<void> {
|
||||
const apiSearchResults = await this.modalHelper.openAdvancedSearchModal({}, async advancedSearchModalData => {
|
||||
return await this.apiManager.query(advancedSearchModalData.query, advancedSearchModalData.apis);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue