Skip to content

Search improvements#15

Open
TheLingo1 wants to merge 1 commit intosubject-f:masterfrom
TheLingo1:search-patch
Open

Search improvements#15
TheLingo1 wants to merge 1 commit intosubject-f:masterfrom
TheLingo1:search-patch

Conversation

@TheLingo1
Copy link

These changes do the following two things:

1. Fix search for NH source.

adding includedTags: [] to the query object in Search.js prevents the proxy url from having %20undefined appended to it, letting the query return successfully.

2. Implement TODO from Search.js.

Changes behavior in Search.js and ScrollableCarousel.js so that only 1 search is done per source, and subsequent searches are done as the user scrolls the carousel near the end.

Copy link
Collaborator

@funkyhippo funkyhippo left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution, reviewing this (+ JS rather than TS code) was a blast-to-the-past and the equivalent to rawdogging digital junk-food.

I left a couple comments.

if (event.key === "Enter" && event.target.value) {
let query = {
title: event.target.value,
includedTags: [],
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure whether this is safe to include as a default; I think it's up to the source to implement the search logic, and it's possible that the inclusion of includedTags would trigger a different search path.

I only spot-checked a single source, but the version of the NHentai source has code that checks for tags, which would result in undefined in the query because of the optional chaining. It doesn't seem like it actually breaks the searching though.

Were there other sources that had buggy implementations?

Copy link
Author

Choose a reason for hiding this comment

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

Hey, thanks for the comments, I agree that having it included by default probably isn't a great idea.

I don't know if it's an issue on my end or not but I haven't been able to get the NH search to return anything unless the undefined was removed from the query. i.e. /api/galleries/search?query=test%20undefined&page=1 returns an empty list but /api/galleries/search?query=test&page=1 had actual results.

Scanning through the other sources I didn't see any that had issues with includedTags the same way in their search implementations. Would having an extra check in runSearchQuery to only add the empty tags array to the NH source be a better solution?

Ex:

runSearchQuery = (query) => {
  Object.entries(this.props.sources).forEach(([sourceName, source]) => {
    const modifiedQuery = (sourceName === "NHentai") ? { ...query, includedTags: [] } : { ...query };
    const queryTask = {
      source,
      query: modifiedQuery,
      metadata: undefined,
    };
    this.sourceQueryHelper(sourceName, source, queryTask);
  });
};

Comment on lines +63 to +65
if(this.state.itemLength + LOAD_BATCH_COUNT >= this.state.childrenLength &&
this.props.onReachEnd &&
!this.state.loadingMore) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: formatting (though apologies, this repo wasn't opinionated in having the right checks in place)

Comment on lines +67 to +69
Promise.resolve(this.props.onReachEnd()).finally(() => {
this.setState({ loadingMore: false });
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this behave correctly if the carousel is expanded? The component is somewhat poorly named, since it can be a magazine-like component if expanded.

Comment on lines +157 to +159
onReachEnd={
hasMoreInSource ? async () => await this.loadMoreFromSource(source) : undefined
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we opt to implement this, we may need to update the lines above to somehow signal the number of results that are actually available:

`${results.length} result(s)`

Otherwise it might be misleading to the user for the number of results.

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