From d58e32b1d931151bff7a3d9b2192a51f0c2f18e2 Mon Sep 17 00:00:00 2001
From: Pas <74743263+Pasithea0@users.noreply.github.com>
Date: Tue, 25 Feb 2025 12:52:30 -0700
Subject: [PATCH] Add lazy loading to discover
---
src/pages/discover/Discover.tsx | 36 +---
.../discover/components/LazyMediaCarousel.tsx | 78 ++++++++
.../discover/components/LazyTabContent.tsx | 29 +++
src/pages/discover/discoverContent.tsx | 177 ++++++++++++------
.../hooks/useIntersectionObserver.tsx | 43 +++++
src/pages/discover/hooks/useTMDBData.tsx | 70 ++++++-
6 files changed, 332 insertions(+), 101 deletions(-)
create mode 100644 src/pages/discover/components/LazyMediaCarousel.tsx
create mode 100644 src/pages/discover/components/LazyTabContent.tsx
create mode 100644 src/pages/discover/hooks/useIntersectionObserver.tsx
diff --git a/src/pages/discover/Discover.tsx b/src/pages/discover/Discover.tsx
index 85f97c97..40bc87ac 100644
--- a/src/pages/discover/Discover.tsx
+++ b/src/pages/discover/Discover.tsx
@@ -1,8 +1,6 @@
-import React, { useEffect, useState } from "react";
import { Helmet } from "react-helmet-async";
import { useTranslation } from "react-i18next";
-import { Loading } from "@/components/layout/Loading";
import DiscoverContent from "@/pages/discover/discoverContent";
import { SubPageLayout } from "../layouts/SubPageLayout";
@@ -11,25 +9,6 @@ import { PageTitle } from "../parts/util/PageTitle";
export function Discover() {
const { t } = useTranslation();
- // Stupid method to "simulate" loading so the user understands this takes a white to load.
- // TO DO: Lazy load all the media cards 💀
-
- // State to track whether content is loading or loaded
- const [loading, setLoading] = useState(true);
-
- // Simulate loading media cards
- useEffect(() => {
- const simulateLoading = async () => {
- // Simulate a loading time with setTimeout or fetch data here
- await new Promise((resolve) => {
- setTimeout(resolve, 2000);
- }); // Simulate 2s loading time
- setLoading(false); // After loading, set loading to false
- };
-
- simulateLoading();
- }, []);
-
return (
- Fetching the latest movies & TV shows... -
-- Please wait while we load the best recommendations for you. -
-