This commit is contained in:
@@ -10,6 +10,8 @@ import MenuItemRenderer from "@/components/listview/MenuItemRenderer";
|
|||||||
import VerticalScrollView from "@/components/listview/VerticalScrollView";
|
import VerticalScrollView from "@/components/listview/VerticalScrollView";
|
||||||
import useToggle from "@/hooks/helpers/useToggle";
|
import useToggle from "@/hooks/helpers/useToggle";
|
||||||
import { glassSurfaceFlat } from "@/lib/styles/glassSurface";
|
import { glassSurfaceFlat } from "@/lib/styles/glassSurface";
|
||||||
|
import clsx from "clsx";
|
||||||
|
import { motion } from "framer-motion";
|
||||||
import { Candle2 } from "iconsax-react";
|
import { Candle2 } from "iconsax-react";
|
||||||
import { useQueryState } from "next-usequerystate";
|
import { useQueryState } from "next-usequerystate";
|
||||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||||
@@ -37,7 +39,7 @@ const MenuIndex = () => {
|
|||||||
});
|
});
|
||||||
const [selectedIngredients, setSelectedIngredients] = useQueryState("ingredients", { defaultValue: "" });
|
const [selectedIngredients, setSelectedIngredients] = useQueryState("ingredients", { defaultValue: "" });
|
||||||
const [selectedDeliveryId, setSelectedDeliveryId] = useQueryState("delivery", { defaultValue: "0" });
|
const [selectedDeliveryId, setSelectedDeliveryId] = useQueryState("delivery", { defaultValue: "0" });
|
||||||
const categoryStickySentinelRef: React.RefObject<HTMLDivElement | null> = useRef(null);
|
const smallCategoriesRef: React.RefObject<HTMLDivElement | null> = useRef(null);
|
||||||
const wrapperRef: React.RefObject<HTMLDivElement | null> = useRef(null);
|
const wrapperRef: React.RefObject<HTMLDivElement | null> = useRef(null);
|
||||||
const [smallCategoriesVisible, setSmallCategoriesVisibility] = useState(false);
|
const [smallCategoriesVisible, setSmallCategoriesVisibility] = useState(false);
|
||||||
const [isInitialMount, setIsInitialMount] = useState(true);
|
const [isInitialMount, setIsInitialMount] = useState(true);
|
||||||
@@ -66,18 +68,16 @@ const MenuIndex = () => {
|
|||||||
const scrollContainer = wrapperRef.current.parentElement?.parentElement;
|
const scrollContainer = wrapperRef.current.parentElement?.parentElement;
|
||||||
if (!scrollContainer) return;
|
if (!scrollContainer) return;
|
||||||
|
|
||||||
const sentinel = categoryStickySentinelRef.current;
|
const handleScroll = () => {
|
||||||
if (!sentinel) return;
|
if (!smallCategoriesRef.current) return;
|
||||||
|
setSmallCategoriesVisibility(scrollContainer.scrollTop >= smallCategoriesRef.current.offsetTop);
|
||||||
|
};
|
||||||
|
|
||||||
const observer = new IntersectionObserver(
|
scrollContainer.addEventListener("scroll", handleScroll, { passive: true });
|
||||||
([entry]) => setSmallCategoriesVisibility(!entry.isIntersecting),
|
handleScroll();
|
||||||
{ root: scrollContainer, threshold: 0 },
|
|
||||||
);
|
|
||||||
|
|
||||||
observer.observe(sentinel);
|
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
observer.disconnect();
|
scrollContainer.removeEventListener("scroll", handleScroll);
|
||||||
};
|
};
|
||||||
}, [isLoading]);
|
}, [isLoading]);
|
||||||
|
|
||||||
@@ -169,19 +169,11 @@ const MenuIndex = () => {
|
|||||||
<div className="flex flex-col gap-4 items-center pt-5 mb-8" ref={wrapperRef}>
|
<div className="flex flex-col gap-4 items-center pt-5 mb-8" ref={wrapperRef}>
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<SearchBox value={search} placeholder={tCommon("SearchPlaceholder")} onChange={updateSearch} />
|
<SearchBox value={search} placeholder={tCommon("SearchPlaceholder")} onChange={updateSearch} />
|
||||||
<div ref={categoryStickySentinelRef} className="h-px w-full" aria-hidden />
|
<CategoryScroll categories={categories} selectedCategory={selectedCategory} onSelect={updateCategory} />
|
||||||
<div className="sticky z-20 top-16 xl:top-20 w-full">
|
|
||||||
<CategoryScroll
|
|
||||||
categories={categories}
|
|
||||||
selectedCategory={selectedCategory}
|
|
||||||
onSelect={updateCategory}
|
|
||||||
variant={smallCategoriesVisible ? "small" : "large"}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<section className="w-full relative z-0">
|
<section className="w-full">
|
||||||
<div className="flex flex-wrap gap-2 items-center relative">
|
<div className="flex flex-wrap gap-2 items-center relative" ref={smallCategoriesRef}>
|
||||||
<span className="sm:text-base text-sm font-medium max-w-[113px] sm:max-w-auto">{selectedCategory === "0" ? "" : categories.find((c) => c.id === selectedCategory)?.title || ""}</span>
|
<span className="sm:text-base text-sm font-medium max-w-[113px] sm:max-w-auto">{selectedCategory === "0" ? "" : categories.find((c) => c.id === selectedCategory)?.title || ""}</span>
|
||||||
<div className="flex min-w-[247px] flex-1 gap-2 justify-end items-center">
|
<div className="flex min-w-[247px] flex-1 gap-2 justify-end items-center">
|
||||||
<button onClick={toggleFilterModal} className={glassSurfaceFlat("rounded-xl h-8 ps-4 pe-2 py-1.5 inline-flex items-center justify-between gap-[7px]")}>
|
<button onClick={toggleFilterModal} className={glassSurfaceFlat("rounded-xl h-8 ps-4 pe-2 py-1.5 inline-flex items-center justify-between gap-[7px]")}>
|
||||||
@@ -195,7 +187,22 @@ const MenuIndex = () => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<VerticalScrollView className="mt-5!">
|
<motion.div
|
||||||
|
initial={{
|
||||||
|
y: smallCategoriesVisible ? 0 : -50,
|
||||||
|
opacity: smallCategoriesVisible ? 1 : 0,
|
||||||
|
}}
|
||||||
|
animate={{
|
||||||
|
y: smallCategoriesVisible ? 0 : -50,
|
||||||
|
opacity: smallCategoriesVisible ? 1 : 0,
|
||||||
|
}}
|
||||||
|
transition={{ duration: 0.1 }}
|
||||||
|
className={clsx(glassSurfaceFlat("fixed left-0 z-10 top-0 px-4 pt-16 right-0 xl:pr-72 xl:pt-20 border-x-0 border-t-0 rounded-none"), !smallCategoriesVisible && "pointer-events-none")}
|
||||||
|
>
|
||||||
|
<CategoryScroll categories={categories} selectedCategory={selectedCategory} onSelect={updateCategory} variant="small" />
|
||||||
|
</motion.div>
|
||||||
|
|
||||||
|
<VerticalScrollView className="mt-5! overflow-y-auto h-full">
|
||||||
{filteredReceiptItems.length === 0 ? (
|
{filteredReceiptItems.length === 0 ? (
|
||||||
<div className="text-center text-foreground/60 py-8">{foodsData ? "غذایی یافت نشد" : "در حال بارگذاری..."}</div>
|
<div className="text-center text-foreground/60 py-8">{foodsData ? "غذایی یافت نشد" : "در حال بارگذاری..."}</div>
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ function ClientMenuRouteWrapper({ children }: Props) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="h-svh overflow-hidden pt-10 flex flex-col pb-4 xl:pt-12">
|
<div className="h-svh overflow-hidden pt-10 flex flex-col pb-4 xl:pt-12">
|
||||||
<div className={glassSurface("z-50 fixed right-4 left-4 xl:right-[285px] top-4 xl:h-16 h-12 flex items-center px-4 justify-between rounded-[32px] xl:w-[calc(100%-305px)]")}>
|
<div data-menu-topbar className={glassSurface("z-50 fixed right-4 left-4 xl:right-[285px] top-4 xl:h-16 h-12 flex items-center px-4 justify-between rounded-[32px] xl:w-[calc(100%-305px)]")}>
|
||||||
<TopBar
|
<TopBar
|
||||||
profileDropState={profileDrop}
|
profileDropState={profileDrop}
|
||||||
toggleProfileDropState={toggleProfileDrop}
|
toggleProfileDropState={toggleProfileDrop}
|
||||||
@@ -122,6 +122,7 @@ function ClientMenuRouteWrapper({ children }: Props) {
|
|||||||
{!hideBottomNav && (
|
{!hideBottomNav && (
|
||||||
<div
|
<div
|
||||||
ref={navContainerRef}
|
ref={navContainerRef}
|
||||||
|
data-menu-bottom-nav
|
||||||
className="fixed bottom-7 left-0 right-0 z-45 px-4"
|
className="fixed bottom-7 left-0 right-0 z-45 px-4"
|
||||||
style={{ willChange: "transform", transformOrigin: "center bottom" }}
|
style={{ willChange: "transform", transformOrigin: "center bottom" }}
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user