diff --git a/src/components/Search.tsx b/src/components/Search.tsx new file mode 100644 index 0000000..b7cb990 --- /dev/null +++ b/src/components/Search.tsx @@ -0,0 +1,66 @@ +import { useState } from "react"; + +import Button from "../components/Button"; + +const Search = () => { + const [searchTerm, setSearchTerm] = useState(""); + const [isSearching, setIsSearching] = useState(false); + const [error, setError] = useState(""); + + const handleSubmit = async (event: React.FormEvent) => { + event.preventDefault(); + if (!searchTerm) { + setError("No search term entered"); + setTimeout(() => { + setError(""); + }, 3000); + return; + } + + setIsSearching(true); + + // const res = await searchTasks(searchTerm); + // console.log("res search: ", res); + // if (res.length === 0) { + // setIsSearching(false); + // setError("No task found"); + // setTimeout(() => { + // setSearchTerm(""); + // setError(""); + // }, 3000); + // return; + // } + setIsSearching(false); + }; + return ( +
+
+ setSearchTerm(e.target.value)} + className={`bg-inherit w-5/6 border rounded-md p-2 focus:outline-none focus:ring-1 ${ + error + ? "border-red-500 dark:border-red-300 focus:ring-red-500 invalid:focus:ring-red-600" + : "focus:ring-slate-900" + }`} + /> +
+ ); +}; + +export default Search; diff --git a/src/pages/unsplash-exp/index.astro b/src/pages/unsplash-exp/index.astro index 830f51a..259570e 100644 --- a/src/pages/unsplash-exp/index.astro +++ b/src/pages/unsplash-exp/index.astro @@ -3,6 +3,7 @@ import StarlightPage from "@astrojs/starlight/components/StarlightPage.astro"; import { Image } from "astro:assets"; import Card from "../../components/Card.astro"; import Button from "../../components/Button"; +import Search from "../../components/Search"; import { BtnActions } from "../../components/Button"; import { type UnsplashPhoto } from "../../models/unsplash"; @@ -25,6 +26,7 @@ console.log(photoList); }} >
+
{ photoList.map((photo: UnsplashPhoto) => (