Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor UI in restaurant detail page #27

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions admin/pages/admins/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const AdminsPage = () => {
const { data, error } = await supabase
.from("admins_roles_restaurants")
.select("*, admins(id, name, email), roles(name)")
.order('id', { ascending: false })
.order("id", { ascending: false })
.range((page - 1) * pageSize, pageSize * page - 1)
.eq("restaurant_id", user.split("/")[2])
.neq("admin_id", user.split("/")[0]);
Expand Down Expand Up @@ -71,13 +71,12 @@ const AdminsPage = () => {
fetchAdmins(currentPage);
}, [currentPage]);

const deleteRecord = async (id: number, relativeId: number) => {
const deleteRecord = async (id: number) => {
try {
await supabase.from("admins").delete().eq("id", id).throwOnError();
await supabase
.from("admins_roles_restaurants")
.delete()
.eq("id", relativeId)
.eq("id", id)
.throwOnError();
setAdminsData(adminsData.filter((x) => x.id != id));
fetchCountAdmins();
Expand Down Expand Up @@ -188,7 +187,7 @@ const AdminsPage = () => {
className="text-red"
onClick={() =>
confirm("Are you sure you want to delete this admin?")
? deleteRecord(admin.admins.id, admin.id)
? deleteRecord(admin.id)
: ""
}
>
Expand Down
2 changes: 1 addition & 1 deletion admin/pages/invited-members/add/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const InvitedMemberPage = () => {

await sendEmail({
to: email,
subject: "Bite Space - Invitation To Join Space",
subject: "Invitation To Join Space",
message: render(
InviteMemberEmail({
invited_by: data.admins.name,
Expand Down
14 changes: 11 additions & 3 deletions website/components/BottomSheet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,31 @@ const BottomSheet = ({
};
}, [isOpen, onClose]);

const handleClose = () => {
if (window.history.state?.bottomSheetOpen) {
window.history.back();
} else {
onClose();
}
};
Comment on lines +34 to +40
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure to specify the button type to prevent unintended form submissions.

- <button onClick={handleClose} className="...">
+ <button type="button" onClick={handleClose} className="...">

Also applies to: 51-51

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
const handleClose = () => {
if (window.history.state?.bottomSheetOpen) {
window.history.back();
} else {
onClose();
}
};
const handleClose = () => {
if (window.history.state?.bottomSheetOpen) {
window.history.back();
} else {
onClose();
}
};
// Assuming this is the button element in the component
<button type="button" onClick={handleClose} className="...">


return (
<div
className={`fixed inset-0 z-[100] flex items-end ${
isOpen ? "block" : "hidden"
}`}
>
<div className="fixed inset-0" onClick={onClose}></div>
{/* <div className="fixed inset-0" onClick={onClose}></div> */}
<header className="select-none header left-0 top-0 z-40 w-full items-center absolute p-3 flex gap-2 text-white">
<button
onClick={onClose}
onClick={handleClose}
className="flex gap-2 items-center bg-primary bg-opacity-50 dark:bg-opacity-30 border-b border-primary dark:border-opacity-50 px-3 py-1 text-sm font-semibold rounded-lg"
>
<span>{"<"}</span>
Back
</button>
<span>|</span>
<p className="font-bold text-sm">{name} dishes</p>
<p className="font-bold text-sm">{name}</p>
</header>
<div className="h-full w-full bg-white dark:bg-black">
<Reels dishesData={items} />
Expand Down
28 changes: 22 additions & 6 deletions website/components/Reel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,16 @@ const Reels = ({ dishesData }: ReelProps) => {

return (
<section className="select-none">
{isLoading ? <MenuDishSkeleton classes="reel" /> : ""}
{isLoading ? (
<MenuDishSkeleton
classes="reel"
style={{
height: screenHeight != 0 ? screenHeight + "px" : "100vh",
}}
/>
) : (
""
)}
Comment on lines +86 to +95
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optimize the iteration by replacing forEach with for...of for better performance.

- entries.forEach((entry) => {
+ for (const entry of entries) {

Also applies to: 118-129

Committable suggestion was skipped due to low confidence.

<div
ref={carouselRef}
className="reelsContainer scrollbar-hidden w-full"
Expand All @@ -106,11 +115,18 @@ const Reels = ({ dishesData }: ReelProps) => {
{!isLoading ? (
<div className="animated-fade">
{data.video ? (
<VideoPlayer
src={data.video}
poster={data.video_thumbnail}
classes={"h-full w-full object-cover"}
/>
<div
style={{
height:
screenHeight != 0 ? screenHeight + "px" : "100vh",
}}
>
<VideoPlayer
src={data.video}
poster={data.video_thumbnail}
classes={"h-full w-full object-cover"}
/>
</div>
) : (
<SwiperComponent images={data.images}></SwiperComponent>
)}
Expand Down
3 changes: 2 additions & 1 deletion website/components/SkeletonPlaceholders/MenuDish.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const MenuDishSkeleton = ({ classes }: any) => {
const MenuDishSkeleton = ({ classes, style }: any) => {
return (
<div
className={`${classes} relative animate-pulse w-full bg-gray-200 dark:bg-black rounded-xl`}
style={style}
>
<div className="absolute flex h-full w-full flex-col gap-3 p-5 pb-10">
<div className="flex flex-col justify-end h-full gap-5">
Expand Down
9 changes: 3 additions & 6 deletions website/pages/category/restaurant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import BottomSheet from "@/components/BottomSheet";
import NoDataFound from "@/components/NoDataFound";
import { useAppDispatch, useAppSelector } from "@/store/store";
import { useAppDispatch } from "@/store/store";
import { RestaurantData } from "@/types/category-by-id";
import Image from "next/image";
import Link from "next/link";
Expand All @@ -12,7 +12,6 @@ import { Swiper, SwiperSlide } from "swiper/react";
import "swiper/css";
import "swiper/css/pagination";

import { Autoplay, Pagination } from "swiper/modules";
import { setScreenHeightState } from "@/store/slice";

const Restaurant = ({
Expand Down Expand Up @@ -49,7 +48,7 @@ const Restaurant = ({
);
}, [dispatch]);

return (
return (
<>
{restaurantsData && restaurantsData.length > 0 ? (
<div className="flex flex-col gap-5">
Expand Down Expand Up @@ -82,8 +81,6 @@ const Restaurant = ({
<Swiper
slidesPerView={"auto"}
spaceBetween={20}
autoplay={true}
modules={[Autoplay]}
className="h-full w-full mt-6"
>
{item.menu.map((data, index) => (
Expand Down Expand Up @@ -134,7 +131,7 @@ const Restaurant = ({
width={100}
/>
</div>
<p className="mt-1 w-full font-extrabold capitalize sm:text-xl text-center">
<p className="mt-1 w-full sm:w-96 font-extrabold capitalize sm:text-xl text-center">
{data.name}
</p>
</SwiperSlide>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ const RestaurantCategory = ({
Back
</button>
<span>|</span>
<p className="font-bold text-sm">{categoryData.name} dishes</p>
<p className="font-bold text-sm">{categoryData.name}</p>
</header>
<Reels
dishesData={dishesData}
Expand Down
2 changes: 1 addition & 1 deletion website/pages/restaurants/[restaurant]/menus/[menu].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ const RestaurantMenu = ({ name, menus }: { name: string; menus: any }) => {
Back
</button>
<span>|</span>
<p className="font-bold text-sm">{menuName} dishes</p>
<p className="font-bold text-sm">{menuName}</p>
</header>
<Reels dishesData={menusData} />
</NoHeaderFooterLayout>
Expand Down
Loading