Skip to content

68/add google env to search #2503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ ALGOLIA_WRITE_API_KEY=
ALGOLIA_INDEX_NAME=docs-test
PUBLIC_ALGOLIA_SEARCH_APP_ID=
PUBLIC_ALGOLIA_SEARCH_PUBLIC_API_KEY=

# Google AI Search
PUBLIC_GOOGLE_PROJECT_ID=
PUBLIC_GOOGLE_APP_ID=
PUBLIC_GOOGLE_ACCESS_TOKEN=
3 changes: 3 additions & 0 deletions src/components/Header/Header.astro
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ const path = Astro.url.pathname
const algoliaVars = {
algoliaAppId: import.meta.env.PUBLIC_ALGOLIA_SEARCH_APP_ID || "",
algoliaPublicApiKey: import.meta.env.PUBLIC_ALGOLIA_SEARCH_PUBLIC_API_KEY || "",
googleProjectId: import.meta.env.PUBLIC_GOOGLE_PROJECT_ID || "",
googleAppId: import.meta.env.PUBLIC_GOOGLE_APP_ID || "",
googleAccessToken: import.meta.env.PUBLIC_GOOGLE_ACCESS_TOKEN || "",
}
---

Expand Down
8 changes: 8 additions & 0 deletions src/components/Header/Nav/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,11 @@ export type AppConfig = {
productsNav: ProductsNav
subProductsNav?: SubProductsNav
} & LinksConfig

export type AlgoliaVars = {
algoliaAppId: string
algoliaPublicApiKey: string
googleProjectId: string
googleAppId: string
googleAccessToken: string
}
22 changes: 17 additions & 5 deletions src/components/Header/NavBar.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React from "react"
import React, { lazy, Suspense, useEffect, useState } from "react"
import { NavBar as Nav } from "./Nav/index.ts"
import { Search } from "./aiSearch/Search.tsx"
import { useNavBar } from "./useNavBar/useNavBar.ts"
import styles from "./scroll.module.css"
import { ProductsNav, SubProductsNav } from "./Nav/config.tsx"
import { AlgoliaVars, ProductsNav, SubProductsNav } from "./Nav/config.tsx"

const LazySearch = lazy(() => import("./aiSearch/Search.tsx"))

export const NavBar = ({
productsNav,
Expand All @@ -16,9 +17,10 @@ export const NavBar = ({
subProductsNav: SubProductsNav
path: string
showSearch?: boolean
algoliaVars: { algoliaAppId: string; algoliaPublicApiKey: string }
algoliaVars: AlgoliaVars
}) => {
const navRef = React.useRef(null)
const [isClient, setIsClient] = useState(false)

const { setNavBarInfo } = useNavBar()

Expand Down Expand Up @@ -54,13 +56,23 @@ export const NavBar = ({
}
}

useEffect(() => {
setIsClient(true)
}, [])

return (
<span ref={navRef}>
<Nav
productsNav={productsNav}
subProductsNav={subProductsNav}
path={path}
searchTrigger={showSearch ? <Search algoliaVars={algoliaVars} /> : undefined}
searchTrigger={
isClient && showSearch ? (
<Suspense fallback={null}>
<LazySearch algoliaVars={algoliaVars} />
</Suspense>
) : undefined
}
onHideChange={onHideChange}
doubleNavbar={doubleNavbar()}
/>
Expand Down
12 changes: 9 additions & 3 deletions src/components/Header/aiSearch/Search.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { SearchButton } from "chainlink-algolia-search"
import "chainlink-algolia-search/dist/index.css"
import { AlgoliaVars } from "../Nav/config.tsx"

export const Search = ({
algoliaVars: { algoliaAppId, algoliaPublicApiKey },
const Search = ({
algoliaVars: { algoliaAppId, algoliaPublicApiKey, googleProjectId, googleAppId, googleAccessToken },
}: {
algoliaVars: { algoliaAppId: string; algoliaPublicApiKey: string }
algoliaVars: AlgoliaVars
}) => {
return (
<SearchButton
Expand All @@ -18,6 +19,11 @@ export const Search = ({
},
{ url: "https://dev.chain.link/tools", imgSrc: "/images/algolia/tools.png", label: "Tools" },
]}
googleProjectId={googleProjectId}
googleAppId={googleAppId}
googleAccessToken={googleAccessToken}
/>
)
}

export default Search
Loading