Skip to content

Conversation

@ltctceplrm
Copy link
Contributor

@ltctceplrm ltctceplrm commented Jan 30, 2024

The code is currently not yet functional because I don't know how to get the MediaType so I can add it to the API name. To test if the rest of the code works I modified this line

const apiSettings = [api.apiName, MediaTypeModel].filter(s => s).join('') as keyof typeof this.plugin.settings;
const apiSettings = [api.apiName, "game"].filter(s => s).join('') as keyof typeof this.plugin.settings;

And it correctly filters out the APIs that are not checked. Same works for movies or series.

@mProjectsCode is there a way to get the media type after it calls APIManager?

@ltctceplrm
Copy link
Contributor Author

I've added a mediaType variable that gets sent with the search query so adding media by media type is currently functional.
I still need to fix the advanced APIsearch since that one is broken API's that you can turn off, I think I went wrong somewhere with the API = default check

openNoteInNewTab: boolean;
useDefaultFrontMatter: boolean;
enableTemplaterIntegration: boolean;
OMDbAPImovie: boolean;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would organize them into sub-objects, by media type.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also make the code for figuring out which APIs to use simpler.

});
});


Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better if these settings were automatically generated. That would mean less maintenance work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree but don't know how to do so yet, especially because it's only for certain APIs

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, if you don't know how to do that, then I will rewrite this after merging.

* @param apisToQuery
*/
async query(query: string, apisToQuery: string[]): Promise<MediaTypeModel[]> {
async query(query: string, apisToQuery: string[], mediaType: string): Promise<MediaTypeModel[]> {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would probably be better if you did the filtering of which APIs to query (based on the user's settings) before calling this method and leave the method as it was.

@ltctceplrm
Copy link
Contributor Author

@mProjectsCode I found the mistake I mentioned and simplified the code by removing the whole "default" API setting, now Advanced Search and Media Type Search both work correctly! I'm looking through your notes now and seeing what I need to change

@ltctceplrm
Copy link
Contributor Author

I reverted changes to main.ts so the this.apiManager.query method is left alone and instead modified hasType in APIModel.ts to check whether the API is turned on or not for the media type.

I've tested it out and it correctly skips the disabled APIs when selecting only 1 media type, however if you select multiple media types (movies and games) where the same API (omdb) has been turned off for one media type (movies) but not for another media type (games) then it will still return movies as well as games for omdb. I'm not sure if this is wanted/intentional or not.

@ltctceplrm
Copy link
Contributor Author

Seeing as the plugin is simultaneously searching for games and movies I don't see how it would be possible to exclude just the games returned by omdb without really overcomplicating the code. Unless I'm missing an easy solution I'd suggest maybe only being able to toggle one media type at a time and if you toggle a second one it un-toggles the previous one?

@ltctceplrm ltctceplrm marked this pull request as ready for review February 6, 2024 19:47
@ltctceplrm ltctceplrm changed the title WIP: Adding options to disable certain API per media type Adding options to disable certain API per media type Feb 6, 2024
@ltctceplrm
Copy link
Contributor Author

I pushed too soon, there's still a mistake in my toggle thingy

@ltctceplrm
Copy link
Contributor Author

Okay it's fixed now

@ltctceplrm
Copy link
Contributor Author

Please let me know if I should change anything else or if it's good like this

@mProjectsCode
Copy link
Owner

I am currently quite busy, I will review this maybe next week.

@ltctceplrm
Copy link
Contributor Author

That's okay, please take your time. Thank you for looking into it.


hasType(type: MediaType): boolean {
return this.types.contains(type);
if (this.types.contains(type) && !(this.plugin.settings[[this.apiName, type].filter(s => s).join('') as keyof typeof this.plugin.settings] === false)){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[this.apiName, type].filter(s => s).join('') as keyof typeof this.plugin.settings

Why not do (this.apiName + type) as keyof MediaDbPluginSettings?

However, I would still recommend organizing the settings into sub-objects for each api.

}
apiToggleComponent.onChange(value => {
this.selectedTypes.find(x => x.name === mediaType).selected = value;
if (value) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What exactly is this code doing? Are you forcing the value of the toggle to be off in certain conditions? If so there is a better way to disable the toggle component. See the setDisabled(value) prop of the toggle component.

});
});


Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, if you don't know how to do that, then I will rewrite this after merging.

@ltctceplrm
Copy link
Contributor Author

Thank you for looking over the code. I'm going to address some of the problems right now and the other ones I'll probably get to tomorrow.

@ltctceplrm
Copy link
Contributor Author

Hello @mProjectsCode, I finally succeeded turning the API toggles into sub objects like you asked, the code additions are once again fully functional (at least according to my tests). I believe I have finished with this pull request but please let me know if I forgot something

@mProjectsCode
Copy link
Owner

I will just merge this and then make some changes myself

@mProjectsCode mProjectsCode merged commit cf3d5c6 into mProjectsCode:master Apr 11, 2024
@ltctceplrm
Copy link
Contributor Author

That's great, thank you merging and also fixing up the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants