update deps; fix preview modal

This commit is contained in:
mProjectsCode 2023-12-12 21:07:49 +01:00
parent 26cf166a54
commit 5125e73cb4
19 changed files with 1365 additions and 1302 deletions

View file

@ -49,7 +49,7 @@ export class BoardGameGeekAPI extends APIModel {
title,
englishTitle: title,
year,
} as BoardGameModel)
} as BoardGameModel),
);
}

View file

@ -52,7 +52,7 @@ export class MALAPI extends APIModel {
year: result.year ?? result.aired?.prop?.from?.year ?? '',
dataSource: this.apiName,
id: result.mal_id,
} as MovieModel)
} as MovieModel),
);
}
if (type === 'movie' || type === 'special') {
@ -64,7 +64,7 @@ export class MALAPI extends APIModel {
year: result.year ?? result.aired?.prop?.from?.year ?? '',
dataSource: this.apiName,
id: result.mal_id,
} as MovieModel)
} as MovieModel),
);
} else if (type === 'series' || type === 'ova') {
ret.push(
@ -75,7 +75,7 @@ export class MALAPI extends APIModel {
year: result.year ?? result.aired?.prop?.from?.year ?? '',
dataSource: this.apiName,
id: result.mal_id,
} as SeriesModel)
} as SeriesModel),
);
}
}

View file

@ -73,7 +73,7 @@ export class MALAPIManga extends APIModel {
lastWatched: '',
personalRating: 0,
},
} as MangaModel)
} as MangaModel),
);
}

View file

@ -55,7 +55,7 @@ export class MusicBrainzAPI extends APIModel {
artists: result['artist-credit'].map((a: any) => a.name),
subType: result['primary-type'],
} as MusicReleaseModel)
} as MusicReleaseModel),
);
}

View file

@ -69,7 +69,7 @@ export class OMDbAPI extends APIModel {
year: result.Year,
dataSource: this.apiName,
id: result.imdbID,
} as MovieModel)
} as MovieModel),
);
} else if (type === 'series') {
ret.push(
@ -80,7 +80,7 @@ export class OMDbAPI extends APIModel {
year: result.Year,
dataSource: this.apiName,
id: result.imdbID,
} as SeriesModel)
} as SeriesModel),
);
} else if (type === 'game') {
ret.push(
@ -91,7 +91,7 @@ export class OMDbAPI extends APIModel {
year: result.Year,
dataSource: this.apiName,
id: result.imdbID,
} as GameModel)
} as GameModel),
);
}
}

View file

@ -41,7 +41,7 @@ export class OpenLibraryAPI extends APIModel {
year: result.first_publish_year,
dataSource: this.apiName,
id: result.key,
} as BookModel)
} as BookModel),
);
}
@ -75,7 +75,7 @@ export class OpenLibraryAPI extends APIModel {
plot: result.description ?? 'unknown',
pages: result.number_of_pages_median ?? 'unknown',
onlineRating: Number.parseFloat(Number(result.ratings_average ?? 0).toFixed(2)),
image: `https://covers.openlibrary.org/b/OLID/` + result.cover_edition_key + `-L.jpg` ?? '',
image: `https://covers.openlibrary.org/b/OLID/` + result.cover_edition_key + `-L.jpg`,
released: true,

View file

@ -60,7 +60,7 @@ export class SteamAPI extends APIModel {
year: '',
dataSource: this.apiName,
id: result.appid,
} as GameModel)
} as GameModel),
);
}

View file

@ -42,7 +42,7 @@ export class WikipediaAPI extends APIModel {
year: '',
dataSource: this.apiName,
id: result.pageid,
} as WikiModel)
} as WikiModel),
);
}

View file

