aboutsummaryrefslogtreecommitdiffstats
path: root/packages/shared-react/hooks
diff options
context:
space:
mode:
authorMohamed Bassem <me@mbassem.com>2024-12-27 16:09:29 +0000
committerMohamed Bassem <me@mbassem.com>2024-12-27 16:09:29 +0000
commit86d74e3f32dd5bccc8df195b55391e206df9a1c4 (patch)
tree0db92b5139f9ef0c8909c16db72fbef782b770b6 /packages/shared-react/hooks
parenta23044bb74e01c861a92417c00d293ff86384e83 (diff)
downloadkarakeep-86d74e3f32dd5bccc8df195b55391e206df9a1c4.tar.zst
feat: Implement highlights support for links. Fixes #620
Diffstat (limited to 'packages/shared-react/hooks')
-rw-r--r--packages/shared-react/hooks/highlights.ts46
1 files changed, 46 insertions, 0 deletions
diff --git a/packages/shared-react/hooks/highlights.ts b/packages/shared-react/hooks/highlights.ts
new file mode 100644
index 00000000..299ed697
--- /dev/null
+++ b/packages/shared-react/hooks/highlights.ts
@@ -0,0 +1,46 @@
+import { api } from "../trpc";
+
+export function useCreateHighlight(
+ ...opts: Parameters<typeof api.highlights.create.useMutation>
+) {
+ const apiUtils = api.useUtils();
+ return api.highlights.create.useMutation({
+ ...opts[0],
+ onSuccess: (res, req, meta) => {
+ apiUtils.highlights.getForBookmark.invalidate({
+ bookmarkId: req.bookmarkId,
+ });
+ return opts[0]?.onSuccess?.(res, req, meta);
+ },
+ });
+}
+
+export function useUpdateHighlight(
+ ...opts: Parameters<typeof api.highlights.update.useMutation>
+) {
+ const apiUtils = api.useUtils();
+ return api.highlights.update.useMutation({
+ ...opts[0],
+ onSuccess: (res, req, meta) => {
+ apiUtils.highlights.getForBookmark.invalidate({
+ bookmarkId: res.bookmarkId,
+ });
+ return opts[0]?.onSuccess?.(res, req, meta);
+ },
+ });
+}
+
+export function useDeleteHighlight(
+ ...opts: Parameters<typeof api.highlights.delete.useMutation>
+) {
+ const apiUtils = api.useUtils();
+ return api.highlights.delete.useMutation({
+ ...opts[0],
+ onSuccess: (res, req, meta) => {
+ apiUtils.highlights.getForBookmark.invalidate({
+ bookmarkId: res.bookmarkId,
+ });
+ return opts[0]?.onSuccess?.(res, req, meta);
+ },
+ });
+}