Skip to content

Commit c8d9244

Browse files
mfortman11ricofurtado
authored andcommitted
remove loadingStore and move the state into chat context (#1593)
1 parent 9d549b6 commit c8d9244

4 files changed

Lines changed: 14 additions & 26 deletions

File tree

frontend/app/chat/page.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { trackLLMCall } from "@/lib/analytics";
1313
import { FILE_CONFIRMATION, FILES_REGEX } from "@/lib/constants";
1414
import { buildSearchPayloadFilters } from "@/lib/filter-normalization";
1515
import { cn } from "@/lib/utils";
16-
import { useLoadingStore } from "@/stores/loadingStore";
1716
import { useGetConversationsQuery } from "../api/queries/useGetConversationsQuery";
1817
import { useGetNudgesQuery } from "../api/queries/useGetNudgesQuery";
1918
import { useGetSettingsQuery } from "../api/queries/useGetSettingsQuery";
@@ -32,7 +31,6 @@ import type {
3231

3332
function ChatPage() {
3433
const isDebugMode = process.env.NEXT_PUBLIC_OPENRAG_DEBUG === "true";
35-
const isCloudBrand = useIsCloudBrand();
3634
const {
3735
endpoint,
3836
setEndpoint,
@@ -50,6 +48,8 @@ function ChatPage() {
5048
placeholderConversation,
5149
conversationFilter,
5250
setConversationFilter,
51+
loading,
52+
setLoading,
5353
} = useChat();
5454
const [messages, setMessages] = useState<Message[]>([
5555
{
@@ -59,7 +59,6 @@ function ChatPage() {
5959
},
6060
]);
6161
const [input, setInput] = useState("");
62-
const { loading, setLoading } = useLoadingStore();
6362
const { setChatError } = useChat();
6463
const [asyncMode, setAsyncMode] = useState(true);
6564
const [expandedFunctionCalls, setExpandedFunctionCalls] = useState<
@@ -109,7 +108,7 @@ function ChatPage() {
109108
streamingMessage,
110109
sendMessage: sendStreamingMessage,
111110
abortStream,
112-
isLoading: isStreamLoading,
111+
isLoading: isChatStreaming,
113112
} = useChatStreaming({
114113
endpoint: apiEndpoint,
115114
onComplete: (message, responseId) => {
@@ -169,7 +168,7 @@ function ChatPage() {
169168
useEffect(() => {
170169
let timeoutId: NodeJS.Timeout | null = null;
171170

172-
if (isStreamLoading && !streamingMessage) {
171+
if (isChatStreaming && !streamingMessage) {
173172
timeoutId = setTimeout(() => {
174173
setWaitingTooLong(true);
175174
}, 20000); // 20 seconds
@@ -180,7 +179,7 @@ function ChatPage() {
180179
return () => {
181180
if (timeoutId) clearTimeout(timeoutId);
182181
};
183-
}, [isStreamLoading, streamingMessage]);
182+
}, [isChatStreaming, streamingMessage]);
184183

185184
const handleEndpointChange = (newEndpoint: EndpointType) => {
186185
setEndpoint(newEndpoint);
@@ -372,7 +371,7 @@ function ChatPage() {
372371

373372
if (
374373
conversationData?.messages &&
375-
(isNewConversation || (!isStreamLoading && hasMessageCountChanged)) &&
374+
(isNewConversation || (!isChatStreaming && hasMessageCountChanged)) &&
376375
!isUserInteracting &&
377376
!isForkingInProgress
378377
) {
@@ -564,7 +563,7 @@ function ChatPage() {
564563
isUserInteracting,
565564
isForkingInProgress,
566565
setPreviousResponseIds,
567-
isStreamLoading,
566+
isChatStreaming,
568567
messages.length,
569568
]);
570569

frontend/components/navigation.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import { useKnowledgeFilter } from "@/contexts/knowledge-filter-context";
2626
import { usePermissions } from "@/hooks/use-permissions";
2727
import { FILES_REGEX } from "@/lib/constants";
2828
import { cn } from "@/lib/utils";
29-
import { useLoadingStore } from "@/stores/loadingStore";
3029
import { DeleteSessionModal } from "./delete-session-modal";
3130
import { KnowledgeFilterList } from "./knowledge-filter-list";
3231

@@ -90,14 +89,9 @@ export function Navigation({
9089
placeholderConversation,
9190
setPlaceholderConversation,
9291
conversationLoaded,
92+
loading,
9393
} = useChat();
9494

95-
const { loading } = useLoadingStore();
96-
97-
useEffect(() => {
98-
console.log("loading", loading);
99-
}, [loading]);
100-
10195
const [previousConversationCount, setPreviousConversationCount] = useState(0);
10296
const [deleteModalOpen, setDeleteModalOpen] = useState(false);
10397
const [conversationToDelete, setConversationToDelete] =

frontend/contexts/chat-context.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ interface ChatContextType {
8787
setChatError: (hasError: boolean) => void;
8888
isOnboardingComplete: boolean;
8989
setOnboardingComplete: (complete: boolean) => void;
90+
loading: boolean;
91+
setLoading: (loading: boolean) => void;
9092
}
9193

9294
const ChatContext = createContext<ChatContextType | undefined>(undefined);
@@ -117,6 +119,7 @@ export function ChatProvider({ children }: ChatProviderProps) {
117119
const [conversationFilter, setConversationFilterState] =
118120
useState<KnowledgeFilter | null>(null);
119121
const [hasChatError, setChatError] = useState(false);
122+
const [loading, setLoading] = useState(false);
120123

121124
// Get settings to check if onboarding was completed (settings.edited)
122125
const { data: settings } = useGetSettingsQuery();
@@ -450,6 +453,8 @@ export function ChatProvider({ children }: ChatProviderProps) {
450453
setChatError,
451454
isOnboardingComplete,
452455
setOnboardingComplete,
456+
loading,
457+
setLoading,
453458
}),
454459
[
455460
endpoint,
@@ -473,6 +478,7 @@ export function ChatProvider({ children }: ChatProviderProps) {
473478
hasChatError,
474479
isOnboardingComplete,
475480
setOnboardingComplete,
481+
loading,
476482
],
477483
);
478484

frontend/stores/loadingStore.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)