Skip to content

Commit fb5d5d9

Browse files
authored
improvement(kb): add loading logic for document selector for kb block (#722)
1 parent 732df04 commit fb5d5d9

File tree

1 file changed

+11
-2
lines changed
  • apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/components/sub-block/components/document-selector

1 file changed

+11
-2
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/components/sub-block/components/document-selector/document-selector.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use client'
22

33
import { useCallback, useEffect, useState } from 'react'
4-
import { Check, ChevronDown, FileText } from 'lucide-react'
4+
import { Check, ChevronDown, FileText, RefreshCw } from 'lucide-react'
55
import { Button } from '@/components/ui/button'
66
import {
77
Command,
@@ -54,6 +54,7 @@ export function DocumentSelector({
5454
const [error, setError] = useState<string | null>(null)
5555
const [open, setOpen] = useState(false)
5656
const [selectedDocument, setSelectedDocument] = useState<DocumentData | null>(null)
57+
const [loading, setLoading] = useState(false)
5758

5859
// Use the proper hook to get the current value and setter
5960
const [storeValue, setStoreValue] = useSubBlockValue(blockId, subBlock.id)
@@ -72,6 +73,7 @@ export function DocumentSelector({
7273
return
7374
}
7475

76+
setLoading(true)
7577
setError(null)
7678

7779
try {
@@ -93,6 +95,8 @@ export function DocumentSelector({
9395
if ((err as Error).name === 'AbortError') return
9496
setError((err as Error).message)
9597
setDocuments([])
98+
} finally {
99+
setLoading(false)
96100
}
97101
}, [knowledgeBaseId])
98102

@@ -192,7 +196,12 @@ export function DocumentSelector({
192196
<CommandInput placeholder='Search documents...' />
193197
<CommandList>
194198
<CommandEmpty>
195-
{error ? (
199+
{loading ? (
200+
<div className='flex items-center justify-center p-4'>
201+
<RefreshCw className='h-4 w-4 animate-spin' />
202+
<span className='ml-2'>Loading documents...</span>
203+
</div>
204+
) : error ? (
196205
<div className='p-4 text-center'>
197206
<p className='text-destructive text-sm'>{error}</p>
198207
</div>

0 commit comments

Comments
 (0)