improve naming

This commit is contained in:
thierryverse 2025-11-12 13:27:15 +02:00
parent 207a284e9d
commit bd4e5d627d
14 changed files with 90 additions and 54 deletions

View file

@ -51,7 +51,7 @@ import {
} from "@/components/ui/select";
import { cn } from "@/lib/utils";
import { useAtomValue } from "jotai";
import { activeSearchSpaceChatsAtom } from "@/stores/chats/active-search-space-chats.atom";
import { activeSearchSpaceChatsAtom } from "@/atoms/chats/queries/active-search-space-chats.atom";
export interface Chat {
created_at: string;
@ -129,8 +129,6 @@ export default function ChatsPageClient({ searchSpaceId }: ChatsPageClientProps)
useEffect(() => {
let result = [...(chats || [])];
console.log("chats", chats);
// Filter by search term
if (searchQuery) {
const query = searchQuery.toLowerCase();

View file

@ -27,9 +27,9 @@ import {
} from "@/components/ui/sidebar";
import { useLLMPreferences } from "@/hooks/use-llm-configs";
import { cn } from "@/lib/utils";
import { activeChatIdAtom } from "@/stores/chats/active-chat.atom";
import { chatUIAtom } from "@/stores/chats/active-chat-ui.atom";
import { activeSearchSpaceIdAtom } from "@/stores/seach-space/active-seach-space.atom";
import { activeChatIdAtom } from "@/atoms/chats/queries/active-chat.atom";
import { chatUIAtom } from "@/atoms/chats/active-chat-ui.atom";
import { activeSearchSpaceIdAtom } from "@/atoms/seach-spaces/active-seach-space.atom";
export function DashboardClientLayout({
children,

View file

@ -0,0 +1,50 @@
import { atom } from "jotai";
import { atomWithQuery } from "jotai-tanstack-query";
import type { ChatDetails } from "@/app/dashboard/[search_space_id]/chats/chats-client";
import type { PodcastItem } from "@/app/dashboard/[search_space_id]/podcasts/podcasts-client";
import { fetchChatDetails } from "@/lib/apis/chat-apis";
import { getPodcastByChatId } from "@/lib/apis/podcast-apis";
import { cacheKeys } from "@/lib/query-client/cache-keys";
type ActiveChatState = {
chatId: string | null;
chatDetails: ChatDetails | null;
podcast: PodcastItem | null;
};
export const activeChatIdAtom = atom<string | null>(null);
export const activeChatAtom = atomWithQuery<ActiveChatState>((get) => {
const activeChatId = get(activeChatIdAtom);
const authToken = localStorage.getItem("surfsense_bearer_token");
if (!activeChatId) {
return {
queryKey: [],
enabled: false,
queryFn: async () => {
return { chatId: null, chatDetails: null, podcast: null };
},
};
}
return {
queryKey: cacheKeys.activeSearchSpace.activeChat(activeChatId),
enabled: !!activeChatId && !!authToken,
queryFn: async () => {
if (!authToken) {
throw new Error("No authentication token found");
}
if (!activeChatId) {
throw new Error("No active chat id found");
}
const [podcast, chatDetails] = await Promise.all([
getPodcastByChatId(activeChatId, authToken),
fetchChatDetails(activeChatId, authToken),
]);
return { chatId: activeChatId, chatDetails, podcast };
},
};
});

View file

@ -1,6 +1,6 @@
import { atomWithQuery } from "jotai-tanstack-query";
import { fetchChatsBySearchSpace } from "@/lib/apis/chat-apis";
import { activeSearchSpaceIdAtom } from "../seach-space/active-seach-space.atom";
import { activeSearchSpaceIdAtom } from "../../seach-spaces/active-seach-space.atom";
export const activeSearchSpaceChatsAtom = atomWithQuery((get) => {
const searchSpaceId = get(activeSearchSpaceIdAtom);

View file

@ -3,7 +3,7 @@
import { useAtom } from "jotai";
import { ExternalLink, Info, X } from "lucide-react";
import { Button } from "@/components/ui/button";
import { announcementDismissedAtom } from "@/stores/announcement.atom";
import { announcementDismissedAtom } from "@/atoms/announcement.atom";
export function AnnouncementBanner() {
const [isDismissed, setIsDismissed] = useAtom(announcementDismissedAtom);

View file

@ -4,8 +4,8 @@ import { LoaderIcon, PanelRight, TriangleAlert } from "lucide-react";
import { toast } from "sonner";
import { generatePodcast } from "@/lib/apis/podcast-apis";
import { cn } from "@/lib/utils";
import { activeChatAtom, activeChatIdAtom } from "@/stores/chats/active-chat.atom";
import { chatUIAtom } from "@/stores/chats/active-chat-ui.atom";
import { activeChatAtom, activeChatIdAtom } from "@/atoms/chats/queries/active-chat.atom";
import { chatUIAtom } from "@/atoms/chats/active-chat-ui.atom";
import { ChatPanelView } from "./ChatPanelView";
export interface GeneratePodcastRequest {

View file

@ -5,8 +5,8 @@ import { AlertCircle, Play, RefreshCw, Sparkles } from "lucide-react";
import { motion } from "motion/react";
import { useCallback } from "react";
import { cn } from "@/lib/utils";
import { activeChatAtom } from "@/stores/chats/active-chat.atom";
import { chatUIAtom } from "@/stores/chats/active-chat-ui.atom";
import { activeChatAtom } from "@/atoms/chats/queries/active-chat.atom";
import { chatUIAtom } from "@/atoms/chats/active-chat-ui.atom";
import { getPodcastStalenessMessage, isPodcastStale } from "../PodcastUtils";
import type { GeneratePodcastRequest } from "./ChatPanelContainer";
import { ConfigModal } from "./ConfigModal";

View file

@ -4,7 +4,7 @@ import { useAtomValue } from "jotai";
import { Pencil } from "lucide-react";
import { useCallback, useContext, useState } from "react";
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
import { activeChatAtom } from "@/stores/chats/active-chat.atom";
import { activeChatAtom } from "@/atoms/chats/queries/active-chat.atom";
import type { GeneratePodcastRequest } from "./ChatPanelContainer";
interface ConfigModalProps {

View file

@ -54,3 +54,27 @@ export const fetchChatsBySearchSpace = async (
return null;
}
};
export const deleteChat = async (chatId: number, authToken: string) => {
try {
const response = await fetch(
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/chats/${chatId}`,
{
method: "DELETE",
headers: {
Authorization: `Bearer ${authToken}`,
},
}
);
if (!response.ok) {
throw new Error(`Failed to delete chat: ${response.statusText}`);
}
return true;
} catch (err) {
console.error("Error deleting chat:", err);
return false;
}
};

View file

@ -1,4 +1,7 @@
export const cacheKeys = {
activeChat: (chatId: string) => ["activeChat", chatId],
activeSearchSpaceChats: (searchSpaceId: string) => ["activeSearchSpaceChats", searchSpaceId],
activeSearchSpace: {
chats : (searchSpaceId: string) => ["active-search-space", "chats", searchSpaceId] as const,
activeChat : (chatId: string) => ["active-search-space", "active-chat", chatId] as const,
deleteChat : ( searchSpaceId: string, chatId: string) => ["active-search-space", "chats", searchSpaceId, "delete", chatId] as const,
},
};

View file

@ -1,39 +0,0 @@
import { atom } from "jotai";
import { atomWithQuery } from "jotai-tanstack-query";
import type { ChatDetails } from "@/app/dashboard/[search_space_id]/chats/chats-client";
import type { PodcastItem } from "@/app/dashboard/[search_space_id]/podcasts/podcasts-client";
import { fetchChatDetails } from "@/lib/apis/chat-apis";
import { getPodcastByChatId } from "@/lib/apis/podcast-apis";
type ActiveChatState = {
chatId: string | null;
chatDetails: ChatDetails | null;
podcast: PodcastItem | null;
};
export const activeChatIdAtom = atom<string | null>(null);
export const activeChatAtom = atomWithQuery<ActiveChatState>((get) => {
const activeChatId = get(activeChatIdAtom);
const authToken = localStorage.getItem("surfsense_bearer_token");
return {
queryKey: ["activeChat", activeChatId],
enabled: !!activeChatId && !!authToken,
queryFn: async () => {
if (!authToken) {
throw new Error("No authentication token found");
}
if (!activeChatId) {
throw new Error("No active chat id found");
}
const [podcast, chatDetails] = await Promise.all([
getPodcastByChatId(activeChatId, authToken),
fetchChatDetails(activeChatId, authToken),
]);
return { chatId: activeChatId, chatDetails, podcast };
},
};
});