@ -68,7 +68,7 @@ export default class MediaDbPlugin extends Plugin {
.onClick(() => this.createEntriesFromFolder(file));
});
}
})
}),
);
// register command to open search modal
@ -291,6 +291,11 @@ export default class MediaDbPlugin extends Plugin {
}
}
generateMediaDbNoteFrontmatterPreview(mediaTypeModel: MediaTypeModel): string {
const fileMetadata = this.modelPropertyMapper.convertObject(mediaTypeModel.toMetaDataObject());
return this.settings.useCustomYamlStringifier ? YAMLConverter.toYaml(fileMetadata) : stringifyYaml(fileMetadata);
}
async generateMediaDbNoteContents(mediaTypeModel: MediaTypeModel, options: CreateNoteOptions): Promise<string> {
let fileMetadata = this.modelPropertyMapper.convertObject(mediaTypeModel.toMetaDataObject());
let fileContent = '';

View file

@ -26,7 +26,6 @@ export class MediaDbPreviewModal extends Modal {
this.plugin = plugin;
this.title = previewModalOptions.modalTitle;
this.elements = previewModalOptions.elements;
this.createNoteOptions = previewModalOptions.createNoteOptions;
this.markdownComponent = new Component();
}
@ -53,8 +52,8 @@ export class MediaDbPreviewModal extends Modal {
previewWrapper.createEl('h3', { text: result.englishTitle });
const fileDiv = previewWrapper.createDiv({ cls: 'media-db-plugin-preview' });
let fileContent = await this.plugin.generateMediaDbNoteContents(result, this.createNoteOptions);
fileContent = `\n${fileContent}\n`;
let fileContent = this.plugin.generateMediaDbNoteFrontmatterPreview(result);
fileContent = `\`\`\`yaml\n${fileContent}\`\`\``;
try {
// TODO: fix this not rendering the frontmatter any more
@ -83,7 +82,7 @@ export class MediaDbPreviewModal extends Modal {
}
onOpen(): void {
this.preview();
void this.preview();
}
onClose(): void {

View file

@ -44,7 +44,7 @@ export class PropertyMappingModel {
return {
res: false,
err: new PropertyMappingNameConflictError(
`Multiple remapped properties (${propertiesWithSameTarget.map(x => x.toString()).toString()}) may not share the same name.`
`Multiple remapped properties (${propertiesWithSameTarget.map(x => x.toString()).toString()}) may not share the same name.`,
),
};
}

View file

@ -192,8 +192,8 @@ export class MediaDbSettingTab extends PluginSettingTab {
"For more syntax, refer to <a href='https://momentjs.com/docs/#/displaying/format/'>format reference</a>.<br>" +
"Your current syntax looks like this: <b><a id='media-db-dateformat-preview' style='pointer-events: none; cursor: default; text-decoration: none;'>" +
this.plugin.dateFormatter.getPreview() +
'</a></b>'
)
'</a></b>',
),
)
.addText(cb => {
cb.setPlaceholder(DEFAULT_SETTINGS.customDateFormat)

View file

@ -100,5 +100,5 @@ describe.each([{ name: OMDbAPI }, { name: MALAPI }, { name: LocGovAPI }, { name:
await expect(apiMock.searchByTitle('Hooking Season Playtest')).resolves.toEqual(ret);
expect(fetchMock).toHaveBeenCalledTimes(1);
});
}
},
);

View file

@ -21,7 +21,7 @@ export function setWikipediaResponseMock() {
year: '',
dataSource: apiMock.apiName,
id: wikiresponse.pageid,
})
}),
);
return ret;
}
@ -37,7 +37,7 @@ export function setOMDbResponseMock() {
year: omdbresponse.Year,
dataSource: apiMock.apiName,
id: omdbresponse.imdbID,
})
}),
);
return ret;
}
@ -53,7 +53,7 @@ export function setMALResponseMock() {
year: result.aired.prop.from.year,
dataSource: apiMock.apiName,
id: result.mal_id,
})
}),
);
return ret;
}
@ -69,7 +69,7 @@ export function setSteamResponseMock() {
year: '',
dataSource: apiMock.apiName,
id: steamResponse.appid,
})
}),
);
return ret;
}
@ -89,7 +89,7 @@ export function setMusicBrainzResponseMock() {
artists: result['artist-credit'].map((a: any) => a.name),
subType: result['primary-type'],
} as MusicReleaseModel)
} as MusicReleaseModel),
);
return ret;
}

View file

@ -175,7 +175,6 @@ export interface SelectModalOptions {
export interface PreviewModalOptions {
modalTitle?: string;
elements?: MediaTypeModel[];
createNoteOptions?: CreateNoteOptions;
}
export const SEARCH_MODAL_DEFAULT_OPTIONS: SearchModalOptions = {
@ -206,7 +205,6 @@ export const SELECT_MODAL_OPTIONS_DEFAULT: SelectModalOptions = {
export const PREVIEW_MODAL_DEFAULT_OPTIONS: PreviewModalOptions = {
modalTitle: 'Media DB Preview',
elements: [],
createNoteOptions: { attachTemplate: true },
};
/**
@ -289,7 +287,7 @@ export class ModalHelper {
* @returns the user input or nothing and a reference to the modal.
*/
async createAdvancedSearchModal(
advancedSearchModalOptions: AdvancedSearchModalOptions
advancedSearchModalOptions: AdvancedSearchModalOptions,
): Promise<{ advancedSearchModalResult: AdvancedSearchModalResult; advancedSearchModal: MediaDbAdvancedSearchModal }> {
const modal = new MediaDbAdvancedSearchModal(this.plugin, advancedSearchModalOptions);
const res: AdvancedSearchModalResult = await new Promise(resolve => {
@ -316,7 +314,7 @@ export class ModalHelper {
*/
async openAdvancedSearchModal(
advancedSearchModalOptions: AdvancedSearchModalOptions,
submitCallback: (advancedSearchModalData: AdvancedSearchModalData) => Promise<MediaTypeModel[]>
submitCallback: (advancedSearchModalData: AdvancedSearchModalData) => Promise<MediaTypeModel[]>,
): Promise<MediaTypeModel[]> {
const { advancedSearchModalResult, advancedSearchModal } = await this.createAdvancedSearchModal(advancedSearchModalOptions);
console.debug(`MDB | advencedSearchModal closed with code ${advancedSearchModalResult.code}`);
@ -380,7 +378,7 @@ export class ModalHelper {
*/
async openIdSearchModal(
idSearchModalOptions: IdSearchModalOptions,
submitCallback: (idSearchModalData: IdSearchModalData) => Promise<MediaTypeModel>
submitCallback: (idSearchModalData: IdSearchModalData) => Promise<MediaTypeModel>,
): Promise<MediaTypeModel> {
const { idSearchModalResult, idSearchModal } = await this.createIdSearchModal(idSearchModalOptions);
console.debug(`MDB | idSearchModal closed with code ${idSearchModalResult.code}`);