replies.ts•2.46 kB
/**
* Generated by orval v7.2.0 🍺
* Do not edit manually.
* storyden
* Storyden social API for building community driven platforms.
The Storyden API does not adhere to semantic versioning but instead applies a rolling strategy with deprecations and minimal breaking changes. This has been done mainly for a simpler development process and it may be changed to a more fixed versioning strategy in the future. Ultimately, the primary way Storyden tracks versions is dates, there are no set release tags currently.
* OpenAPI spec version: v1.25.8-canary
*/
import type { Key } from "swr";
import useSWRMutation from "swr/mutation";
import type { SWRMutationConfiguration } from "swr/mutation";
import { fetcher } from "../client";
import type {
InternalServerErrorResponse,
NotFoundResponse,
ReplyCreateBody,
ReplyCreateOKResponse,
UnauthorisedResponse,
} from "../openapi-schema";
/**
* Create a new post within a thread.
*/
export const replyCreate = (
threadMark: string,
replyCreateBody: ReplyCreateBody,
) => {
return fetcher<ReplyCreateOKResponse>({
url: `/threads/${threadMark}/replies`,
method: "POST",
headers: { "Content-Type": "application/json" },
data: replyCreateBody,
});
};
export const getReplyCreateMutationFetcher = (threadMark: string) => {
return (
_: Key,
{ arg }: { arg: ReplyCreateBody },
): Promise<ReplyCreateOKResponse> => {
return replyCreate(threadMark, arg);
};
};
export const getReplyCreateMutationKey = (threadMark: string) =>
[`/threads/${threadMark}/replies`] as const;
export type ReplyCreateMutationResult = NonNullable<
Awaited<ReturnType<typeof replyCreate>>
>;
export type ReplyCreateMutationError =
| UnauthorisedResponse
| NotFoundResponse
| InternalServerErrorResponse;
export const useReplyCreate = <
TError =
| UnauthorisedResponse
| NotFoundResponse
| InternalServerErrorResponse,
>(
threadMark: string,
options?: {
swr?: SWRMutationConfiguration<
Awaited<ReturnType<typeof replyCreate>>,
TError,
Key,
ReplyCreateBody,
Awaited<ReturnType<typeof replyCreate>>
> & { swrKey?: string };
},
) => {
const { swr: swrOptions } = options ?? {};
const swrKey = swrOptions?.swrKey ?? getReplyCreateMutationKey(threadMark);
const swrFn = getReplyCreateMutationFetcher(threadMark);
const query = useSWRMutation(swrKey, swrFn, swrOptions);
return {
swrKey,
...query,
};
};