Change structure and implement some admin functions
This commit is contained in:
+6
-35
@@ -6,7 +6,6 @@ import {
|
||||
useRouteError,
|
||||
isRouteErrorResponse,
|
||||
json,
|
||||
redirect,
|
||||
useLoaderData
|
||||
} from "@remix-run/react";
|
||||
import type { PropsWithChildren } from "react";
|
||||
@@ -20,31 +19,11 @@ export const links: LinksFunction = () => [
|
||||
import Header, { HeaderData } from "~/components/header";
|
||||
import { Col, Container, Row } from "react-bootstrap";
|
||||
import { getSession } from "./auth/session";
|
||||
import { head } from "lodash";
|
||||
import { User } from "@zenstackhq/runtime/models";
|
||||
|
||||
export async function loader({
|
||||
request,
|
||||
}: LoaderFunctionArgs) {
|
||||
const session = await getSession(
|
||||
request.headers.get("Cookie")
|
||||
);
|
||||
|
||||
let data : HeaderData = {loggedin: false};
|
||||
|
||||
if(session.has("user_id")){
|
||||
data.user = session.get("user");
|
||||
data.loggedin = true;
|
||||
}
|
||||
|
||||
return json({data});
|
||||
}
|
||||
|
||||
function Document({
|
||||
children,
|
||||
headerData,
|
||||
title = "K-FRIDGE",
|
||||
}: PropsWithChildren<{ title?: string, headerData: HeaderData }>) {
|
||||
}: PropsWithChildren<{ title?: string}>) {
|
||||
return (
|
||||
<html lang="en" data-bs-theme="light">
|
||||
<head>
|
||||
@@ -57,12 +36,7 @@ function Document({
|
||||
<Links />
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<Header data={headerData}></Header>
|
||||
</header>
|
||||
<main>
|
||||
{children}
|
||||
</main>
|
||||
{children}
|
||||
<Scripts />
|
||||
</body>
|
||||
</html>
|
||||
@@ -70,22 +44,19 @@ function Document({
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
const data = useLoaderData<typeof loader>();
|
||||
|
||||
return (
|
||||
<Document headerData={data.data}>
|
||||
<Outlet />
|
||||
<Document>
|
||||
<Outlet></Outlet>
|
||||
</Document>
|
||||
);
|
||||
}
|
||||
|
||||
export function ErrorBoundary() {
|
||||
const error = useRouteError();
|
||||
const data = useLoaderData<typeof loader>();
|
||||
|
||||
if (isRouteErrorResponse(error)) {
|
||||
return (
|
||||
<Document headerData={data.data}
|
||||
<Document
|
||||
title={`${error.status} ${error.statusText}`}
|
||||
>
|
||||
<Container>
|
||||
@@ -107,7 +78,7 @@ export function ErrorBoundary() {
|
||||
? error.message
|
||||
: "Unknown error";
|
||||
return (
|
||||
<Document title="Uh-oh!" headerData={data.data}>
|
||||
<Document title="Uh-oh!">
|
||||
<Container>
|
||||
<Row className="align-items-md-stretch">
|
||||
<Col md={12}>
|
||||
|
||||
Reference in New Issue
Block a user