diff --git a/website/pages/restaurants/[id]/index.tsx b/website/pages/restaurants/[restaurant]/index.tsx
similarity index 77%
rename from website/pages/restaurants/[id]/index.tsx
rename to website/pages/restaurants/[restaurant]/index.tsx
index 1558ff1..d8bb751 100644
--- a/website/pages/restaurants/[id]/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,15 +12,19 @@ import "swiper/css";
import "swiper/css/effect-fade";
import { InView } from "react-intersection-observer";
import { useRouter } from "next/router";
-import RootLayout from "@/pages/layout";
+import RootLayout from "@/components/Layout/root";
import NotFound from "@/components/PageNotFound";
import VideoPlayer from "@/components/VideoPlayer";
import MenuDish from "@/components/SkeletonPlaceholders/MenuDish";
+import Link from "next/link";
+import withScrollRestoration from "@/components/withScrollRestoration";
const RestaurantMenu = () => {
const router = useRouter();
- const { id } = router.query;
- const suffix = id?.toString().substring(id?.lastIndexOf("-") + 1);
+ const { restaurant } = router.query;
+ const suffix = restaurant
+ ?.toString()
+ .substring(restaurant?.lastIndexOf("-") + 1);
const [isRestaurantLoading, setIsRestaurantLoading] = useState(true);
const [isDishesLoading, setIsDishesLoading] = useState(true);
@@ -54,7 +58,8 @@ const RestaurantMenu = () => {
const { data: menusData, error } = await supabase
.from("menus")
.select("id, name")
- .eq("restaurant_id", atob(suffix!));
+ .eq("restaurant_id", atob(suffix!))
+ .order("id", { ascending: true });
if (error) return error;
@@ -65,7 +70,8 @@ const RestaurantMenu = () => {
.select(
"id, name, description, price, images, video, video_thumbnail"
)
- .eq("menu_id", menu.id);
+ .eq("menu_id", menu.id)
+ .order("id", { ascending: true });
if (dishError) {
throw dishError;
@@ -89,13 +95,46 @@ const RestaurantMenu = () => {
fetchRestaurantData();
fetchDishes();
- }, [id, router, suffix]);
+ }, [restaurant, router, suffix]);
+
+ const resizableRestaurantDivRef = useRef
(null);
+ const [scrolled, setScrolled] = useState(false);
+
+ useEffect(() => {
+ const handleScroll = () => {
+ const resizableRestaurantDiv = resizableRestaurantDivRef.current;
+ if (!resizableRestaurantDiv || scrolled) return;
+
+ if (window.scrollY > 0) {
+ resizableRestaurantDiv.style.height = "60vh";
+ setScrolled(true);
+ }
+ };
+
+ const handleScrollUp = () => {
+ const resizableRestaurantDiv = resizableRestaurantDivRef.current;
+ if (!resizableRestaurantDiv || !scrolled) return;
+
+ if (window.scrollY === 0) {
+ resizableRestaurantDiv.style.height = "100vh";
+ setScrolled(false);
+ }
+ };
+
+ window.addEventListener("scroll", handleScroll);
+ window.addEventListener("scroll", handleScrollUp);
+
+ return () => {
+ window.removeEventListener("scroll", handleScroll);
+ window.removeEventListener("scroll", handleScrollUp);
+ };
+ }, [scrolled]);
return (
<>
{restaurantData ? (
-
+
@@ -131,7 +170,7 @@ const RestaurantMenu = () => {
{restaurantData.address}
-
@@ -181,7 +220,7 @@ const RestaurantMenu = () => {
inView ? "animated-fade-y" : ""
}`}
>
-
+
{item.name}
{isDishesLoading ? (
@@ -264,8 +303,11 @@ const RestaurantMenu = () => {