mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-03 09:16:40 +00:00
auto collapse sidebar on small screens
This commit is contained in:
@@ -30,6 +30,7 @@ export async function Layout({
|
|||||||
}: LayoutProps) {
|
}: LayoutProps) {
|
||||||
const allCookies = await cookies();
|
const allCookies = await cookies();
|
||||||
const sidebarStateCookie = allCookies.get("pangolin-sidebar-state")?.value;
|
const sidebarStateCookie = allCookies.get("pangolin-sidebar-state")?.value;
|
||||||
|
const hasCookiePreference = sidebarStateCookie !== undefined;
|
||||||
|
|
||||||
const initialSidebarCollapsed =
|
const initialSidebarCollapsed =
|
||||||
sidebarStateCookie === "collapsed" ||
|
sidebarStateCookie === "collapsed" ||
|
||||||
@@ -44,6 +45,7 @@ export async function Layout({
|
|||||||
orgs={orgs}
|
orgs={orgs}
|
||||||
navItems={navItems}
|
navItems={navItems}
|
||||||
defaultSidebarCollapsed={initialSidebarCollapsed}
|
defaultSidebarCollapsed={initialSidebarCollapsed}
|
||||||
|
hasCookiePreference={hasCookiePreference}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|||||||
@@ -43,17 +43,20 @@ interface LayoutSidebarProps {
|
|||||||
orgs?: ListUserOrgsResponse["orgs"];
|
orgs?: ListUserOrgsResponse["orgs"];
|
||||||
navItems: SidebarNavSection[];
|
navItems: SidebarNavSection[];
|
||||||
defaultSidebarCollapsed: boolean;
|
defaultSidebarCollapsed: boolean;
|
||||||
|
hasCookiePreference: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function LayoutSidebar({
|
export function LayoutSidebar({
|
||||||
orgId,
|
orgId,
|
||||||
orgs,
|
orgs,
|
||||||
navItems,
|
navItems,
|
||||||
defaultSidebarCollapsed
|
defaultSidebarCollapsed,
|
||||||
|
hasCookiePreference
|
||||||
}: LayoutSidebarProps) {
|
}: LayoutSidebarProps) {
|
||||||
const [isSidebarCollapsed, setIsSidebarCollapsed] = useState(
|
const [isSidebarCollapsed, setIsSidebarCollapsed] = useState(
|
||||||
defaultSidebarCollapsed
|
defaultSidebarCollapsed
|
||||||
);
|
);
|
||||||
|
const [hasManualToggle, setHasManualToggle] = useState(hasCookiePreference);
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
const isAdminPage = pathname?.startsWith("/admin");
|
const isAdminPage = pathname?.startsWith("/admin");
|
||||||
const { user } = useUserContext();
|
const { user } = useUserContext();
|
||||||
@@ -72,6 +75,27 @@ export function LayoutSidebar({
|
|||||||
setSidebarStateCookie(isSidebarCollapsed);
|
setSidebarStateCookie(isSidebarCollapsed);
|
||||||
}, [isSidebarCollapsed]);
|
}, [isSidebarCollapsed]);
|
||||||
|
|
||||||
|
// Auto-collapse sidebar at 1650px or less, but only if no cookie preference exists
|
||||||
|
useEffect(() => {
|
||||||
|
if (hasManualToggle) {
|
||||||
|
return; // Don't auto-collapse if user has manually toggled
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleResize = () => {
|
||||||
|
// print inner width
|
||||||
|
if (typeof window !== "undefined") {
|
||||||
|
const shouldCollapse = window.innerWidth <= 1650;
|
||||||
|
setIsSidebarCollapsed(shouldCollapse);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Set initial state based on window width
|
||||||
|
handleResize();
|
||||||
|
|
||||||
|
window.addEventListener("resize", handleResize);
|
||||||
|
return () => window.removeEventListener("resize", handleResize);
|
||||||
|
}, [hasManualToggle]);
|
||||||
|
|
||||||
function loadFooterLinks(): { text: string; href?: string }[] | undefined {
|
function loadFooterLinks(): { text: string; href?: string }[] | undefined {
|
||||||
if (!isUnlocked()) {
|
if (!isUnlocked()) {
|
||||||
return undefined;
|
return undefined;
|
||||||
@@ -230,9 +254,10 @@ export function LayoutSidebar({
|
|||||||
<Tooltip>
|
<Tooltip>
|
||||||
<TooltipTrigger asChild>
|
<TooltipTrigger asChild>
|
||||||
<button
|
<button
|
||||||
onClick={() =>
|
onClick={() => {
|
||||||
setIsSidebarCollapsed(!isSidebarCollapsed)
|
setIsSidebarCollapsed(!isSidebarCollapsed);
|
||||||
}
|
setHasManualToggle(true);
|
||||||
|
}}
|
||||||
className="cursor-pointer absolute -right-2.5 top-1/2 transform -translate-y-1/2 w-2 h-8 rounded-full flex items-center justify-center transition-all duration-200 ease-in-out hover:scale-110 group z-1"
|
className="cursor-pointer absolute -right-2.5 top-1/2 transform -translate-y-1/2 w-2 h-8 rounded-full flex items-center justify-center transition-all duration-200 ease-in-out hover:scale-110 group z-1"
|
||||||
aria-label={
|
aria-label={
|
||||||
isSidebarCollapsed
|
isSidebarCollapsed
|
||||||
|
|||||||
@@ -55,7 +55,6 @@ export function SubscriptionStatusProvider({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("No matching tier found");
|
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user