Skip to content

Commit

Permalink
Fix isIndexLoaded (#825)
Browse files Browse the repository at this point in the history
  • Loading branch information
logancyang authored Nov 17, 2024
1 parent b388dbc commit f992655
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/VectorStoreManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ class VectorStoreManager {
}
}

public getIsIndexLoaded(): boolean {
public async getIsIndexLoaded(): Promise<boolean> {
await this.waitForInitialization();
return this.isIndexLoaded;
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ ${chatContent}`;
debug={debug}
addMessage={addMessage}
vault={app.vault}
isIndexLoaded={plugin.vectorStoreManager.getIsIndexLoaded()}
isIndexLoadedPromise={plugin.vectorStoreManager.getIsIndexLoaded()}
/>
</div>
</div>
Expand Down
11 changes: 9 additions & 2 deletions src/components/ChatComponents/ChatControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ interface ChatControlsProps {
onRefreshVaultContext: () => void;
settings: CopilotSettings;
vault_qa_strategy: string;
isIndexLoadedPromise: Promise<boolean>;
debug?: boolean;
isIndexLoaded: boolean;
}

const ChatControls: React.FC<ChatControlsProps> = ({
Expand All @@ -33,9 +33,16 @@ const ChatControls: React.FC<ChatControlsProps> = ({
settings,
vault_qa_strategy,
debug,
isIndexLoaded,
isIndexLoadedPromise,
}) => {
const [selectedChain, setSelectedChain] = useState<ChainType>(currentChain);
const [isIndexLoaded, setIsIndexLoaded] = useState(false);

useEffect(() => {
isIndexLoadedPromise.then((loaded) => {
setIsIndexLoaded(loaded);
});
}, [isIndexLoadedPromise]);

const handleChainChange = async ({ value }: { value: string }) => {
const newChain = stringToChainType(value);
Expand Down
6 changes: 3 additions & 3 deletions src/components/ChatComponents/ChatInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface ChatInputProps {
addMessage: (message: ChatMessage) => void;
vault: Vault;
vault_qa_strategy: string;
isIndexLoaded: boolean;
isIndexLoadedPromise: Promise<boolean>;
debug?: boolean;
}

Expand All @@ -57,7 +57,7 @@ const ChatInput: React.FC<ChatInputProps> = ({
addMessage,
vault,
vault_qa_strategy,
isIndexLoaded,
isIndexLoadedPromise,
debug,
}) => {
const [shouldFocus, setShouldFocus] = useState(false);
Expand Down Expand Up @@ -206,7 +206,7 @@ const ChatInput: React.FC<ChatInputProps> = ({
onRefreshVaultContext={onRefreshVaultContext}
settings={settings}
vault_qa_strategy={vault_qa_strategy}
isIndexLoaded={isIndexLoaded}
isIndexLoadedPromise={isIndexLoadedPromise}
debug={debug}
/>

Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/settings/components/QASettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ const QASettings: React.FC<QASettingsProps> = ({
/>
<ToggleComponent
name="Disable index loading on mobile"
description="When enabled, vector store index won't be loaded on mobile devices to save resources. Only chat mode will be available. Any existing index from desktop sync will be preserved."
description="When enabled, vector store index won't be loaded on mobile devices to save resources. Only chat mode will be available. Any existing index from desktop sync will be preserved. Uncheck to enable QA modes on mobile."
value={disableIndexOnMobile}
onChange={setDisableIndexOnMobile}
/>
Expand Down

0 comments on commit f992655

Please sign in to comment.