Skip to content

Commit

Permalink
Refactor getting bowser height
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-dharti-r committed Apr 30, 2024
1 parent c15b2fa commit c9d6db4
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 9 deletions.
4 changes: 2 additions & 2 deletions website/components/FoodCategory/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const FoodCategory = () => {
try {
const { data, error } = await supabase
.from("categories")
.select()
.select("*")
.eq("restaurant_id", 0)
.order("id", { ascending: true });

Expand All @@ -43,7 +43,7 @@ const FoodCategory = () => {

return (
<>
<section className="bg-primary/[.03] py-16 md:py-20 lg:py-28">
<section className="py-16 md:py-20 lg:py-28">
<div className="container">
<SectionTitle
title="What's on your mind?"
Expand Down
8 changes: 8 additions & 0 deletions website/components/Hero/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ const Hero = () => {

useEffect(() => {
setScreenHeight(window.innerHeight);

window.addEventListener("resize", () =>
setScreenHeight(window.innerHeight)
);
return () =>
window.removeEventListener("resize", () =>
setScreenHeight(window.innerHeight)
);
}, []);

return (
Expand Down
31 changes: 28 additions & 3 deletions website/components/PageNotFound/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
import Image from "next/image";
import { useEffect, useState } from "react";

const NotFound = () => {
const [screenHeight, setScreenHeight] = useState<number>(0);

useEffect(() => {
setScreenHeight(window.innerHeight);

window.addEventListener("resize", () =>
setScreenHeight(window.innerHeight)
);
return () =>
window.removeEventListener("resize", () =>
setScreenHeight(window.innerHeight)
);
}, []);

return (
<div className="h-screen select-none">
<div className="animated-fade-y flex h-screen w-full">
<div className="select-none">
<div
className="animated-fade-y flex w-full"
style={{
height: screenHeight != 0 ? screenHeight + "px" : "100vh",
}}
>
<Image
className="object-cover w-full h-full"
src="/images/not-found.webp"
Expand All @@ -12,7 +32,12 @@ const NotFound = () => {
loading="lazy"
/>
</div>
<div className="animated-fade-y absolute top-0 bg-black h-screen w-full bg-opacity-60">
<div
className="animated-fade-y absolute top-0 bg-black w-full bg-opacity-60"
style={{
height: screenHeight != 0 ? screenHeight + "px" : "100vh",
}}
>
<div className="container h-full items-center justify-center text-white flex flex-col">
<div className="text-3xl sm:text-5xl md:text-7xl font-extrabold border-b border-primary pb-2 sm:pb-3 md:pb-5">
Not Found
Expand Down
8 changes: 8 additions & 0 deletions website/pages/about/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ const About = () => {

useEffect(() => {
setScreenHeight(window.innerHeight);

window.addEventListener("resize", () =>
setScreenHeight(window.innerHeight)
);
return () =>
window.removeEventListener("resize", () =>
setScreenHeight(window.innerHeight)
);
}, []);

return (
Expand Down
8 changes: 6 additions & 2 deletions website/pages/category/[category].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ const Category = () => {

useEffect(() => {
const fetchCategoryData = async () => {
if (restaurantsData.length != 0) {
return;
}

if (suffix) {
try {
const { data, error } = await supabase
Expand All @@ -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;
Expand Down Expand Up @@ -89,7 +93,7 @@ const Category = () => {
};

fetchCategoryData();
}, [suffix]);
}, [restaurantsData.length, suffix]);

return (
<>
Expand Down
11 changes: 10 additions & 1 deletion website/pages/restaurants/[restaurant]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLDivElement>(null);
Expand Down Expand Up @@ -391,7 +400,7 @@ const RestaurantMenu = () => {
</div>
</div>
<div className="scrollbar-hidden mx-3">
<p className="text-2xl font-bold mb-5 border-b dark:border-white dark:border-opacity-30 border-black border-opacity-10 pb-2">
<p className="text-center text-2xl font-bold mb-5 border-b dark:border-white dark:border-opacity-30 border-black border-opacity-10 pb-2">
Menus
</p>
<div className="grid grid-cols-2 gap-3 h-full w-full">
Expand Down
13 changes: 12 additions & 1 deletion website/pages/restaurants/[restaurant]/menus/[menu].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const RestaurantMenu = () => {
setScreenHeight(window.innerHeight);

const fetchDishes = async () => {
if (menuData) return;

if (suffix && menuSuffix) {
try {
const { data, error } = await supabase
Expand Down Expand Up @@ -70,7 +72,7 @@ const RestaurantMenu = () => {
};

fetchDishes();
}, [suffix, menuSuffix]);
}, [suffix, menuSuffix, menuData]);

const carouselRef = useRef<HTMLDivElement>(null);
const [numDivsToRender, setNumDivsToRender] = useState(2); // Initial number of dish to render
Expand Down Expand Up @@ -109,6 +111,15 @@ const RestaurantMenu = () => {
}
};
}

window.addEventListener("resize", () =>
setScreenHeight(window.innerHeight)
);

return () =>
window.removeEventListener("resize", () =>
setScreenHeight(window.innerHeight)
);
}, [carouselRef, numDivsToRender, menuData?.length]);

return (
Expand Down

0 comments on commit c9d6db4

Please sign in to comment.