From b5908d95cb93acac0de07def74b1042fc2761d81 Mon Sep 17 00:00:00 2001 From: cp-dharti-r Date: Fri, 26 Apr 2024 18:21:12 +0530 Subject: [PATCH] Refactor layout file and use ref --- .../components/Layout/{layout.tsx => root.tsx} | 0 ...{layoutWithoutFooter.tsx => withoutFooter.tsx} | 0 website/pages/about/index.tsx | 2 +- website/pages/category/[category].tsx | 2 +- website/pages/index.tsx | 2 +- .../restaurants/[restaurant]/cuisines/index.tsx | 2 +- website/pages/restaurants/[restaurant]/index.tsx | 15 ++++++--------- .../restaurants/[restaurant]/menus/[menu].tsx | 6 +++--- 8 files changed, 13 insertions(+), 16 deletions(-) rename website/components/Layout/{layout.tsx => root.tsx} (100%) rename website/components/Layout/{layoutWithoutFooter.tsx => withoutFooter.tsx} (100%) diff --git a/website/components/Layout/layout.tsx b/website/components/Layout/root.tsx similarity index 100% rename from website/components/Layout/layout.tsx rename to website/components/Layout/root.tsx diff --git a/website/components/Layout/layoutWithoutFooter.tsx b/website/components/Layout/withoutFooter.tsx similarity index 100% rename from website/components/Layout/layoutWithoutFooter.tsx rename to website/components/Layout/withoutFooter.tsx diff --git a/website/pages/about/index.tsx b/website/pages/about/index.tsx index 47aa59b..fb11498 100644 --- a/website/pages/about/index.tsx +++ b/website/pages/about/index.tsx @@ -1,6 +1,6 @@ "use client"; -import RootLayout from "@/components/Layout/layout"; +import RootLayout from "@/components/Layout/root"; import withScrollRestoration from "@/components/withScrollRestoration"; import Image from "next/image"; import Link from "next/link"; diff --git a/website/pages/category/[category].tsx b/website/pages/category/[category].tsx index a0da77f..f36d209 100644 --- a/website/pages/category/[category].tsx +++ b/website/pages/category/[category].tsx @@ -7,7 +7,7 @@ import { useEffect, useState } from "react"; import { CategoryData, RestaurantData } from "@/types/category-by-id"; import { useRouter } from "next/router"; import Restaurant from "./restaurant"; -import RootLayout from "../../components/Layout/layout"; +import RootLayout from "../../components/Layout/root"; import NotFound from "@/components/PageNotFound"; const Category = () => { diff --git a/website/pages/index.tsx b/website/pages/index.tsx index 9d4f525..3971f91 100644 --- a/website/pages/index.tsx +++ b/website/pages/index.tsx @@ -5,7 +5,7 @@ import Hero from "@/components/Hero"; import ItemCard from "@/components/ItemCard"; import YouMayLike from "@/components/YouMayLike"; import { Inter } from "@next/font/google"; -import RootLayout from "../components/Layout/layout"; +import RootLayout from "../components/Layout/root"; import withScrollRestoration from "@/components/withScrollRestoration"; const inter = Inter({ subsets: ["latin"] }); diff --git a/website/pages/restaurants/[restaurant]/cuisines/index.tsx b/website/pages/restaurants/[restaurant]/cuisines/index.tsx index bcc5115..8d67c66 100644 --- a/website/pages/restaurants/[restaurant]/cuisines/index.tsx +++ b/website/pages/restaurants/[restaurant]/cuisines/index.tsx @@ -14,7 +14,7 @@ import SectionTitle from "@/components/Common/SectionTitle"; import "swiper/css"; import "swiper/css/effect-fade"; import { useRouter } from "next/router"; -import RootLayout from "@/components/Layout/layout"; +import RootLayout from "@/components/Layout/root"; import NoDataFound from "@/components/NoDataFound"; const CuisineRestaurant = () => { diff --git a/website/pages/restaurants/[restaurant]/index.tsx b/website/pages/restaurants/[restaurant]/index.tsx index b5c5c4c..89829c6 100644 --- a/website/pages/restaurants/[restaurant]/index.tsx +++ b/website/pages/restaurants/[restaurant]/index.tsx @@ -3,7 +3,7 @@ import supabase from "@/utils/supabase"; import Image from "next/image"; -import React, { useEffect, useState } from "react"; +import React, { useEffect, useRef, useState } from "react"; import { Autoplay, EffectFade } from "swiper/modules"; import { Swiper, SwiperSlide } from "swiper/react"; @@ -12,7 +12,7 @@ import "swiper/css"; import "swiper/css/effect-fade"; import { InView } from "react-intersection-observer"; import { useRouter } from "next/router"; -import RootLayout from "@/components/Layout/layout"; +import RootLayout from "@/components/Layout/root"; import NotFound from "@/components/PageNotFound"; import VideoPlayer from "@/components/VideoPlayer"; import MenuDish from "@/components/SkeletonPlaceholders/MenuDish"; @@ -97,13 +97,12 @@ const RestaurantMenu = () => { fetchDishes(); }, [restaurant, router, suffix]); + const resizableRestaurantDivRef = useRef(null);; const [scrolled, setScrolled] = useState(false); useEffect(() => { const handleScroll = () => { - const resizableRestaurantDiv = document.getElementById( - "resizableRestaurantDiv" - ); + const resizableRestaurantDiv = resizableRestaurantDivRef.current; if (!resizableRestaurantDiv || scrolled) return; if (window.scrollY > 0) { @@ -113,9 +112,7 @@ const RestaurantMenu = () => { }; const handleScrollUp = () => { - const resizableRestaurantDiv = document.getElementById( - "resizableRestaurantDiv" - ); + const resizableRestaurantDiv = resizableRestaurantDivRef.current; if (!resizableRestaurantDiv || !scrolled) return; if (window.scrollY === 0) { @@ -308,7 +305,7 @@ const RestaurantMenu = () => {
diff --git a/website/pages/restaurants/[restaurant]/menus/[menu].tsx b/website/pages/restaurants/[restaurant]/menus/[menu].tsx index 64ca0a4..6197fd8 100644 --- a/website/pages/restaurants/[restaurant]/menus/[menu].tsx +++ b/website/pages/restaurants/[restaurant]/menus/[menu].tsx @@ -14,7 +14,7 @@ import { useRouter } from "next/router"; import NotFound from "@/components/PageNotFound"; import VideoPlayer from "@/components/VideoPlayer"; import MenuDish from "@/components/SkeletonPlaceholders/MenuDish"; -import LayoutWithoutFooter from "@/components/Layout/layoutWithoutFooter"; +import LayoutWithoutFooter from "@/components/Layout/withoutFooter"; const RestaurantMenu = () => { const router = useRouter(); @@ -34,8 +34,8 @@ const RestaurantMenu = () => { const { data: menusData, error } = await supabase .from("menus") .select("id, name") - .eq("restaurant_id", atob(suffix!)); - // .eq("id", atob(menuSuffix!)); + .eq("restaurant_id", atob(suffix!)) + .eq("id", atob(menuSuffix!)); if (error) return error;