refactor: consolidate public chat snapshot mutations with cache invalidation

This commit is contained in:
CREDO23 2026-02-02 16:47:23 +02:00
parent 67f797232e
commit ee56334abe
5 changed files with 41 additions and 35 deletions

View file

@ -5,7 +5,7 @@ import { useAtomValue, useSetAtom } from "jotai";
import { Globe, User, Users } from "lucide-react";
import { useCallback, useMemo, useState } from "react";
import { toast } from "sonner";
import { createPublicChatSnapshotMutationAtom } from "@/atoms/chat/chat-thread-mutation.atoms";
import { createPublicChatSnapshotMutationAtom } from "@/atoms/public-chat-snapshots/public-chat-snapshots-mutation.atoms";
import { currentThreadAtom, setThreadVisibilityAtom } from "@/atoms/chat/current-thread.atom";
import { myAccessAtom } from "@/atoms/members/members-query.atoms";
import { Button } from "@/components/ui/button";

View file

@ -23,7 +23,7 @@ export function PublicChatSnapshotsManager({
const [deletingId, setDeletingId] = useState<number | undefined>();
// Data fetching
const { data: snapshotsData, isLoading, isError, refetch } = useAtomValue(publicChatSnapshotsAtom);
const { data: snapshotsData, isLoading, isError } = useAtomValue(publicChatSnapshotsAtom);
// Permissions
const { data: access } = useAtomValue(myAccessAtom);
@ -57,14 +57,13 @@ export function PublicChatSnapshotsManager({
thread_id: snapshot.thread_id,
snapshot_id: snapshot.id,
});
await refetch();
} catch (error) {
console.error("Failed to delete snapshot:", error);
} finally {
setDeletingId(undefined);
}
},
[deleteSnapshot, refetch]
[deleteSnapshot]
);
// Loading state