mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-31 19:45:15 +02:00
feat: add public chat frontend
This commit is contained in:
parent
9d7259aab9
commit
37adc54d6a
9 changed files with 415 additions and 1 deletions
56
surfsense_web/components/public-chat/public-chat-footer.tsx
Normal file
56
surfsense_web/components/public-chat/public-chat-footer.tsx
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
"use client";
|
||||
|
||||
import { Copy, Loader2 } from "lucide-react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { publicChatApiService } from "@/lib/apis/public-chat-api.service";
|
||||
import { getBearerToken } from "@/lib/auth-utils";
|
||||
|
||||
interface PublicChatFooterProps {
|
||||
shareToken: string;
|
||||
}
|
||||
|
||||
export function PublicChatFooter({ shareToken }: PublicChatFooterProps) {
|
||||
const router = useRouter();
|
||||
const [isCloning, setIsCloning] = useState(false);
|
||||
|
||||
const handleCopyAndContinue = async () => {
|
||||
const token = getBearerToken();
|
||||
|
||||
if (!token) {
|
||||
const returnUrl = encodeURIComponent(`/public/${shareToken}`);
|
||||
router.push(`/login?returnUrl=${returnUrl}&action=clone`);
|
||||
return;
|
||||
}
|
||||
|
||||
setIsCloning(true);
|
||||
|
||||
try {
|
||||
await publicChatApiService.clonePublicChat({
|
||||
share_token: shareToken,
|
||||
});
|
||||
|
||||
toast.success("Copying chat to your account...", {
|
||||
description: "You'll be notified when it's ready.",
|
||||
});
|
||||
|
||||
router.push("/dashboard");
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : "Failed to copy chat";
|
||||
toast.error(message);
|
||||
} finally {
|
||||
setIsCloning(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="mx-auto flex max-w-(--thread-max-width) items-center justify-center px-4 py-4">
|
||||
<Button size="lg" onClick={handleCopyAndContinue} disabled={isCloning} className="gap-2">
|
||||
{isCloning ? <Loader2 className="size-4 animate-spin" /> : <Copy className="size-4" />}
|
||||
Copy and continue this chat
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue