diff --git a/components/Search/Search.styled.ts b/components/Search/Search.styled.ts index a7f5e0c6..ef547318 100644 --- a/components/Search/Search.styled.ts +++ b/components/Search/Search.styled.ts @@ -100,6 +100,26 @@ const Clear = styled("button", { }, }); +const GenerativeAICheckbox = styled("div", { + color: "$black50", + fontSize: "$gr2", + display: "flex", + alignItems: "center", + + "& label": { + cursor: "pointer", + width: "120px", + }, + + "& svg": { + position: "relative", + padding: "$gr0", + height: "$gr3", + width: "$gr3", + fill: "$black50", + }, +}); + const ResultsMessage = styled("span", { color: "$black50", padding: "0 $gr4 $gr4", @@ -144,6 +164,7 @@ const ResultsWrapper = styled("div", { export { Button, Clear, + GenerativeAICheckbox, Input, NoResultsMessage, ResultsMessage, diff --git a/components/Search/Search.tsx b/components/Search/Search.tsx index 186f5566..22eed7a5 100644 --- a/components/Search/Search.tsx +++ b/components/Search/Search.tsx @@ -1,7 +1,14 @@ -import { Button, Clear, Input, SearchStyled } from "./Search.styled"; +import { + Button, + Clear, + GenerativeAICheckbox, + Input, + SearchStyled, +} from "./Search.styled"; import { IconArrowForward, IconClear, + IconInfo, IconSearch, } from "@/components/Shared/SVG/Icons"; import React, { @@ -14,7 +21,9 @@ import React, { } from "react"; import { ALL_FACETS } from "@/lib/constants/facets-model"; +import { DCAPI_ENDPOINT } from "@/lib/constants/endpoints"; import GenerativeAIDialog from "@/components/Shared/Dialog"; +import { Gothic_A1 } from "next/font/google"; import { UserContext } from "@/context/user-context"; import useQueryParams from "@/hooks/useQueryParams"; import { useRouter } from "next/router"; @@ -44,6 +53,9 @@ const Search: React.FC = ({ isSearchActive }) => { isOpen: false, title: "Generative AI Dialog", }); + const [genAICheckBox, setGenAICheckBox] = useState( + searchState.isGenerativeAI + ); const handleSubmit = (e: SyntheticEvent) => { e.preventDefault(); @@ -86,11 +98,16 @@ const Search: React.FC = ({ isSearchActive }) => { }; const handleGenerativeAIChange = (e: ChangeEvent) => { - setModalGenerativeUI({ ...modalGenerativeAI, isOpen: e.target.checked }); - searchDispatch({ - isGenerativeAI: e.target.checked, - type: "updateGenerativeAI", - }); + if (!user?.isLoggedIn) { + setModalGenerativeUI({ ...modalGenerativeAI, isOpen: e.target.checked }); + } + + if (user?.isLoggedIn) { + searchDispatch({ + isGenerativeAI: e.target.checked, + type: "updateGenerativeAI", + }); + } }; useEffect(() => { @@ -109,6 +126,21 @@ const Search: React.FC = ({ isSearchActive }) => { !searchFocus && !searchValue ? isSearchActive(false) : isSearchActive(true); }, [searchFocus, searchValue, isSearchActive]); + useEffect(() => { + setGenAICheckBox(searchState.isGenerativeAI); + }, [searchState.isGenerativeAI]); + + // TODO: This needs to accept more than one query param when + // directing to NU SSO. We need the additional query param + // to know that user came wanting to use Generative AI + function goToLocation() { + const currentUrl = `${window.location.origin}${router.asPath}`; + const url = new URL(currentUrl); + url.searchParams.set("ai", "true"); + console.log("url.toString()", url.toString()); + return url.toString(); + } + return ( <> = ({ isSearchActive }) => { )} - + + + + @@ -151,8 +187,12 @@ const Search: React.FC = ({ isSearchActive }) => { setModalGenerativeUI({ ...modalGenerativeAI, isOpen: false }) } > -

You must log in to proceed

- +

+ + Click here + {" "} + to login +

diff --git a/pages/search.tsx b/pages/search.tsx index cfbf60d0..954deaf6 100644 --- a/pages/search.tsx +++ b/pages/search.tsx @@ -20,6 +20,7 @@ import { NextPage } from "next"; import { PRODUCTION_URL } from "@/lib/constants/endpoints"; import PaginationAltCounts from "@/components/Search/PaginationAltCounts"; import SearchSimilar from "@/components/Search/Similar"; +import { UserContext } from "@/context/user-context"; import { apiPostRequest } from "@/lib/dc-api"; import axios from "axios"; import { buildDataLayer } from "@/lib/ga/data-layer"; @@ -29,6 +30,7 @@ import { loadDefaultStructuredData } from "@/lib/json-ld"; import { parseUrlFacets } from "@/lib/utils/facet-helpers"; import { pluralize } from "@/lib/utils/count-helpers"; import { useRouter } from "next/router"; +import { useSearchState } from "@/context/search-context"; type RequestState = { data: ApiSearchResponse | null; @@ -39,6 +41,12 @@ type RequestState = { const SearchPage: NextPage = () => { const size = 40; const router = useRouter(); + + const { searchState } = useSearchState(); + const { user } = React.useContext(UserContext); + const showChatResponse = user?.isLoggedIn && searchState.isGenerativeAI; + console.log("showChatResponse", showChatResponse); + const [requestState, setRequestState] = useState({ data: null, error: "", @@ -182,7 +190,7 @@ const SearchPage: NextPage = () => { /> )} - + {showChatResponse && }