From 0af513da89726c537125d5c1315de5ee08878e6e Mon Sep 17 00:00:00 2001 From: tejaspanchall Date: Thu, 5 Jun 2025 17:56:55 +0530 Subject: [PATCH] updated search on landing page --- .env.example | 3 ++- next.config.js | 9 +++++++-- src/app/page.jsx | 50 ++++++++++++++++++++++++++++++++---------------- src/lib/api.js | 2 +- 4 files changed, 43 insertions(+), 21 deletions(-) diff --git a/.env.example b/.env.example index e979aac..c556dbc 100644 --- a/.env.example +++ b/.env.example @@ -1 +1,2 @@ -ANIWATCH_API = your animwatch-api key \ No newline at end of file +# Your AniWatch API URL - replace with your own API endpoint +ANIWATCH_API=https://your-api-url.com \ No newline at end of file diff --git a/next.config.js b/next.config.js index 54b5db7..539b60d 100644 --- a/next.config.js +++ b/next.config.js @@ -34,14 +34,19 @@ const nextConfig = { }, serverExternalPackages: ['puppeteer-core'], async rewrites() { + // Get the API URL from environment variable or use default + const apiUrl = process.env.ANIWATCH_API; + // Extract the base URL without the /api/v2/hianime path + const baseUrl = apiUrl.replace('/api/v2/hianime', ''); + return [ { source: '/api/v2/hianime/:path*', - destination: 'https://justaniwatchapi.vercel.app/api/v2/hianime/:path*' + destination: `${apiUrl}/:path*` }, { source: '/api/anime/:path*', - destination: 'https://justaniwatchapi.vercel.app/api/v2/hianime/anime/:path*' + destination: `${apiUrl}/anime/:path*` } ] }, diff --git a/src/app/page.jsx b/src/app/page.jsx index 91ecefd..5cffa8d 100644 --- a/src/app/page.jsx +++ b/src/app/page.jsx @@ -30,6 +30,7 @@ export default function LandingPage() { if (searchQuery.trim().length > 2) { try { const suggestions = await fetchSearchSuggestions(searchQuery); + // Update to use the same format as home page search setSearchSuggestions(suggestions || []); setShowSuggestions(true); } catch (error) { @@ -70,14 +71,16 @@ export default function LandingPage() { const handleSearch = (e) => { e.preventDefault(); if (searchQuery.trim()) { - router.push(`/search/${searchQuery}`); + router.push(`/search?q=${encodeURIComponent(searchQuery)}`); setSearchQuery(''); setShowSuggestions(false); } }; - const handleSuggestionClick = (title) => { - router.push(`/search/${title}`); + const handleSuggestionClick = (suggestion) => { + // Updated to handle object-based suggestions + const query = suggestion.title || suggestion; + router.push(`/search?q=${encodeURIComponent(query)}`); setSearchQuery(''); setShowSuggestions(false); }; @@ -184,10 +187,32 @@ export default function LandingPage() { {searchSuggestions.map((suggestion, index) => (
handleSuggestionClick(suggestion)} > - {suggestion} + {suggestion.image && ( +
+ {suggestion.title +
+ )} +
+

{suggestion.title || suggestion}

+ {suggestion.jname && ( +

{suggestion.jname}

+ )} +
+ {suggestion.type && ( + + {suggestion.type} + + )}
))} @@ -259,14 +284,7 @@ export default function LandingPage() { }`} >
- +

JustAnime offers the best user experience for anime streaming with fast loading speeds, a beautiful interface, no intrusive ads, large content library, HD quality, and weekly updates. Our clean design and extensive features set us apart from other platforms.

@@ -277,7 +295,7 @@ export default function LandingPage() { className="w-full flex justify-between items-center p-3 sm:p-4 text-left hover:bg-opacity-90 transition-colors" onClick={() => toggleFAQ(2)} > -

Why should I choose JustAnime?

+

How do I request an anime?

-

- If you want a good and safe place to watch anime online for free, give JustAnime a try, and if you like what we provide, please help us by sharing JustAnime to your friends and do not forget to bookmark our site. -

+

You can request anime by visiting our Discord community or using the contact form. Our team aims to fulfill requests quickly based on availability.

diff --git a/src/lib/api.js b/src/lib/api.js index 7d12b17..1f8be12 100644 --- a/src/lib/api.js +++ b/src/lib/api.js @@ -1,7 +1,7 @@ // Use absolute URL for server components and relative URL for client components const isServer = typeof window === 'undefined'; const API_BASE_URL = isServer - ? "https://justaniwatchapi.vercel.app/api/v2/hianime" // Use absolute URL for server-side + ? process.env.ANIWATCH_API // Use environment variable with fallback : "/api/v2/hianime"; // Use relative URL for client-side // Common headers for all API requests