Skip to content

Commit

Permalink
Refactor layout file and use ref
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-dharti-r committed Apr 26, 2024
1 parent 9bba4f2 commit b5908d9
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 16 deletions.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion website/pages/about/index.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
2 changes: 1 addition & 1 deletion website/pages/category/[category].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down
2 changes: 1 addition & 1 deletion website/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"] });
Expand Down
2 changes: 1 addition & 1 deletion website/pages/restaurants/[restaurant]/cuisines/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down
15 changes: 6 additions & 9 deletions website/pages/restaurants/[restaurant]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";
Expand Down Expand Up @@ -97,13 +97,12 @@ const RestaurantMenu = () => {
fetchDishes();
}, [restaurant, router, suffix]);

const resizableRestaurantDivRef = useRef<HTMLDivElement>(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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -308,7 +305,7 @@ const RestaurantMenu = () => {
<section className="sm:hidden">
<div className="scrollbar-hidden mb-10 animated-fade">
<div
id="resizableRestaurantDiv"
ref={resizableRestaurantDivRef}
className="smooth-resize h-screen relative capitalize mb-10"
>
<div className="h-full w-full">
Expand Down
6 changes: 3 additions & 3 deletions website/pages/restaurants/[restaurant]/menus/[menu].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;

Expand Down

0 comments on commit b5908d9

Please sign in to comment.