51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
import { api } from "../trpc";
|
|
|
|
export function useUpdateLabel(
|
|
...opts: Parameters<typeof api.labels.update.useMutation>
|
|
) {
|
|
const apiUtils = api.useUtils();
|
|
|
|
return api.tags.update.useMutation({
|
|
...opts[0],
|
|
onSuccess: (res, req, meta) => {
|
|
apiUtils.labels.list.invalidate();
|
|
apiUtils.labels.get.invalidate({ labelId: res.id });
|
|
// apiUtils.bookmarks.getBookmarks.invalidate({
|
|
// labelId: res.id;
|
|
|
|
// TODO: Maybe we can only look at the cache and invalidate only affected bookmarks
|
|
// apiUtils.bookmarks.getBookmark.invalidate();
|
|
return opts[0]?.onSuccess?.(res, req, meta);
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useDeleteLabel(
|
|
...opts: Parameters<typeof api.labels.delete.useMutation>
|
|
) {
|
|
const apiUtils = api.useUtils();
|
|
|
|
return api.labels.delete.useMutation({
|
|
...opts[0],
|
|
onSuccess: (res, req, meta) => {
|
|
apiUtils.labels.list.invalidate();
|
|
// apiUtils.bookmarks.getBookmark.invalidate();
|
|
return opts[0]?.onSuccess?.(res, req, meta);
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useDeleteUnusedTags(
|
|
...opts: Parameters<typeof api.tags.deleteUnused.useMutation>
|
|
) {
|
|
const apiUtils = api.useUtils();
|
|
|
|
return api.tags.deleteUnused.useMutation({
|
|
...opts[0],
|
|
onSuccess: (res, req, meta) => {
|
|
apiUtils.tags.list.invalidate();
|
|
return opts[0]?.onSuccess?.(res, req, meta);
|
|
},
|
|
});
|
|
}
|