mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-28 18:36:23 +02:00
improve naming
This commit is contained in:
parent
207a284e9d
commit
bd4e5d627d
14 changed files with 90 additions and 54 deletions
5
surfsense_web/atoms/announcement.atom.ts
Normal file
5
surfsense_web/atoms/announcement.atom.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import { atomWithStorage } from "jotai/utils";
|
||||
|
||||
// Atom to track whether the announcement banner has been dismissed
|
||||
// Persists to localStorage automatically
|
||||
export const announcementDismissedAtom = atomWithStorage("surfsense_announcement_dismissed", false);
|
||||
9
surfsense_web/atoms/chats/active-chat-ui.atom.ts
Normal file
9
surfsense_web/atoms/chats/active-chat-ui.atom.ts
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import { atom } from "jotai";
|
||||
|
||||
type ChatUIState = {
|
||||
isChatPannelOpen: boolean;
|
||||
};
|
||||
|
||||
export const chatUIAtom = atom<ChatUIState>({
|
||||
isChatPannelOpen: false,
|
||||
});
|
||||
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 };
|
||||
},
|
||||
};
|
||||
});
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
import { atomWithQuery } from "jotai-tanstack-query";
|
||||
import { fetchChatsBySearchSpace } from "@/lib/apis/chat-apis";
|
||||
import { activeSearchSpaceIdAtom } from "../../seach-spaces/active-seach-space.atom";
|
||||
|
||||
export const activeSearchSpaceChatsAtom = atomWithQuery((get) => {
|
||||
const searchSpaceId = get(activeSearchSpaceIdAtom);
|
||||
const authToken = localStorage.getItem("surfsense_bearer_token");
|
||||
|
||||
return {
|
||||
queryKey: ["chatsBySearchSpace", searchSpaceId],
|
||||
enabled: !!searchSpaceId && !!authToken,
|
||||
queryFn: async () => {
|
||||
if (!authToken) {
|
||||
throw new Error("No authentication token found");
|
||||
}
|
||||
if (!searchSpaceId) {
|
||||
throw new Error("No search space id found");
|
||||
}
|
||||
|
||||
return fetchChatsBySearchSpace(searchSpaceId, authToken);
|
||||
},
|
||||
};
|
||||
});
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
import { atom } from "jotai";
|
||||
|
||||
export const activeSearchSpaceIdAtom = atom<string | null>(null);
|
||||
Loading…
Add table
Add a link
Reference in a new issue