diff --git a/.env.development b/.env.development index 62beb370..57853ead 100644 --- a/.env.development +++ b/.env.development @@ -9,8 +9,6 @@ #NEXT_PUBLIC_APP_ID=1:166652277588:web:e08b9e19916451e14dcec1 #NEXT_PUBLIC_APP_MEASUREMENT_ID=G-7ZNKM9VFN2 -# TDO - NEXT_PUBLIC_API_URL=http://localhost:3001 NEXT_PUBLIC_FRONTEND_URL=http://localhost:3000 NEXT_PUBLIC_APP_API_KEY=AIzaSyAHz1s-UuNhlZ6aKvqwzmzzidzWxBKw9hw diff --git a/src/components/nav/SearchModal.jsx b/src/components/nav/SearchModal.jsx index 81f82d88..643b1512 100644 --- a/src/components/nav/SearchModal.jsx +++ b/src/components/nav/SearchModal.jsx @@ -1,8 +1,31 @@ import React from 'react'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faSearch, faBug, faLock, faUserSecret, faNetworkWired, faBrain, faTerminal } from '@fortawesome/free-solid-svg-icons'; +import { useState, useEffect } from 'react'; +import request from '@/utils/request'; +import {useRouter} from 'next/router'; const SearchModal = ({ showSearchModal, setShowSearchModal }) => { + const [search, setSearch] = useState(''); + const [results, setResults] = useState(null); + const router = useRouter(); + const debouncedSearchTerm = useDebounce(search, 100); // 300ms delay + + useEffect(() => { + if (debouncedSearchTerm) { + const endpoint = process.env.NEXT_PUBLIC_API_URL; + const url = `${endpoint}/search/${debouncedSearchTerm}`; + console.log(url); + request(url, "GET", null).then((res) => { + setResults(res.results); + console.log(res); + }).catch((err) => { console.log(err); }); + } + }, [debouncedSearchTerm]); + + const routeToChallenge = (id) => router.push("/challenges/"+id); + const routeToUser = (username) => router.push("/users/"+username); + return ( <> {showSearchModal && ( @@ -19,8 +42,31 @@ const SearchModal = ({ showSearchModal, setShowSearchModal }) => {