diff options
| author | real-zephex <[email protected]> | 2024-04-12 11:39:57 +0530 |
|---|---|---|
| committer | real-zephex <[email protected]> | 2024-04-12 11:39:57 +0530 |
| commit | f6ecf3a393ba50bb74ce83ad2bc723e2670f7215 (patch) | |
| tree | 676f00108119d29253ffe0b658c62575788199e4 /src/app/kdrama/components | |
| parent | fix: fixed kdrama page and made it available (diff) | |
| download | dramalama-f6ecf3a393ba50bb74ce83ad2bc723e2670f7215.tar.xz dramalama-f6ecf3a393ba50bb74ce83ad2bc723e2670f7215.zip | |
minor fixes
Diffstat (limited to 'src/app/kdrama/components')
| -rw-r--r-- | src/app/kdrama/components/cacher.js | 16 | ||||
| -rw-r--r-- | src/app/kdrama/components/popular.jsx | 2 | ||||
| -rw-r--r-- | src/app/kdrama/components/recent.jsx | 3 | ||||
| -rw-r--r-- | src/app/kdrama/components/search.jsx | 4 |
4 files changed, 22 insertions, 3 deletions
diff --git a/src/app/kdrama/components/cacher.js b/src/app/kdrama/components/cacher.js index 4c787d5..1bb159e 100644 --- a/src/app/kdrama/components/cacher.js +++ b/src/app/kdrama/components/cacher.js @@ -1,7 +1,7 @@ // This function pre-fetches all the video links for a drama in the background "use server"; -export default async function PreFetchVideoLinks(data, dramaId) { +export async function PreFetchVideoLinks(data, dramaId) { try { const fetchPromises = data.map(async (element) => { const link = `https://consumet-jade.vercel.app/movies/dramacool/watch?episodeId=${element.id}&mediaId=${dramaId}`; @@ -14,3 +14,17 @@ export default async function PreFetchVideoLinks(data, dramaId) { console.error("Error occurred while pre-fetching video links:", error); } } + +export async function PreFetchAnimeInfo(data) { + try { + const fetchPromises = data.results.map(async (element) => { + const link = `https://consumet-jade.vercel.app/movies/dramacool/info?id=${element.id}`; + await fetch(link, { next: { revalidate: 86400 } }); + }); + + await Promise.all(fetchPromises); + console.log("Drama info fetched successfully."); + } catch (error) { + console.error("Error occurred while pre-fetching video links:", error); + } +} diff --git a/src/app/kdrama/components/popular.jsx b/src/app/kdrama/components/popular.jsx index 7c29ee2..639ed9f 100644 --- a/src/app/kdrama/components/popular.jsx +++ b/src/app/kdrama/components/popular.jsx @@ -1,9 +1,11 @@ import styles from "../styles/popular.module.css"; import Image from "next/image"; import Link from "next/link"; +import { PreFetchAnimeInfo } from "./cacher"; export default async function PopularDramas() { const popular = await getPopular(); + PreFetchAnimeInfo(popular); return ( <div className={styles.Main}> diff --git a/src/app/kdrama/components/recent.jsx b/src/app/kdrama/components/recent.jsx index 0b6b7f6..e69e32a 100644 --- a/src/app/kdrama/components/recent.jsx +++ b/src/app/kdrama/components/recent.jsx @@ -1,10 +1,11 @@ import styles from "../styles/popular.module.css"; import Image from "next/image"; import Link from "next/link"; +import { PreFetchAnimeInfo } from "./cacher"; export default async function RecentDramas() { const popular = await getPopular(); - + PreFetchAnimeInfo(popular); return ( <div className={styles.Main}> <p className={styles.popDramasText}>Recently Released</p> diff --git a/src/app/kdrama/components/search.jsx b/src/app/kdrama/components/search.jsx index 5444c89..0dac544 100644 --- a/src/app/kdrama/components/search.jsx +++ b/src/app/kdrama/components/search.jsx @@ -6,6 +6,7 @@ import { FaSearch } from "react-icons/fa"; import FetchSearchTitle from "./searchQuery"; import Image from "next/image"; import Link from "next/link"; +import { PreFetchAnimeInfo } from "./cacher"; export default function DramaSearch() { const [title, setTitle] = useState(""); @@ -15,6 +16,7 @@ export default function DramaSearch() { const handleSearch = async (title) => { setLoadingText(true); const data = await FetchSearchTitle(title); + PreFetchAnimeInfo(data); setLoadingText(false); setInfoTitle(data); }; @@ -32,7 +34,7 @@ export default function DramaSearch() { } }} ></input> - </div> + </div> {loadingText && ( <p className={styles.LoadingText}>Wait a moment...</p> |