mirror of
https://github.com/karakeep-app/karakeep.git
synced 2026-03-04 18:24:18 +01:00
50 lines
1.4 KiB
TypeScript
50 lines
1.4 KiB
TypeScript
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, context) => {
|
|
apiUtils.highlights.getForBookmark.invalidate({
|
|
bookmarkId: req.bookmarkId,
|
|
});
|
|
apiUtils.highlights.getAll.invalidate();
|
|
return opts[0]?.onSuccess?.(res, req, meta, context);
|
|
},
|
|
});
|
|
}
|
|
|
|
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, context) => {
|
|
apiUtils.highlights.getForBookmark.invalidate({
|
|
bookmarkId: res.bookmarkId,
|
|
});
|
|
apiUtils.highlights.getAll.invalidate();
|
|
return opts[0]?.onSuccess?.(res, req, meta, context);
|
|
},
|
|
});
|
|
}
|
|
|
|
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, context) => {
|
|
apiUtils.highlights.getForBookmark.invalidate({
|
|
bookmarkId: res.bookmarkId,
|
|
});
|
|
apiUtils.highlights.getAll.invalidate();
|
|
return opts[0]?.onSuccess?.(res, req, meta, context);
|
|
},
|
|
});
|
|
}
|