diff --git a/website/components/FoodCategory/index.tsx b/website/components/FoodCategory/index.tsx index 247f8ea..eb47680 100644 --- a/website/components/FoodCategory/index.tsx +++ b/website/components/FoodCategory/index.tsx @@ -24,7 +24,7 @@ const FoodCategory = () => { try { const { data, error } = await supabase .from("categories") - .select() + .select("*") .eq("restaurant_id", 0) .order("id", { ascending: true }); @@ -43,7 +43,7 @@ const FoodCategory = () => { return ( <> -
+
{ useEffect(() => { setScreenHeight(window.innerHeight); + + window.addEventListener("resize", () => + setScreenHeight(window.innerHeight) + ); + return () => + window.removeEventListener("resize", () => + setScreenHeight(window.innerHeight) + ); }, []); return ( diff --git a/website/components/PageNotFound/index.tsx b/website/components/PageNotFound/index.tsx index 516c801..c9ead25 100644 --- a/website/components/PageNotFound/index.tsx +++ b/website/components/PageNotFound/index.tsx @@ -1,9 +1,29 @@ import Image from "next/image"; +import { useEffect, useState } from "react"; const NotFound = () => { + const [screenHeight, setScreenHeight] = useState(0); + + useEffect(() => { + setScreenHeight(window.innerHeight); + + window.addEventListener("resize", () => + setScreenHeight(window.innerHeight) + ); + return () => + window.removeEventListener("resize", () => + setScreenHeight(window.innerHeight) + ); + }, []); + return ( -
-
+
+
{ loading="lazy" />
-
+
Not Found diff --git a/website/pages/about/index.tsx b/website/pages/about/index.tsx index 4cd4163..3e3a235 100644 --- a/website/pages/about/index.tsx +++ b/website/pages/about/index.tsx @@ -11,6 +11,14 @@ const About = () => { useEffect(() => { setScreenHeight(window.innerHeight); + + window.addEventListener("resize", () => + setScreenHeight(window.innerHeight) + ); + return () => + window.removeEventListener("resize", () => + setScreenHeight(window.innerHeight) + ); }, []); return ( diff --git a/website/pages/category/[category].tsx b/website/pages/category/[category].tsx index f36d209..fc7ca38 100644 --- a/website/pages/category/[category].tsx +++ b/website/pages/category/[category].tsx @@ -21,6 +21,10 @@ const Category = () => { useEffect(() => { const fetchCategoryData = async () => { + if (restaurantsData.length != 0) { + return; + } + if (suffix) { try { const { data, error } = await supabase @@ -38,7 +42,7 @@ const Category = () => { .from("categories") .select("id, restaurant_id, image") .neq("restaurant_id", 0) - .order('id', { ascending: false }) + .order("id", { ascending: false }) .contains("tags", [data.name.toLowerCase()]); if (categoriesError) throw categoriesError; @@ -89,7 +93,7 @@ const Category = () => { }; fetchCategoryData(); - }, [suffix]); + }, [restaurantsData.length, suffix]); return ( <> diff --git a/website/pages/restaurants/[restaurant]/index.tsx b/website/pages/restaurants/[restaurant]/index.tsx index 356a2cc..792b4f5 100644 --- a/website/pages/restaurants/[restaurant]/index.tsx +++ b/website/pages/restaurants/[restaurant]/index.tsx @@ -99,6 +99,15 @@ const RestaurantMenu = () => { fetchRestaurantData(); fetchDishes(); + + window.addEventListener("resize", () => + setScreenHeight(window.innerHeight) + ); + + return () => + window.removeEventListener("resize", () => + setScreenHeight(window.innerHeight) + ); }, [restaurant, router, suffix]); const resizableRestaurantDivRef = useRef(null); @@ -391,7 +400,7 @@ const RestaurantMenu = () => {
-

+

Menus

diff --git a/website/pages/restaurants/[restaurant]/menus/[menu].tsx b/website/pages/restaurants/[restaurant]/menus/[menu].tsx index 46d0752..16cc9f5 100644 --- a/website/pages/restaurants/[restaurant]/menus/[menu].tsx +++ b/website/pages/restaurants/[restaurant]/menus/[menu].tsx @@ -35,6 +35,8 @@ const RestaurantMenu = () => { setScreenHeight(window.innerHeight); const fetchDishes = async () => { + if (menuData) return; + if (suffix && menuSuffix) { try { const { data, error } = await supabase @@ -70,7 +72,7 @@ const RestaurantMenu = () => { }; fetchDishes(); - }, [suffix, menuSuffix]); + }, [suffix, menuSuffix, menuData]); const carouselRef = useRef(null); const [numDivsToRender, setNumDivsToRender] = useState(2); // Initial number of dish to render @@ -109,6 +111,15 @@ const RestaurantMenu = () => { } }; } + + window.addEventListener("resize", () => + setScreenHeight(window.innerHeight) + ); + + return () => + window.removeEventListener("resize", () => + setScreenHeight(window.innerHeight) + ); }, [carouselRef, numDivsToRender, menuData?.length]); return (