remove ssr
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
"use client";
|
||||
|
||||
import { useGetAbout } from "@/app/[name]/(Main)/about/hooks/useAboutData";
|
||||
import { PWA_ICON_192 } from "@/lib/helpers/pwaIcons";
|
||||
import { useParams } from "next/navigation";
|
||||
import { useEffect } from "react";
|
||||
|
||||
function upsertMeta(name: string, content: string, attribute: "name" | "property" = "name") {
|
||||
let element = document.querySelector(`meta[${attribute}="${name}"]`);
|
||||
if (!element) {
|
||||
element = document.createElement("meta");
|
||||
element.setAttribute(attribute, name);
|
||||
document.head.appendChild(element);
|
||||
}
|
||||
element.setAttribute("content", content);
|
||||
}
|
||||
|
||||
function upsertLink(rel: string, href: string) {
|
||||
let element = document.querySelector(`link[rel="${rel}"]`) as HTMLLinkElement | null;
|
||||
if (!element) {
|
||||
element = document.createElement("link");
|
||||
element.rel = rel;
|
||||
document.head.appendChild(element);
|
||||
}
|
||||
element.href = href;
|
||||
}
|
||||
|
||||
export default function RestaurantHeadManager() {
|
||||
const { name } = useParams<{ name: string }>();
|
||||
const { data } = useGetAbout();
|
||||
|
||||
useEffect(() => {
|
||||
if (!name || !data?.data) return;
|
||||
|
||||
const restaurant = data.data;
|
||||
document.title = restaurant.seoTitle || restaurant.name;
|
||||
|
||||
upsertMeta(
|
||||
"description",
|
||||
restaurant.seoDescription ||
|
||||
restaurant.description ||
|
||||
`منوی ${restaurant.name}`,
|
||||
);
|
||||
|
||||
const themeColor = restaurant.menuColor || "#F4F5F9";
|
||||
upsertMeta("theme-color", themeColor);
|
||||
|
||||
upsertLink("manifest", `/${name}/manifest.webmanifest`);
|
||||
|
||||
const logo = restaurant.logo?.trim();
|
||||
const iconUrl =
|
||||
logo && logo !== ""
|
||||
? `/${name}/api/logo?url=${encodeURIComponent(logo)}&size=192`
|
||||
: PWA_ICON_192;
|
||||
|
||||
upsertLink("icon", iconUrl);
|
||||
upsertLink("apple-touch-icon", iconUrl);
|
||||
}, [data, name]);
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
"use client";
|
||||
|
||||
import { useGetAbout } from "@/app/[name]/(Main)/about/hooks/useAboutData";
|
||||
import { useParams } from "next/navigation";
|
||||
|
||||
type Props = {
|
||||
children: React.ReactNode;
|
||||
};
|
||||
|
||||
export default function RestaurantNotFoundGuard({ children }: Props) {
|
||||
const { name } = useParams<{ name: string }>();
|
||||
const { isError, isLoading, isFetching } = useGetAbout();
|
||||
|
||||
if (!name) {
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
||||
if (isLoading || isFetching) {
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
||||
if (isError) {
|
||||
return (
|
||||
<div className="flex min-h-[50vh] items-center justify-center px-6 text-center">
|
||||
<p className="text-disabled-text">رستوران یافت نشد</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return <>{children}</>;
|
||||
}
|
||||
Reference in New Issue
Block a user