From 6efd15397fd8ed5d3520494e2450a9b15b1cf42f Mon Sep 17 00:00:00 2001 From: real-zephex Date: Thu, 11 Apr 2024 02:45:11 +0530 Subject: tried to leverage caching of next js: trending and recent animes info are now cached along with all the animes when you search for one --- src/app/anime/recent/page.jsx | 4 +++- src/app/anime/search/components/fetchInfo.js | 2 +- src/app/anime/search/components/fetchedInfo.js | 6 ++++-- src/app/anime/search/search.module.css | 10 +++++++--- src/app/anime/top-airing/page.jsx | 5 +++-- src/app/anime/videoLinkfetcher.js | 14 ++++++++++++++ 6 files changed, 32 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/app/anime/recent/page.jsx b/src/app/anime/recent/page.jsx index b197899..645df11 100644 --- a/src/app/anime/recent/page.jsx +++ b/src/app/anime/recent/page.jsx @@ -1,9 +1,11 @@ import Image from "next/image"; import Link from "next/link"; import styles from "./recent.module.css"; +import { preFetchAnimeInfo } from "../videoLinkfetcher"; export default async function Releases() { const data = await fetchRecentEpisodes(); + preFetchAnimeInfo(data); return (
@@ -21,7 +23,7 @@ export default async function Releases() { >
{data ? ( @@ -16,10 +18,10 @@ export default async function fetchedInfo(data) {

{item.title}

Drama Poster
diff --git a/src/app/anime/search/search.module.css b/src/app/anime/search/search.module.css index 28fae6e..74bd7f2 100644 --- a/src/app/anime/search/search.module.css +++ b/src/app/anime/search/search.module.css @@ -37,7 +37,7 @@ } .animeEntry:hover .anime { - opacity: 0.5; + opacity: 0.4; } .animeEntry:hover .anime:hover { @@ -63,13 +63,13 @@ display: flex; justify-content: space-between; align-items: center; - padding: 10px; + padding: 5px; border-style: dotted; border-color: #636363; margin: 10px 10px 0px 0px; border-radius: 10px; border-width: 4px; - transition: opacity 400ms ease-in; + transition: opacity 200ms ease-in; background-color: #353535a6; } @@ -90,4 +90,8 @@ .searchContainer { width: 70%; } + + .anime p { + width: 50dvw; + } } \ No newline at end of file diff --git a/src/app/anime/top-airing/page.jsx b/src/app/anime/top-airing/page.jsx index e385629..2c4fb88 100644 --- a/src/app/anime/top-airing/page.jsx +++ b/src/app/anime/top-airing/page.jsx @@ -1,10 +1,11 @@ import styles from "./trending.module.css"; import Image from "next/image"; import Link from "next/link"; +import { preFetchAnimeInfo } from "../videoLinkfetcher"; export default async function Trending() { const data = await test(); - + preFetchAnimeInfo(data); return (
@@ -21,7 +22,7 @@ export default async function Trending() { >
{ + const link = `https://anime-sensei-api.vercel.app/anime/gogoanime/info/${element.id}`; + await fetch(link, { next: { revalidate: 86400 } }); + }); + + await Promise.all(fetchPromises); + console.log("Anime info pre-fetched successfully!"); + } catch (error) { + console.error("Error occurred while pre-fetching anime info: ", error); + } +} -- cgit v1.2.3