Skip to content

Commit

Permalink
Search page active tab is streaming tab when the ai query param is se…
Browse files Browse the repository at this point in the history
…t and a user is logged in
  • Loading branch information
adamjarling committed Jun 25, 2024
1 parent 508f19a commit 70247b9
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions hooks/useGenerativeAISearchToggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, { useEffect, useState } from "react";
import { DCAPI_ENDPOINT } from "@/lib/constants/endpoints";
import { UserContext } from "@/context/user-context";
import { useRouter } from "next/router";
import { useSearchState } from "@/context/search-context";

const defaultModalState = {
isOpen: false,
Expand All @@ -13,6 +14,8 @@ const aiQueryParam = "ai";

export default function useGenerativeAISearchToggle() {
const router = useRouter();
const { searchDispatch } = useSearchState();

const [dialog, setDialog] = useState(defaultModalState);

const { user } = React.useContext(UserContext);
Expand All @@ -29,6 +32,13 @@ export default function useGenerativeAISearchToggle() {
if (isAiQueryParam) {
setDialog((prevDialog) => ({ ...prevDialog, isOpen: !user?.isLoggedIn }));
}
// Ensure Chat AI active tab = "stream" on search page
if (isChecked) {
searchDispatch({
activeTab: "stream",
type: "updateActiveTab",
});
}
}, [isAiQueryParam, user]);

function goToLocation() {
Expand Down

0 comments on commit 70247b9

Please sign in to comment.