mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-27 09:46:25 +02:00
improve naming
This commit is contained in:
parent
207a284e9d
commit
bd4e5d627d
14 changed files with 90 additions and 54 deletions
|
|
@ -51,7 +51,7 @@ import {
|
||||||
} from "@/components/ui/select";
|
} from "@/components/ui/select";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { useAtomValue } from "jotai";
|
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 {
|
export interface Chat {
|
||||||
created_at: string;
|
created_at: string;
|
||||||
|
|
@ -129,8 +129,6 @@ export default function ChatsPageClient({ searchSpaceId }: ChatsPageClientProps)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let result = [...(chats || [])];
|
let result = [...(chats || [])];
|
||||||
|
|
||||||
console.log("chats", chats);
|
|
||||||
|
|
||||||
// Filter by search term
|
// Filter by search term
|
||||||
if (searchQuery) {
|
if (searchQuery) {
|
||||||
const query = searchQuery.toLowerCase();
|
const query = searchQuery.toLowerCase();
|
||||||
|
|
|
||||||
|
|
@ -27,9 +27,9 @@ import {
|
||||||
} from "@/components/ui/sidebar";
|
} from "@/components/ui/sidebar";
|
||||||
import { useLLMPreferences } from "@/hooks/use-llm-configs";
|
import { useLLMPreferences } from "@/hooks/use-llm-configs";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { activeChatIdAtom } from "@/stores/chats/active-chat.atom";
|
import { activeChatIdAtom } from "@/atoms/chats/queries/active-chat.atom";
|
||||||
import { chatUIAtom } from "@/stores/chats/active-chat-ui.atom";
|
import { chatUIAtom } from "@/atoms/chats/active-chat-ui.atom";
|
||||||
import { activeSearchSpaceIdAtom } from "@/stores/seach-space/active-seach-space.atom";
|
import { activeSearchSpaceIdAtom } from "@/atoms/seach-spaces/active-seach-space.atom";
|
||||||
|
|
||||||
export function DashboardClientLayout({
|
export function DashboardClientLayout({
|
||||||
children,
|
children,
|
||||||
|
|
|
||||||
50
surfsense_web/atoms/chats/queries/active-chat.atom.ts
Normal file
50
surfsense_web/atoms/chats/queries/active-chat.atom.ts
Normal 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 };
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { atomWithQuery } from "jotai-tanstack-query";
|
import { atomWithQuery } from "jotai-tanstack-query";
|
||||||
import { fetchChatsBySearchSpace } from "@/lib/apis/chat-apis";
|
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) => {
|
export const activeSearchSpaceChatsAtom = atomWithQuery((get) => {
|
||||||
const searchSpaceId = get(activeSearchSpaceIdAtom);
|
const searchSpaceId = get(activeSearchSpaceIdAtom);
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
import { useAtom } from "jotai";
|
import { useAtom } from "jotai";
|
||||||
import { ExternalLink, Info, X } from "lucide-react";
|
import { ExternalLink, Info, X } from "lucide-react";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { announcementDismissedAtom } from "@/stores/announcement.atom";
|
import { announcementDismissedAtom } from "@/atoms/announcement.atom";
|
||||||
|
|
||||||
export function AnnouncementBanner() {
|
export function AnnouncementBanner() {
|
||||||
const [isDismissed, setIsDismissed] = useAtom(announcementDismissedAtom);
|
const [isDismissed, setIsDismissed] = useAtom(announcementDismissedAtom);
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@ import { LoaderIcon, PanelRight, TriangleAlert } from "lucide-react";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { generatePodcast } from "@/lib/apis/podcast-apis";
|
import { generatePodcast } from "@/lib/apis/podcast-apis";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { activeChatAtom, activeChatIdAtom } from "@/stores/chats/active-chat.atom";
|
import { activeChatAtom, activeChatIdAtom } from "@/atoms/chats/queries/active-chat.atom";
|
||||||
import { chatUIAtom } from "@/stores/chats/active-chat-ui.atom";
|
import { chatUIAtom } from "@/atoms/chats/active-chat-ui.atom";
|
||||||
import { ChatPanelView } from "./ChatPanelView";
|
import { ChatPanelView } from "./ChatPanelView";
|
||||||
|
|
||||||
export interface GeneratePodcastRequest {
|
export interface GeneratePodcastRequest {
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@ import { AlertCircle, Play, RefreshCw, Sparkles } from "lucide-react";
|
||||||
import { motion } from "motion/react";
|
import { motion } from "motion/react";
|
||||||
import { useCallback } from "react";
|
import { useCallback } from "react";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { activeChatAtom } from "@/stores/chats/active-chat.atom";
|
import { activeChatAtom } from "@/atoms/chats/queries/active-chat.atom";
|
||||||
import { chatUIAtom } from "@/stores/chats/active-chat-ui.atom";
|
import { chatUIAtom } from "@/atoms/chats/active-chat-ui.atom";
|
||||||
import { getPodcastStalenessMessage, isPodcastStale } from "../PodcastUtils";
|
import { getPodcastStalenessMessage, isPodcastStale } from "../PodcastUtils";
|
||||||
import type { GeneratePodcastRequest } from "./ChatPanelContainer";
|
import type { GeneratePodcastRequest } from "./ChatPanelContainer";
|
||||||
import { ConfigModal } from "./ConfigModal";
|
import { ConfigModal } from "./ConfigModal";
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import { useAtomValue } from "jotai";
|
||||||
import { Pencil } from "lucide-react";
|
import { Pencil } from "lucide-react";
|
||||||
import { useCallback, useContext, useState } from "react";
|
import { useCallback, useContext, useState } from "react";
|
||||||
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
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";
|
import type { GeneratePodcastRequest } from "./ChatPanelContainer";
|
||||||
|
|
||||||
interface ConfigModalProps {
|
interface ConfigModalProps {
|
||||||
|
|
|
||||||
|
|
@ -54,3 +54,27 @@ export const fetchChatsBySearchSpace = async (
|
||||||
return null;
|
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;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
export const cacheKeys = {
|
export const cacheKeys = {
|
||||||
activeChat: (chatId: string) => ["activeChat", chatId],
|
activeSearchSpace: {
|
||||||
activeSearchSpaceChats: (searchSpaceId: string) => ["activeSearchSpaceChats", searchSpaceId],
|
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,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -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 };
|
|
||||||
},
|
|
||||||
};
|
|
||||||
});
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue