remove ssr
This commit is contained in:
+5
-110
@@ -1,114 +1,9 @@
|
||||
import PreferenceWrapper from '@/components/wrapper/PreferenceWrapper'
|
||||
import React from 'react'
|
||||
import type { Metadata, Viewport } from 'next'
|
||||
import { getRestaurant } from './lib/getRestaurant'
|
||||
import { notFound } from 'next/navigation'
|
||||
import CartChecker from '@/components/CartChecker'
|
||||
import ActiveChecker from '@/components/ActiveChecker'
|
||||
import { PWA_ICON_192, PWA_ICON_512 } from '@/lib/helpers/pwaIcons'
|
||||
import RestaurantLayoutClient from "./RestaurantLayoutClient";
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
export const revalidate = 0
|
||||
|
||||
type LayoutParams = { name: string }
|
||||
|
||||
export async function generateMetadata({
|
||||
params
|
||||
}: {
|
||||
params: Promise<LayoutParams>
|
||||
}): Promise<Metadata> {
|
||||
const { name } = await params
|
||||
const defaultIcon = PWA_ICON_192
|
||||
const defaultIcon512 = PWA_ICON_512
|
||||
|
||||
try {
|
||||
const restaurant = await getRestaurant(name)
|
||||
const title = restaurant.seoTitle || restaurant.name
|
||||
const logo = restaurant.logo
|
||||
|
||||
let iconUrl = defaultIcon
|
||||
let icon192Url = defaultIcon
|
||||
let icon512Url = defaultIcon512
|
||||
|
||||
if (logo && logo.trim() !== "") {
|
||||
iconUrl = `/${name}/api/logo?url=${encodeURIComponent(logo)}&size=192`
|
||||
icon192Url = iconUrl
|
||||
icon512Url = `/${name}/api/logo?url=${encodeURIComponent(logo)}&size=512`
|
||||
}
|
||||
|
||||
return {
|
||||
title,
|
||||
description: restaurant.seoDescription || restaurant.description || `منوی ${restaurant.name}`,
|
||||
manifest: `/${name}/manifest.webmanifest`,
|
||||
icons: {
|
||||
icon: [
|
||||
{ url: iconUrl },
|
||||
{ url: icon192Url, sizes: "192x192", type: "image/png" },
|
||||
{ url: icon512Url, sizes: "512x512", type: "image/png" },
|
||||
],
|
||||
shortcut: iconUrl,
|
||||
apple: iconUrl,
|
||||
},
|
||||
}
|
||||
} catch {
|
||||
return {
|
||||
title: `${name} - Dashboard`,
|
||||
description: `PWA dashboard for ${name}`,
|
||||
manifest: `/${name}/manifest.webmanifest`,
|
||||
icons: {
|
||||
icon: [
|
||||
{ url: PWA_ICON_192 },
|
||||
{ url: PWA_ICON_192, sizes: "192x192", type: "image/png" },
|
||||
{ url: PWA_ICON_512, sizes: "512x512", type: "image/png" },
|
||||
],
|
||||
shortcut: PWA_ICON_192,
|
||||
apple: PWA_ICON_192,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function generateViewport({
|
||||
params
|
||||
}: {
|
||||
params: Promise<LayoutParams>
|
||||
}): Promise<Viewport> {
|
||||
try {
|
||||
const { name } = await params
|
||||
const restaurant = await getRestaurant(name)
|
||||
|
||||
return {
|
||||
themeColor: restaurant.menuColor || '#F4F5F9'
|
||||
}
|
||||
} catch {
|
||||
return {
|
||||
themeColor: '#F4F5F9'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default async function Layout({
|
||||
export default function Layout({
|
||||
children,
|
||||
params
|
||||
}: {
|
||||
children: React.ReactNode
|
||||
params: Promise<LayoutParams>
|
||||
}): Promise<React.ReactNode> {
|
||||
const { name } = await params
|
||||
|
||||
try {
|
||||
await getRestaurant(name)
|
||||
} catch (error) {
|
||||
if (error instanceof Error && error.message === 'RESTAURANT_NOT_FOUND') {
|
||||
notFound()
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<PreferenceWrapper>{children}</PreferenceWrapper>
|
||||
<CartChecker />
|
||||
<ActiveChecker />
|
||||
</>
|
||||
)
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
return <RestaurantLayoutClient>{children}</RestaurantLayoutClient>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user