Skip to content

Commit 0402875

Browse files
committed
Use the aiFlags api to know when to enable the ai chat box.
Signed-off-by: Hiram Chirino <hiram@hiramchirino.com>
1 parent bc64c03 commit 0402875

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

client/src/app/components/ai-assistant.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { Input } from "@/components/ui/input";
1111
import { ScrollArea } from "@/components/ui/scroll-area";
1212
import { MessageCircle, Send, X } from "lucide-react";
1313
import { ChatMessage, ChatState } from "../client";
14-
import { useCompletionMutation } from "../queries/ai";
14+
import { useCompletionMutation, useFetchAiFlagsQuery } from "../queries/ai";
1515
import ReactMarkdown from "react-markdown";
1616

1717
interface Conversation {
@@ -35,8 +35,8 @@ export function AIAssistantProvider({
3535
}: {
3636
children: React.ReactNode;
3737
}) {
38-
// todo: querying the API to see if the feature is enabled.
39-
const [isEnabled] = useState(true);
38+
const aiFlags = useFetchAiFlagsQuery();
39+
const isEnabled = aiFlags.data?.completions || false;
4040

4141
const [isOpen, setIsOpen] = useState(false);
4242
const [chatState, setChatState] = useState({ messages: [] } as ChatState);

client/src/app/queries/ai.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { useMutation } from "@tanstack/react-query";
1+
import { useMutation, useQuery } from "@tanstack/react-query";
22
import { AxiosError } from "axios";
33
import { client } from "@app/axios-config/apiInit";
4-
import { ChatState, completions } from "@app/client";
4+
import { aiFlags, ChatState, completions } from "@app/client";
5+
import { dataOf } from "./dataOf";
56

67
export const useCompletionMutation = (
78
onError?: (err: AxiosError, next: ChatState) => void,
@@ -16,3 +17,13 @@ export const useCompletionMutation = (
1617
onError,
1718
});
1819
};
20+
21+
export const useFetchAiFlagsQuery = () => {
22+
return useQuery({
23+
queryKey: ["ai/flags"],
24+
queryFn: () => {
25+
return dataOf(aiFlags({ client }));
26+
},
27+
refetchInterval: false,
28+
});
29+
};

0 commit comments

Comments
 (0)