2025-03-11 23:04:29 +08:00
|
|
|
import { isRouteErrorResponse, Outlet } from 'react-router'
|
2025-02-23 10:22:51 +08:00
|
|
|
|
2025-03-09 09:57:26 +08:00
|
|
|
import { getCategories } from '~/apis/common/get-categories'
|
|
|
|
|
import { getTags } from '~/apis/common/get-tags'
|
2025-03-09 20:22:48 +08:00
|
|
|
import { AdminProvider } from '~/contexts/admin'
|
2025-02-23 10:22:51 +08:00
|
|
|
import { AdminDashboardLayout } from '~/layouts/admin/dashboard'
|
|
|
|
|
|
2025-03-09 09:57:26 +08:00
|
|
|
import type { Route } from './+types/_admin.lg-admin._dashboard'
|
|
|
|
|
|
|
|
|
|
export const loader = async ({}: Route.LoaderArgs) => {
|
|
|
|
|
const { data: categoriesData } = await getCategories()
|
|
|
|
|
const { data: tagsData } = await getTags()
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
categoriesData,
|
|
|
|
|
tagsData,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-11 23:04:29 +08:00
|
|
|
export const ErrorBoundary = ({ error }: Route.ErrorBoundaryProps) => {
|
|
|
|
|
let message = 'Oops!'
|
|
|
|
|
let details = 'An unexpected error occurred.'
|
|
|
|
|
let stack: string | undefined
|
|
|
|
|
|
|
|
|
|
if (isRouteErrorResponse(error)) {
|
|
|
|
|
message = error.status === 404 ? '404' : 'Error'
|
|
|
|
|
details =
|
|
|
|
|
error.status === 404
|
|
|
|
|
? 'The requested page could not be found.'
|
|
|
|
|
: error.statusText || details
|
|
|
|
|
} else if (import.meta.env.DEV && error && error instanceof Error) {
|
|
|
|
|
details = error.message
|
|
|
|
|
stack = error.stack
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="container mx-auto p-4">
|
|
|
|
|
<h1>{message}</h1>
|
|
|
|
|
<p>{details}</p>
|
|
|
|
|
{stack && (
|
|
|
|
|
<pre className="w-full p-4 whitespace-pre-wrap">
|
|
|
|
|
<code>{stack}</code>
|
|
|
|
|
</pre>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-23 10:11:47 +08:00
|
|
|
const DashboardLayout = () => {
|
2025-02-22 17:14:33 +08:00
|
|
|
return (
|
2025-03-09 20:22:48 +08:00
|
|
|
<AdminProvider>
|
|
|
|
|
<AdminDashboardLayout>
|
|
|
|
|
<Outlet />
|
|
|
|
|
</AdminDashboardLayout>
|
|
|
|
|
</AdminProvider>
|
2025-02-22 17:14:33 +08:00
|
|
|
)
|
|
|
|
|
}
|
2025-02-23 10:11:47 +08:00
|
|
|
export default DashboardLayout
|