feat(web): add back buttons for the pull requests and usage pages in the sidebar footer (#6031)
Co-authored-by: shivam <[email protected]>
This commit is contained in:
1 parent
220e573b14
commit
44621c345f
1 file changed
+48
-9
@@ -1,6 +1,11 @@
|
||||
import { ChartNoAxesColumnIcon, GitPullRequestIcon, SettingsIcon } from "lucide-react";
|
||||
import {
|
||||
ArrowLeftIcon,
|
||||
ChartNoAxesColumnIcon,
|
||||
GitPullRequestIcon,
|
||||
SettingsIcon,
|
||||
} from "lucide-react";
|
||||
import { memo, useCallback } from "react";
|
||||
import { Link, useNavigate } from "@tanstack/react-router";
|
||||
import { Link, useCanGoBack, useLocation, useNavigate } from "@tanstack/react-router";
|
||||
|
||||
import { useEnvironmentIdentificationMode } from "../../hooks/useSettings";
|
||||
import { cn } from "../../lib/utils";
|
||||
@@ -114,6 +119,15 @@ function T3Wordmark() {
|
||||
export const SidebarChromeFooter = memo(function SidebarChromeFooter() {
|
||||
const navigate = useNavigate();
|
||||
const { isMobile, setOpenMobile } = useSidebar();
|
||||
const canGoBack = useCanGoBack();
|
||||
const currentFooterPage = useLocation({
|
||||
select: (location) =>
|
||||
location.pathname === "/usage"
|
||||
? "usage"
|
||||
: location.pathname === "/pull-requests"
|
||||
? "pull-requests"
|
||||
: null,
|
||||
});
|
||||
const primaryEnvironment = usePrimaryEnvironment();
|
||||
const pullRequestsSupported =
|
||||
primaryEnvironment?.serverConfig?.environment.capabilities.pullRequests === true;
|
||||
@@ -138,12 +152,28 @@ export const SidebarChromeFooter = memo(function SidebarChromeFooter() {
|
||||
void navigate({ to: "/usage" });
|
||||
}, [isMobile, navigate, setOpenMobile]);
|
||||
|
||||
const handleBackClick = useCallback(() => {
|
||||
closeMobileSidebar();
|
||||
if (canGoBack) {
|
||||
window.history.back();
|
||||
return;
|
||||
}
|
||||
void navigate({ to: "/" });
|
||||
}, [canGoBack, closeMobileSidebar, navigate]);
|
||||
|
||||
return (
|
||||
<SidebarFooter className="p-[var(--sidebar-content-inset)]">
|
||||
<SidebarProviderUpdatePill />
|
||||
<SidebarUpdatePill />
|
||||
<SidebarMenu>
|
||||
{pullRequestsSupported ? (
|
||||
{currentFooterPage === "pull-requests" ? (
|
||||
<SidebarMenuItem>
|
||||
<SidebarMenuButton onClick={handleBackClick}>
|
||||
<ArrowLeftIcon />
|
||||
<span>Back</span>
|
||||
</SidebarMenuButton>
|
||||
</SidebarMenuItem>
|
||||
) : pullRequestsSupported ? (
|
||||
<SidebarMenuItem>
|
||||
<SidebarMenuButton onClick={handlePullRequestsClick}>
|
||||
<GitPullRequestIcon />
|
||||
@@ -151,12 +181,21 @@ export const SidebarChromeFooter = memo(function SidebarChromeFooter() {
|
||||
</SidebarMenuButton>
|
||||
</SidebarMenuItem>
|
||||
) : null}
|
||||
<SidebarMenuItem>
|
||||
<SidebarMenuButton onClick={handleUsageClick}>
|
||||
<ChartNoAxesColumnIcon />
|
||||
<span>Usage</span>
|
||||
</SidebarMenuButton>
|
||||
</SidebarMenuItem>
|
||||
{currentFooterPage === "usage" ? (
|
||||
<SidebarMenuItem>
|
||||
<SidebarMenuButton onClick={handleBackClick}>
|
||||
<ArrowLeftIcon />
|
||||
<span>Back</span>
|
||||
</SidebarMenuButton>
|
||||
</SidebarMenuItem>
|
||||
) : (
|
||||
<SidebarMenuItem>
|
||||
<SidebarMenuButton onClick={handleUsageClick}>
|
||||
<ChartNoAxesColumnIcon />
|
||||
<span>Usage</span>
|
||||
</SidebarMenuButton>
|
||||
</SidebarMenuItem>
|
||||
)}
|
||||
<SidebarMenuItem>
|
||||
<SidebarMenuButton onClick={handleSettingsClick}>
|
||||
<SettingsIcon />
|
||||
|
||||
Reference in new issue
Block a user