-
-
Notifications
You must be signed in to change notification settings - Fork 833
feat: Add Bookmark Sorting Feature #812
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
feat: Add Bookmark Sorting Feature #812
Conversation
- Add sort order toggle in GlobalActions component - Implement ascending/descending sort functionality - Update translations for sorting feature in all languages - Add sort order icons and dropdown menu - Maintain sort preference in URL params
- Add sort order toggle in GlobalActions component - Implement ascending/descending sort functionality - Update translations for sorting feature in all languages - Add sort order icons and dropdown menu - Maintain sort preference in URL params during session Note: Sort order resets to default on page refresh, server-side persistence can be implemented in future enhancement
there is the new feature of smart lists/filtering based on queries. My assumption was, that sorting would be part of the query language in the future, since your solution will not work with pagination i assume? |
I do not have knowledge about smart lists/filtering. Is this upcoming feature? |
Hey, thanks for the PR! My plan (still haven't given it a lot of thought) is to keep sorting and smart search separate (the way this PR introduces it) because sorting is needed even when smart searching is not used. Will hopefully be able to review this PR over the weekend. |
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.
Hey, thanks for the PR! Overall, the approach looks good to me. Left some comments, that we can merge the PR after they get addressed.
pnpm-lock.yaml
Outdated
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.
I think you might be using a different pnpm version which introduced a lot of changes to the lock file. Those will probably need to be reverted.
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.
sure.
packages/shared/types/bookmarks.ts
Outdated
@@ -161,6 +167,8 @@ export const zGetBookmarksRequestSchema = z.object({ | |||
// The value is currently not being used, but keeping it so that client can still set it to true for older | |||
// servers. | |||
useCursorV2: z.boolean().optional(), | |||
sortBy: zSortBy.optional().default("createdAt"), |
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.
Given that this is currently unused, should we just drop it for now to avoid confusion?
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.
yes, removed it.
packages/shared/types/bookmarks.ts
Outdated
@@ -12,6 +12,12 @@ export const enum BookmarkTypes { | |||
UNKNOWN = "unknown", | |||
} | |||
|
|||
export const zSortOrder = z.enum(["asc", "desc"]); | |||
export type SortOrder = z.infer<typeof zSortOrder>; |
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.
Please follow the same style in the rest of the file. All zod inferred type start with the Z
prefix.
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.
Done
packages/shared/types/bookmarks.ts
Outdated
export type SortOrder = z.infer<typeof zSortOrder>; | ||
|
||
export const zSortBy = z.enum(["createdAt"]); | ||
export type SortBy = z.infer<typeof zSortBy>; |
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.
Same comment about the prefix.
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.
Removed this as well.
className="cursor-pointer justify-between" | ||
onClick={() => updateSort("desc")} | ||
> | ||
<span>{t("actions.sort.newest_first")}</span> |
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.
Let's include some lucide sort icons here to make it look nicer: https://lucide.dev/icons/?search=sort
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.
Added icon here. Let me know if you think some other icon should be there.
.orderBy( | ||
input.sortOrder === "asc" | ||
? asc(bookmarks.createdAt) | ||
: desc(bookmarks.createdAt), | ||
desc(bookmarks.id), | ||
), |
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.
Given that this order button is global, we'll need to modify the searchBookmarks
endpoint as well, and modify apps/web/lib/hooks/bookmark-search.ts
to pass the sorting order to it as well.
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.
Yes, search will also support sorting now.
Hi @MohamedBassem, thanks for reviewing PR. |
839c1ed
to
7daa87b
Compare
- Implement global sort order functionality using a shared Zustand store (`useSortOrder` hook). - Update `getBookmarks` and `searchBookmarks` endpoints to accept a `sortOrder` parameter. - Refactor code to import `ZSortOrder` from shared types (`bookmarks.ts`), ensuring consistency across the codebase. - Update components (`UpdatableBookmarksGrid`, `bookmark-search`) to use the shared `useSortOrder` hook. - Remove unused `zSortBy` definition from `packages/shared/types/bookmarks.ts` to avoid confusion. - Ensure consistent naming conventions by prefixing Zod inferred types with `Z`. - Clean up code and address previous PR feedback comments.
Hello @MohamedBassem, Thanks |
Thank you! |
Hey @MohamedBassem btw when is next release planned? |
@dakshpareek Given that the last release was last week, I think it'll be sometime until the next one. Maybe 3 weeks or so until we accumulate enough features for the release. There hasn't been a lot of changes since the release, so the nightly build should be stable if you want to switch to it today and have your feature available there today :D |
This PR adds the ability to sort bookmarks by creation date in ascending or descending order.
Changes
Screenshots
Testing Done
Notes