From f992655511b8a67f22e5707556dc2281ef0aa60a Mon Sep 17 00:00:00 2001 From: Logan Yang Date: Sat, 16 Nov 2024 16:08:52 -0800 Subject: [PATCH] Fix isIndexLoaded (#825) --- src/VectorStoreManager.ts | 3 ++- src/components/Chat.tsx | 2 +- src/components/ChatComponents/ChatControls.tsx | 11 +++++++++-- src/components/ChatComponents/ChatInput.tsx | 6 +++--- src/constants.ts | 2 +- src/settings/components/QASettings.tsx | 2 +- 6 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/VectorStoreManager.ts b/src/VectorStoreManager.ts index 95d22104..d9acd039 100644 --- a/src/VectorStoreManager.ts +++ b/src/VectorStoreManager.ts @@ -149,7 +149,8 @@ class VectorStoreManager { } } - public getIsIndexLoaded(): boolean { + public async getIsIndexLoaded(): Promise { + await this.waitForInitialization(); return this.isIndexLoaded; } diff --git a/src/components/Chat.tsx b/src/components/Chat.tsx index 4f59d31d..cfb368ab 100644 --- a/src/components/Chat.tsx +++ b/src/components/Chat.tsx @@ -574,7 +574,7 @@ ${chatContent}`; debug={debug} addMessage={addMessage} vault={app.vault} - isIndexLoaded={plugin.vectorStoreManager.getIsIndexLoaded()} + isIndexLoadedPromise={plugin.vectorStoreManager.getIsIndexLoaded()} /> diff --git a/src/components/ChatComponents/ChatControls.tsx b/src/components/ChatComponents/ChatControls.tsx index feccb464..b5e2f590 100644 --- a/src/components/ChatComponents/ChatControls.tsx +++ b/src/components/ChatComponents/ChatControls.tsx @@ -20,8 +20,8 @@ interface ChatControlsProps { onRefreshVaultContext: () => void; settings: CopilotSettings; vault_qa_strategy: string; + isIndexLoadedPromise: Promise; debug?: boolean; - isIndexLoaded: boolean; } const ChatControls: React.FC = ({ @@ -33,9 +33,16 @@ const ChatControls: React.FC = ({ settings, vault_qa_strategy, debug, - isIndexLoaded, + isIndexLoadedPromise, }) => { const [selectedChain, setSelectedChain] = useState(currentChain); + const [isIndexLoaded, setIsIndexLoaded] = useState(false); + + useEffect(() => { + isIndexLoadedPromise.then((loaded) => { + setIsIndexLoaded(loaded); + }); + }, [isIndexLoadedPromise]); const handleChainChange = async ({ value }: { value: string }) => { const newChain = stringToChainType(value); diff --git a/src/components/ChatComponents/ChatInput.tsx b/src/components/ChatComponents/ChatInput.tsx index cb9e8df4..17ee634f 100644 --- a/src/components/ChatComponents/ChatInput.tsx +++ b/src/components/ChatComponents/ChatInput.tsx @@ -31,7 +31,7 @@ interface ChatInputProps { addMessage: (message: ChatMessage) => void; vault: Vault; vault_qa_strategy: string; - isIndexLoaded: boolean; + isIndexLoadedPromise: Promise; debug?: boolean; } @@ -57,7 +57,7 @@ const ChatInput: React.FC = ({ addMessage, vault, vault_qa_strategy, - isIndexLoaded, + isIndexLoadedPromise, debug, }) => { const [shouldFocus, setShouldFocus] = useState(false); @@ -206,7 +206,7 @@ const ChatInput: React.FC = ({ onRefreshVaultContext={onRefreshVaultContext} settings={settings} vault_qa_strategy={vault_qa_strategy} - isIndexLoaded={isIndexLoaded} + isIndexLoadedPromise={isIndexLoadedPromise} debug={debug} /> diff --git a/src/constants.ts b/src/constants.ts index e6443389..b30c0408 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -243,7 +243,7 @@ export const DEFAULT_SETTINGS: CopilotSettings = { activeModels: BUILTIN_CHAT_MODELS, activeEmbeddingModels: BUILTIN_EMBEDDING_MODELS, embeddingRequestsPerSecond: 10, - disableIndexOnMobile: false, + disableIndexOnMobile: true, enabledCommands: { [COMMAND_IDS.FIX_GRAMMAR]: { enabled: true, diff --git a/src/settings/components/QASettings.tsx b/src/settings/components/QASettings.tsx index 4621df03..325fd068 100644 --- a/src/settings/components/QASettings.tsx +++ b/src/settings/components/QASettings.tsx @@ -151,7 +151,7 @@ const QASettings: React.FC = ({ />