diff --git a/apps/playground/.env.example b/apps/playground/.env.example index ef77c84df..db20c4906 100644 --- a/apps/playground/.env.example +++ b/apps/playground/.env.example @@ -6,4 +6,7 @@ BLOCKFROST_API_KEY_PREPROD= DONATE_ADA_ADDRESS= DONATE_MESHTOKEN_WALLET= -NEXT_PUBLIC_GOOGLE_ANALYTICS= \ No newline at end of file +NEXT_PUBLIC_GOOGLE_ANALYTICS= + +GOOGLE_SEARCH_API= +GOOGLE_SEARCH_CX= \ No newline at end of file diff --git a/apps/playground/src/backend/search.ts b/apps/playground/src/backend/search.ts new file mode 100644 index 000000000..5ea9bc4a0 --- /dev/null +++ b/apps/playground/src/backend/search.ts @@ -0,0 +1,18 @@ +import { post } from "./"; + +export async function searchQuery(query: string) { + const googleSearchResults = await post(`google/search`, { query }); + + const results: any[] = []; + + for (const result of googleSearchResults.items) { + results.push({ + title: result.title, + url: result.link.replace("https://meshjs.dev/", "/"), + displayUrl: result.htmlFormattedUrl, + snippet: result.htmlSnippet, + }); + } + + return results; +} diff --git a/apps/playground/src/components/site/navbar/index.tsx b/apps/playground/src/components/site/navbar/index.tsx index 106ba116d..ee57eede3 100644 --- a/apps/playground/src/components/site/navbar/index.tsx +++ b/apps/playground/src/components/site/navbar/index.tsx @@ -26,6 +26,8 @@ export default function Navbar() { const [showMobileMenu, setShowMobileMenu] = useState(false); const router = useRouter(); + const [query, setQuery] = useState(""); + useEffect(() => { setIsSSR(false); }, []); @@ -38,6 +40,13 @@ export default function Navbar() { setShowMobileMenu(!showMobileMenu); } + function search() { + router.push({ + pathname: "/search", + query: { q: query }, + }); + } + useEffect(() => { function setDarkTheme(bool: boolean) { if (bool) { @@ -75,6 +84,46 @@ export default function Navbar() { {/* right icons start */}
+
+ +
+
+ + + +
+ setQuery(e.target.value)} + onKeyDown={(e) => { + if (e.key === "Enter") { + search(); + } + }} + /> +
+
+ {socials.map((social, i) => { return ( +
+ +
+
+ + + +
+ setQuery(e.target.value)} + onKeyDown={(e) => { + if (e.key === "Enter") { + search(); + } + }} + /> +
+ +