File size: 1,248 Bytes
5da4770 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
import { createMutationHook, createQueryHook } from "@/hooks/use-query";
import { threadKeys } from "./keys";
import { Thread, updateThread, toggleThreadPublicStatus, deleteThread, getThread } from "./utils";
import { getThreads } from "@/lib/api";
export const useThreadQuery = (threadId: string) =>
createQueryHook(
threadKeys.details(threadId),
() => getThread(threadId),
{
enabled: !!threadId,
retry: 1,
}
)();
export const useToggleThreadPublicStatus = () =>
createMutationHook(
({
threadId,
isPublic,
}: {
threadId: string;
isPublic: boolean;
}) => toggleThreadPublicStatus(threadId, isPublic)
)();
export const useUpdateThreadMutation = () =>
createMutationHook(
({
threadId,
data,
}: {
threadId: string;
data: Partial<Thread>,
}) => updateThread(threadId, data)
)()
export const useDeleteThreadMutation = () =>
createMutationHook(
({ threadId }: { threadId: string }) => deleteThread(threadId)
)()
export const useThreadsForProject = (projectId: string) => {
return createQueryHook(
threadKeys.byProject(projectId),
() => getThreads(projectId),
{
enabled: !!projectId,
retry: 1,
}
)();
}; |