From bb921cc1079aa08eca83f9b3da6890f95a745eee Mon Sep 17 00:00:00 2001 From: prostarz Date: Mon, 11 Nov 2024 18:17:55 +0000 Subject: [PATCH] fix(ui): titlebar causing layout shifts --- src/components/errorComponent/index.tsx | 22 ++++++++++++++----- src/features/navigation/components/navbar.tsx | 4 ++-- src/features/settings/components/sidebar.tsx | 15 ++++++++++--- src/lib/helpers/helpers.ts | 5 +++++ src/routes/__root.tsx | 4 ++-- src/routes/settings.tsx | 6 ++--- 6 files changed, 40 insertions(+), 16 deletions(-) diff --git a/src/components/errorComponent/index.tsx b/src/components/errorComponent/index.tsx index c869d6c..28c44d6 100644 --- a/src/components/errorComponent/index.tsx +++ b/src/components/errorComponent/index.tsx @@ -1,28 +1,38 @@ -import { cn } from "@/lib"; +import { useSettings } from "@/hooks"; +import { cn, shouldHideTitleBar } from "@/lib"; import { ErrorComponentProps, Link } from "@tanstack/react-router"; import { Button, buttonVariants } from "../ui/button"; import { ScrollArea } from "../ui/scroll-area"; const ErrorComponent = (props: ErrorComponentProps) => { + const { settings } = useSettings(); + return ( -
+

{props.error.name}

{props.error.message}

-
+
-
+          
             {props.error.stack}
           
-
-
+
+
Go to Home diff --git a/src/features/navigation/components/navbar.tsx b/src/features/navigation/components/navbar.tsx index 2534a7e..2dbc2a0 100644 --- a/src/features/navigation/components/navbar.tsx +++ b/src/features/navigation/components/navbar.tsx @@ -1,5 +1,5 @@ import { useSettings } from "@/hooks"; -import { cn } from "@/lib"; +import { cn, shouldHideTitleBar } from "@/lib"; import NavBarBottom from "./containers/bottom"; import NavBarTop from "./containers/top"; @@ -13,7 +13,7 @@ const NavBar = () => { className={cn( "fixed inset-y-0 left-0 z-10 w-16 flex flex-col border-r bg-background", { - "top-8": !["none", "native"].includes(titleBarStyle), + "top-8": !shouldHideTitleBar(titleBarStyle), } )} > diff --git a/src/features/settings/components/sidebar.tsx b/src/features/settings/components/sidebar.tsx index cdc0d27..6abfe59 100644 --- a/src/features/settings/components/sidebar.tsx +++ b/src/features/settings/components/sidebar.tsx @@ -1,6 +1,7 @@ import { AppInfo, LinkItemType } from "@/@types"; import { useLanguageContext } from "@/contexts/I18N"; -import { invoke } from "@/lib"; +import { useSettings } from "@/hooks"; +import { cn, invoke, shouldHideTitleBar } from "@/lib"; import { useQuery } from "@tanstack/react-query"; import { ReactElement } from "react"; import { FaDiscord, FaGithub } from "react-icons/fa6"; @@ -34,6 +35,7 @@ const SettingsSidebar = ({ settingsTabs: ReactElement[]; }) => { const { t } = useLanguageContext(); + const { settings } = useSettings(); const { data, isPending, isError } = useQuery({ queryKey: ["settings", "version"], @@ -44,9 +46,16 @@ const SettingsSidebar = ({ }); return ( -
+
-

+

{t("sections.settings")}

diff --git a/src/lib/helpers/helpers.ts b/src/lib/helpers/helpers.ts index 387573b..aadb8c2 100644 --- a/src/lib/helpers/helpers.ts +++ b/src/lib/helpers/helpers.ts @@ -1,3 +1,4 @@ +import { SettingsTitleBarStyle } from "@/@types"; import { Website } from "../api/igdb/types"; export const getSteamIdFromUrl = (url: string) => @@ -19,3 +20,7 @@ export const createSlug = (str: string) => { .replace(/[^\w ]+/g, "") .replace(/ +/g, "-"); }; + +export const shouldHideTitleBar = (titleBarStyle: SettingsTitleBarStyle) => { + return ["none", "native"].includes(titleBarStyle); +}; diff --git a/src/routes/__root.tsx b/src/routes/__root.tsx index 461e91e..128e488 100644 --- a/src/routes/__root.tsx +++ b/src/routes/__root.tsx @@ -3,7 +3,7 @@ import { TooltipProvider } from "@/components/ui/tooltip"; import NavBar from "@/features/navigation/components/navbar"; import Updater from "@/features/updater/components/updater"; import { useAppStartup, useSettings } from "@/hooks"; -import { cn } from "@/lib"; +import { cn, shouldHideTitleBar } from "@/lib"; import { createRootRoute, Outlet } from "@tanstack/react-router"; export const Route = createRootRoute({ @@ -26,7 +26,7 @@ function Root() {
{/* Sidebar navigation */} diff --git a/src/routes/settings.tsx b/src/routes/settings.tsx index 36b0eb5..bd9e58d 100644 --- a/src/routes/settings.tsx +++ b/src/routes/settings.tsx @@ -30,13 +30,13 @@ function RouteComponent() { ); return ( -
+
-
+
+
}