mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-01 20:03:30 +02:00
feat: update UI for snapshot-based public sharing
This commit is contained in:
parent
6aff69f4ec
commit
98991d2ed4
6 changed files with 39 additions and 155 deletions
|
|
@ -1,28 +1,31 @@
|
|||
import { atomWithMutation } from "jotai-tanstack-query";
|
||||
import { toast } from "sonner";
|
||||
import type {
|
||||
TogglePublicShareRequest,
|
||||
TogglePublicShareResponse,
|
||||
CreateSnapshotRequest,
|
||||
CreateSnapshotResponse,
|
||||
} from "@/contracts/types/chat-threads.types";
|
||||
import { chatThreadsApiService } from "@/lib/apis/chat-threads-api.service";
|
||||
|
||||
export const togglePublicShareMutationAtom = atomWithMutation(() => ({
|
||||
mutationFn: async (request: TogglePublicShareRequest) => {
|
||||
return chatThreadsApiService.togglePublicShare(request);
|
||||
export const createSnapshotMutationAtom = atomWithMutation(() => ({
|
||||
mutationFn: async (request: CreateSnapshotRequest) => {
|
||||
return chatThreadsApiService.createSnapshot(request);
|
||||
},
|
||||
onSuccess: (response: TogglePublicShareResponse) => {
|
||||
if (response.enabled && response.share_token) {
|
||||
const publicUrl = `${window.location.origin}/public/${response.share_token}`;
|
||||
navigator.clipboard.writeText(publicUrl);
|
||||
toast.success("Public link copied to clipboard", {
|
||||
description: "Anyone with this link can view the chat",
|
||||
onSuccess: (response: CreateSnapshotResponse) => {
|
||||
// Construct URL using frontend origin (backend returns its own URL which differs)
|
||||
const publicUrl = `${window.location.origin}/public/${response.share_token}`;
|
||||
navigator.clipboard.writeText(publicUrl);
|
||||
if (response.is_new) {
|
||||
toast.success("Public link created and copied to clipboard", {
|
||||
description: "Anyone with this link can view a snapshot of this chat",
|
||||
});
|
||||
} else {
|
||||
toast.success("Public sharing disabled");
|
||||
toast.success("Public link copied to clipboard", {
|
||||
description: "This snapshot already exists",
|
||||
});
|
||||
}
|
||||
},
|
||||
onError: (error: Error) => {
|
||||
console.error("Failed to toggle public share:", error);
|
||||
toast.error("Failed to update public sharing");
|
||||
console.error("Failed to create snapshot:", error);
|
||||
toast.error("Failed to create public link");
|
||||
},
|
||||
}));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue