-
Notifications
You must be signed in to change notification settings - Fork 59
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
Adds search by genre to WebUI #238
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,19 +41,36 @@ const queryFilter = (query: NullAndUndefined<string>, { title }: IMangaCard): bo | |
return title.toLowerCase().includes(query.toLowerCase()); | ||
}; | ||
|
||
const queryGenreFilter = (query: NullAndUndefined<string>, { genre }: IMangaCard): boolean => { | ||
if (!query) return true; | ||
const queries = query.split(',').map((str) => str.toLowerCase().trim()); | ||
return queries.every((element) => genre.map((el) => el.toLowerCase()).includes(element)); | ||
}; | ||
|
||
const filterManga = ( | ||
manga: IMangaCard[], | ||
query: NullAndUndefined<string>, | ||
unread: NullAndUndefined<boolean>, | ||
downloaded: NullAndUndefined<boolean>, | ||
): IMangaCard[] => | ||
manga.filter((m) => { | ||
if (query) { | ||
return queryFilter(query, m); | ||
} | ||
|
||
return downloadedFilter(downloaded, m) && unreadFilter(unread, m); | ||
}); | ||
): IMangaCard[] => { | ||
let filteredManga: IMangaCard[] = []; | ||
if (query) { | ||
const titleFilteredManga = manga.filter((m) => queryFilter(query, m)); | ||
const genreFilteredManga = manga.filter((m) => queryGenreFilter(query, m)); | ||
const unique = titleFilteredManga.concat(genreFilteredManga).reduce((acc: Record<number, IMangaCard>, obj) => { | ||
const { id } = obj; | ||
if (!acc[id]) { | ||
acc[id] = obj; | ||
} | ||
return acc; | ||
}, {}); | ||
filteredManga = Object.values(unique); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this commit reverts #226. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this not how the app works? If you want to search something that is not downloaded then you remove the filter and search for it, right? It felt like a bug that my filters were not being honored when I searched for my manga I believe we should stick close to the app implementation. If setting and unsetting the filters are cumbersome or buggy we could improve the experience there. I will adhere to the consensus. But, I think we should keep this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I never used the app (don't have an android), so I can't say. I guess it's preference. I expected it to search my whole library (or at least the category, since whole library is not possible). if it should work like the app, what about adding some kind of flag to search all mangas/ignore filters? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That sounds like a good workaround, but for that we need to clarify the following details
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @schroda any opinions on these? I'd like to get this PR reviewed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
filteredManga = (filteredManga.length ? filteredManga : manga).filter( | ||
(m) => downloadedFilter(downloaded, m) && unreadFilter(unread, m), | ||
); | ||
return filteredManga; | ||
}; | ||
|
||
const sortByUnread = (a: IMangaCard, b: IMangaCard): number => | ||
// eslint-disable-next-line implicit-arrow-linebreak | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will keep the mangas that matched by title above the ones that matched by genre. I am working on a more streamlined version that gives a rank to manga objects while filtering, and sorts accordingly. Could be more performant