Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

feat(sidebar): show throbber while threads are loading

Akarshan Biswasa848a48478a3
diff --git a/web-app/src/components/left-sidebar/NavChats.tsx b/web-app/src/components/left-sidebar/NavChats.tsx
index f8fc1e654..1d8ccc499 100644
--- a/web-app/src/components/left-sidebar/NavChats.tsx
+++ b/web-app/src/components/left-sidebar/NavChats.tsx
@@ -9,7 +9,7 @@ import {
DropdownMenuContent,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
-import { MoreHorizontal } from "lucide-react"
+import { MoreHorizontal, Loader2 } from "lucide-react"
import { useMemo, useState } from "react"
import { useTranslation } from '@/i18n/react-i18next-compat'
import { useThreads } from "@/hooks/useThreads"
@@ -20,6 +20,7 @@ export function NavChats() {
const { t } = useTranslation()
const getFilteredThreads = useThreads((state) => state.getFilteredThreads)
const threads = useThreads((state) => state.threads)
+ const isLoadingThreads = useThreads((state) => state.isLoadingThreads)
const deleteAllThreads = useThreads((state) => state.deleteAllThreads)
const [dropdownOpen, setDropdownOpen] = useState(false)
@@ -29,6 +30,16 @@ export function NavChats() {
}, [getFilteredThreads, threads])
if (threadsWithoutProject.length === 0) {
+ if (isLoadingThreads) {
+ return (
+ <SidebarGroup className="group-data-[collapsible=icon]:hidden">
+ <SidebarGroupLabel>{t('common:chats')}</SidebarGroupLabel>
+ <div className="flex items-center justify-center py-2">
+ <Loader2 className="size-4 animate-spin text-muted-foreground" />
+ </div>
+ </SidebarGroup>
+ )
+ }
return null
}
diff --git a/web-app/src/hooks/useThreads.ts b/web-app/src/hooks/useThreads.ts
index 6bdbb0c37..1fdc61d9e 100644
--- a/web-app/src/hooks/useThreads.ts
+++ b/web-app/src/hooks/useThreads.ts
@@ -11,6 +11,8 @@ import { useAppState } from '@/hooks/useAppState'
type ThreadState = {
threads: Record<string, Thread>
+ isLoadingThreads: boolean
+ setThreadsLoading: (loading: boolean) => void
currentThreadId?: string
getCurrentThread: () => Thread | undefined
setThreads: (threads: Thread[]) => void
@@ -58,6 +60,8 @@ const cleanupVectorDB = async (threadId: string) => {
export const useThreads = create<ThreadState>()((set, get) => ({
threads: {},
+ isLoadingThreads: true,
+ setThreadsLoading: (loading) => set({ isLoadingThreads: loading }),
searchIndex: null,
setThreads: (threads) => {
const threadMap = threads.reduce(
diff --git a/web-app/src/providers/DataProvider.tsx b/web-app/src/providers/DataProvider.tsx
index 77012fc55..80695b3d8 100644
--- a/web-app/src/providers/DataProvider.tsx
+++ b/web-app/src/providers/DataProvider.tsx
@@ -185,6 +185,7 @@ export function DataProvider() {
const { setServers, setSettings } = useMCPServers()
const { setAssistants } = useAssistant()
const { setThreads } = useThreads()
+ const setThreadsLoading = useThreads((s) => s.setThreadsLoading)
const navigate = useNavigate()
const serviceHub = useServiceHub()
@@ -301,9 +302,14 @@ export function DataProvider() {
return
}
setThreads(threads)
+ setThreadsLoading(false)
})
.catch(() => {
- if (cancelled || attempt >= 20) return
+ if (cancelled) return
+ if (attempt >= 20) {
+ setThreadsLoading(false)
+ return
+ }
attempt += 1
timer = setTimeout(load, Math.min(1000, 150 * attempt))
})
@@ -325,7 +331,7 @@ export function DataProvider() {
clearTimeout(timer)
unsubscribe()
}
- }, [serviceHub, setThreads])
+ }, [serviceHub, setThreads, setThreadsLoading])
// Sync remote providers with backend when providers change
const providers = useModelProvider((s) => s.providers)