Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CritiqueBrainz functions to APIService #1584

Merged
merged 7 commits into from
Aug 25, 2021
Merged

Conversation

jdaok
Copy link
Contributor

@jdaok jdaok commented Aug 22, 2021

(this PR does not depend on any others and can be merged)

This PR adds some types and helper functions to APIService that will be used by the Critiquebrainz review modal.

lookupMBRelease() & lookupMBReleaseFromTrack() send lookup requests to MusicBrainz, these will be used to search for entities of Listens in the review modal.

Adds submitReviewToCB(), lookupMBRelease(), lookupMBReleaseFromTrack() for use by the Critiquebrainz review modal
@amCap1712 amCap1712 merged commit 86aa345 into metabrainz:master Aug 25, 2021
Comment on lines +892 to +893
const data = await response.json();
return data;
Copy link
Member

Choose a reason for hiding this comment

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

This is equivalent to return await response.json(); which is warned against by an eslint rule. Here's a nice writeup on it, https://jakearchibald.com/2017/await-vs-return-vs-return-await/. TL,DR; is that return await is only useful inside a try/catch.

So in this case, it'll probably be fine to do return response.json(). But I am not sure if we would want to add a try/catch here or in the react component etc. @MonkeyDo knows better about react error handling so this is fine by me for now.

Copy link
Member

Choose a reason for hiding this comment

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

I agree that over here we will be fine with just return response.json(). The relevant change can be made.

Copy link
Member

@akshaaatt akshaaatt left a comment

Choose a reason for hiding this comment

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

I think we do need to fix the await implementation as I have mentioned. The rest is good.
Great work!

Comment on lines +892 to +893
const data = await response.json();
return data;
Copy link
Member

Choose a reason for hiding this comment

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

I agree that over here we will be fine with just return response.json(). The relevant change can be made.

lookupMBRelease = async (releaseMBID: string): Promise<any> => {
const url = `${this.MBBaseURI}/release/${releaseMBID}?fmt=json&inc=release-groups`;
const response = await fetch(encodeURI(url));
this.checkStatus(response);
Copy link
Member

Choose a reason for hiding this comment

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

We are missing an await over here.

lookupMBReleaseFromTrack = async (trackMBID: string): Promise<any> => {
const url = `${this.MBBaseURI}/release?track=${trackMBID}&fmt=json`;
const response = await fetch(encodeURI(url));
this.checkStatus(response);
Copy link
Member

Choose a reason for hiding this comment

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

The await again.

entity_id: string;
entity_type: ReviewableEntityType;
text: string;
languageCode: string;
Copy link
Member

Choose a reason for hiding this comment

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

This could just be language since the api uses this standard. This is not necessary though.

@amCap1712
Copy link
Member

Good catch regarding the missing await! Since, this one is already merged I'll open a new PR fixing this. Also, I see there are many other methods in APIService class which do not have the await. Will fix those too.

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.

4 participants