-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add sort option to search bar #57
Open
johahor
wants to merge
44
commits into
main
Choose a base branch
from
feat/sort-by-rating
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,025
−283
Open
Changes from all commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
60a510d
feat: update db seeding script to insert book genres
martakam 6eba723
fix: force book genres to be unique
martakam 1b0b3cd
feat: add GraphQL endpoint for genres
martakam bea8b4b
feat: allow filtering books based on genre
martakam 052de9c
fix: import better-auth util from correct package
martakam 0a5927d
fix: book genres we're searching for should be OR, not AND
martakam 05bb2b9
chore: generate GraphQL types
martakam 2cdf893
feat: add genre filtering to frontend
martakam 1d3ecfa
chore: generate GraphQL types
martakam 41b862a
feat: sort genres by popularity
martakam c0ecc59
test: add unit tests for genre filtering
martakam 610864a
feat: add languages to GraphQL schema
martakam 6458c3a
feat: add language filtering to FilterBooksSection
martakam 51362e6
test: check language filter usage and URL synchronization
martakam f511662
feat: add Silder component from Shadcn
martakam 8ea7baa
feat: add filtering based on page count
martakam 455ef84
test: check pages filter counts as one filter
martakam 885386b
test: pages count filter and URL synchronization
martakam 74516ec
fix: do not allow empty strings as values in book data
martakam 85e1e2f
chore: run Prettier after GraphQL codegen
martakam bda4670
feat: add book formats query to backend
martakam f7941ec
feat: add book format filtering to book filters
martakam 7e8bd88
Merge branch 'main' into feat/add-book-filters
martakam 34a0402
feat: add rating and numRatings to backend
johahor 01a98d0
chore: generate GraphQL types
johahor 7238d6a
feat: sort books by rating in searchBooks
johahor 8c068a9
feat: add book sort options to frontend
johahor ea892ed
feat: add sort to useBookSearchParams
johahor d148a70
feat: send sorting to searchBooks query
johahor 7e4bb1f
chore: generate GraphQL types
johahor 0e1cc03
feat: add sort select to search bar
johahor 491e5f0
refactor: rename pages filter to book length
martakam 9d2f92b
fix: reset page search param when changing filters
martakam 394d55f
Merge branch 'main' into feat/add-book-filters
martakam 47ded9b
feat: add rating and numRatings to backend
johahor fe7364a
chore: generate GraphQL types
johahor ca69070
feat: sort books by rating in searchBooks
johahor aa2e5a4
feat: add book sort options to frontend
johahor e41e2e2
feat: add sort to useBookSearchParams
johahor ff98e0d
feat: send sorting to searchBooks query
johahor 4e4afec
chore: generate GraphQL types
johahor 10f334e
feat: add sort select to search bar
johahor 21788de
Merge branch 'feat/sort-by-rating' of https://git.ntnu.no/IT2810-H26/…
martakam ffd979f
Update backend/src/schema/books/resolvers/Query/searchBooks.ts
johahor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| function parseRating({ | ||
| rating, | ||
| numRatings, | ||
| }: { | ||
| rating: string | number; | ||
| numRatings: string | number; | ||
| }) { | ||
| const count = Number.parseInt(String(numRatings), 10); | ||
| const average = Number.parseFloat(String(rating)); | ||
|
|
||
| const hasRatings = | ||
| Number.isFinite(count) && count > 0 && Number.isFinite(average); | ||
|
|
||
| // The dataset uses 0.0 for books without ratings. We store NULL instead, so unrated books are not mistaken for books with the worst rating. | ||
| return { | ||
| rating: hasRatings && average > 0 ? average : null, | ||
| numRatings: Number.isFinite(count) ? count : null, | ||
| }; | ||
| } | ||
|
|
||
| export { parseRating }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { asc, count, desc, isNotNull } from "drizzle-orm"; | ||
| import type { QueryResolvers } from "~/schema/types.generated"; | ||
| import { db } from "~/db"; | ||
| import { books } from "~/db/schema"; | ||
|
|
||
| export const bookFormats: NonNullable<QueryResolvers["bookFormats"]> = async ( | ||
| _parent, | ||
| _args, | ||
| _ctx, | ||
| ) => { | ||
| // Order by each format's book count, and then alphabetically | ||
| const rows = await db | ||
| .select({ bookFormat: books.bookFormat }) | ||
| .from(books) | ||
| .where(isNotNull(books.bookFormat)) | ||
| .groupBy(books.bookFormat) | ||
| .orderBy(desc(count()), asc(books.bookFormat)); | ||
|
|
||
| return rows.flatMap((row) => (row.bookFormat ? [row.bookFormat] : [])); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { asc, count, desc, eq } from "drizzle-orm"; | ||
| import type { QueryResolvers } from "~/schema/types.generated"; | ||
| import { db } from "~/db"; | ||
| import { bookGenres, bookToGenres } from "~/db/schema"; | ||
|
|
||
| export const genres: NonNullable<QueryResolvers["genres"]> = async ( | ||
| _parent, | ||
| _args, | ||
| _ctx, | ||
| ) => { | ||
| // Order by each genre's book count, and then alphabetically | ||
| const rows = await db | ||
| .select({ genre: bookGenres.genre }) | ||
| .from(bookGenres) | ||
| .leftJoin(bookToGenres, eq(bookToGenres.genreId, bookGenres.id)) | ||
| .groupBy(bookGenres.id) | ||
| .orderBy(desc(count(bookToGenres.bookId)), asc(bookGenres.genre)); | ||
|
|
||
| return rows.map((row) => row.genre); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { asc, count, desc, isNotNull } from "drizzle-orm"; | ||
| import type { QueryResolvers } from "~/schema/types.generated"; | ||
| import { db } from "~/db"; | ||
| import { books } from "~/db/schema"; | ||
|
|
||
| export const languages: NonNullable<QueryResolvers["languages"]> = async ( | ||
| _parent, | ||
| _args, | ||
| _ctx, | ||
| ) => { | ||
| // Order by each language's book count, and then alphabetically | ||
| const rows = await db | ||
| .select({ language: books.language }) | ||
| .from(books) | ||
| .where(isNotNull(books.language)) | ||
| .groupBy(books.language) | ||
| .orderBy(desc(count()), asc(books.language)); | ||
|
|
||
| return rows.flatMap((row) => (row.language ? [row.language] : [])); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.