feat(frontend): two-phase cloning with loading state

This commit is contained in:
CREDO23 2026-01-28 00:17:44 +02:00
parent 0c8d1f3fef
commit 9a4da10b12
5 changed files with 85 additions and 13 deletions

View file

@ -1,8 +1,12 @@
import {
type ClonePublicChatRequest,
type ClonePublicChatResponse,
type CompleteCloneRequest,
type CompleteCloneResponse,
clonePublicChatRequest,
clonePublicChatResponse,
completeCloneRequest,
completeCloneResponse,
type GetPublicChatRequest,
type GetPublicChatResponse,
getPublicChatRequest,
@ -29,6 +33,7 @@ class PublicChatApiService {
/**
* Clone a public chat to the user's account.
* Creates an empty thread and returns thread_id for redirect.
* Requires authentication.
*/
clonePublicChat = async (request: ClonePublicChatRequest): Promise<ClonePublicChatResponse> => {
@ -44,6 +49,25 @@ class PublicChatApiService {
clonePublicChatResponse
);
};
/**
* Complete the clone by copying messages and podcasts.
* Called from the chat page after redirect.
* Requires authentication.
*/
completeClone = async (request: CompleteCloneRequest): Promise<CompleteCloneResponse> => {
const parsed = completeCloneRequest.safeParse(request);
if (!parsed.success) {
const errorMessage = parsed.error.issues.map((issue) => issue.message).join(", ");
throw new ValidationError(`Invalid request: ${errorMessage}`);
}
return baseApiService.post(
`/api/v1/threads/${parsed.data.thread_id}/complete-clone`,
completeCloneResponse
);
};
}
export const publicChatApiService = new PublicChatApiService();