sendou.ink/app/components/Main.tsx
Kalle d4d6002344
New results tab for tournaments (#1876)
* Initial

* Try npm in deploy script

* Progress

* Progress

* Progress

* Add missing index

* Title to user results page

* Hide SPR before tournament over

* Results page and redirect

* SPR info

* Row bg colors

* Laoyut shift fix

* Hide Swiss start round button if bracket is in preview

* Fix e2e test

* Not needed

* one more revert
2024-09-08 11:25:10 +03:00

76 lines
1.6 KiB
TypeScript

import {
isRouteErrorResponse,
useLocation,
useRouteError,
} from "@remix-run/react";
import { SideNav } from "app/components/layout/SideNav";
import clsx from "clsx";
import type * as React from "react";
import { useUser } from "~/features/auth/core/user";
export const Main = ({
children,
className,
classNameOverwrite,
halfWidth,
bigger,
style,
}: {
children: React.ReactNode;
className?: string;
classNameOverwrite?: string;
halfWidth?: boolean;
bigger?: boolean;
style?: React.CSSProperties;
}) => {
const error = useRouteError();
const user = useUser();
const showLeaderboard =
import.meta.env.VITE_PLAYWIRE_PUBLISHER_ID &&
!user?.patronTier &&
!isRouteErrorResponse(error);
const location = useLocation();
const isFrontPage = location.pathname === "/";
return (
<div className="layout__main-container">
{!isFrontPage ? <SideNav /> : null}
<main
className={
classNameOverwrite
? clsx(classNameOverwrite, {
[containerClassName("narrow")]: halfWidth,
"pt-8-forced": showLeaderboard,
})
: clsx(
"layout__main",
containerClassName("normal"),
{
[containerClassName("narrow")]: halfWidth,
[containerClassName("wide")]: bigger,
"pt-8-forced": showLeaderboard,
},
className,
)
}
style={style}
>
{children}
</main>
</div>
);
};
export const containerClassName = (width: "narrow" | "normal" | "wide") => {
if (width === "narrow") {
return "half-width";
}
if (width === "wide") {
return "bigger";
}
return "main";
};