diff --git a/packages/frontend/core/src/modules/workspace-indexer-embedding/entities/embedding.ts b/packages/frontend/core/src/modules/workspace-indexer-embedding/entities/embedding.ts index 2c4f31841c..de99bb3faa 100644 --- a/packages/frontend/core/src/modules/workspace-indexer-embedding/entities/embedding.ts +++ b/packages/frontend/core/src/modules/workspace-indexer-embedding/entities/embedding.ts @@ -24,7 +24,6 @@ import { import { COUNT_PER_PAGE } from '../constants'; import type { EmbeddingStore } from '../stores/embedding'; import type { - AttachmentFile, IgnoredDoc, LocalAttachmentFile, PersistedAttachmentFile, @@ -55,7 +54,7 @@ interface EmbeddingProgress { } export class Embedding extends Entity { - enabled$ = new LiveData(false); + enabled$ = new LiveData(null); error$ = new LiveData(null); attachments$ = new LiveData({ edges: [], @@ -66,36 +65,28 @@ export class Embedding extends Entity { totalCount: 0, }); ignoredDocs$ = new LiveData([]); - isEnabledLoading$ = new LiveData(false); - isAttachmentsLoading$ = new LiveData(false); - isIgnoredDocsLoading$ = new LiveData(false); + isEnabledLoading$ = new LiveData(true); + isAttachmentsLoading$ = new LiveData(true); + isIgnoredDocsLoading$ = new LiveData(true); embeddingProgress$ = new LiveData(null); - isEmbeddingProgressLoading$ = new LiveData(false); + isEmbeddingProgressLoading$ = new LiveData(true); private readonly EMBEDDING_PROGRESS_POLL_INTERVAL = 3000; private readonly stopEmbeddingProgress$ = new Subject(); uploadingAttachments$ = new LiveData([]); - mergedAttachments$ = new LiveData([]); constructor( private readonly workspaceService: WorkspaceService, private readonly store: EmbeddingStore ) { super(); - this.getEnabled(); - this.getAttachments({ first: COUNT_PER_PAGE, after: null }); - this.getIgnoredDocs(); - this.getEmbeddingProgress(); - this.uploadingAttachments$.subscribe(() => this.updateMergedAttachments()); - this.attachments$.subscribe(() => this.updateMergedAttachments()); - this.updateMergedAttachments(); } - private updateMergedAttachments() { - const uploading = this.uploadingAttachments$.value; - const uploaded = this.attachments$.value.edges.map(edge => edge.node); - this.mergedAttachments$.next([...uploading, ...uploaded].slice(0, 10)); - } + mergedAttachments$ = LiveData.computed(get => { + const uploading = get(this.uploadingAttachments$); + const uploaded = get(this.attachments$).edges.map(edge => edge.node); + return [...uploading, ...uploaded].slice(0, 10); + }); getEnabled = effect( exhaustMap(() => { diff --git a/packages/frontend/core/src/modules/workspace-indexer-embedding/view/embedding-settings.tsx b/packages/frontend/core/src/modules/workspace-indexer-embedding/view/embedding-settings.tsx index ad308bfd5c..e906110879 100644 --- a/packages/frontend/core/src/modules/workspace-indexer-embedding/view/embedding-settings.tsx +++ b/packages/frontend/core/src/modules/workspace-indexer-embedding/view/embedding-settings.tsx @@ -12,6 +12,7 @@ import { useLiveData, useService } from '@toeverything/infra'; import type React from 'react'; import { useCallback, useEffect } from 'react'; +import { COUNT_PER_PAGE } from '../constants'; import { EmbeddingService } from '../services/embedding'; import { Attachments } from './attachments'; import EmbeddingProgress from './embedding-progress'; @@ -23,9 +24,7 @@ export const EmbeddingSettings: React.FC = () => { const t = useI18n(); const embeddingService = useService(EmbeddingService); const embeddingEnabled = useLiveData(embeddingService.embedding.enabled$); - const { pageInfo, totalCount } = useLiveData( - embeddingService.embedding.attachments$ - ); + const { totalCount } = useLiveData(embeddingService.embedding.attachments$); const attachments = useLiveData( embeddingService.embedding.mergedAttachments$ ); @@ -38,6 +37,9 @@ export const EmbeddingSettings: React.FC = () => { embeddingService.embedding.isIgnoredDocsLoading$ ); const workspaceDialogService = useService(WorkspaceDialogService); + const isEnabledLoading = useLiveData( + embeddingService.embedding.isEnabledLoading$ + ); const handleEmbeddingToggle = useCallback( (checked: boolean) => { @@ -74,10 +76,9 @@ export const EmbeddingSettings: React.FC = () => { (offset: number) => { embeddingService.embedding.getAttachments({ offset, - after: pageInfo.endCursor, }); }, - [embeddingService.embedding, pageInfo.endCursor] + [embeddingService.embedding] ); const handleSelectDoc = useCallback(() => { @@ -113,6 +114,14 @@ export const EmbeddingSettings: React.FC = () => { useEffect(() => { embeddingService.embedding.startEmbeddingProgressPolling(); + embeddingService.embedding.getEnabled(); + embeddingService.embedding.getAttachments({ + first: COUNT_PER_PAGE, + after: null, + }); + embeddingService.embedding.getIgnoredDocs(); + embeddingService.embedding.getEmbeddingProgress(); + return () => { embeddingService.embedding.stopEmbeddingProgressPolling(); }; @@ -139,8 +148,9 @@ export const EmbeddingSettings: React.FC = () => { >