From 2f333479353864e9a5965459296bf8288592f1db Mon Sep 17 00:00:00 2001 From: real-zephex Date: Thu, 21 Mar 2024 13:15:44 +0530 Subject: fixes: minor performance improvements --- src/app/search/page.jsx | 61 +++++++++++++++++-------------------------------- 1 file changed, 21 insertions(+), 40 deletions(-) (limited to 'src/app/search/page.jsx') diff --git a/src/app/search/page.jsx b/src/app/search/page.jsx index 00309f6..75f09bd 100644 --- a/src/app/search/page.jsx +++ b/src/app/search/page.jsx @@ -3,25 +3,23 @@ import "./search.css"; import { FaSearch } from "react-icons/fa"; // Import the search icon from react-icons library import { useState } from "react"; -import Image from "next/image"; -import Link from "next/link"; -import testFunction from "./api/fetchInfo"; +import Results from "./components/fetchInfo"; +import fetchedInfo from "./components/fetchedInfo"; export default function Input() { const [searchedAnime, setSearchedAnime] = useState(null); const [loading, setLoading] = useState(null); - const [search1, setSearch] = useState(null); + const [info, setInfo] = useState(null); const handleKeyPress = async (event) => { if ( (event.code === "Enter" || event.key === "Enter" || event.code === 13) && - searchedAnime != "" + searchedAnime !== "" ) { setLoading(true); - let x = await testFunction(searchedAnime); - setSearch(x); + setInfo(await fetchedInfo(await Results(searchedAnime))); setLoading(false); } else if ( (event.code === "Enter" || @@ -39,9 +37,11 @@ export default function Input() {
- setSearchedAnime(event.target.value) - } + onChange={(event) => { + if (event.target.value.trim() !== "") { + setSearchedAnime(event.target.value); + } + }} onKeyDown={(event) => handleKeyPress(event)} placeholder="Enter anime title" > @@ -49,38 +49,19 @@ export default function Input() {
{loading && ( -

- Please wait while we crunch all the data for you. +

+ Please wait while we crunch all the data for you

)} -
- {search1 ? ( - search1.results && search1.results.length > 0 ? ( - search1.results.map((item, index) => ( - -
-

{item.title}

- Drama Poster -
- - )) - ) : ( -
-

No results found

-
- ) - ) : null} -
+ + {info} ); } -- cgit v1.2.3