Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Improvement: mobile responsive fixes, sidebar cookies, and more (#528)

Ameer Al Ashhabfc4b4ab0196f
diff --git a/apps/web/app/dashboard/_components/AdminNavbar/AdminDesktopNav.tsx b/apps/web/app/dashboard/_components/AdminNavbar/AdminDesktopNav.tsx
index 07d749ed7..4a4210f56 100644
--- a/apps/web/app/dashboard/_components/AdminNavbar/AdminDesktopNav.tsx
+++ b/apps/web/app/dashboard/_components/AdminNavbar/AdminDesktopNav.tsx
@@ -6,18 +6,13 @@ import { motion } from "framer-motion";
import { useDetectPlatform } from "hooks/useDetectPlatform";
import { ChevronRight } from "lucide-react";
import Link from "next/link";
-import { useEffect, useState } from "react";
+import { useEffect } from "react";
+import { useSharedContext } from "../DynamicSharedLayout";
import { AdminNavItems } from "./AdminNavItems";
export const AdminDesktopNav = () => {
+ const { toggleSidebarCollapsed, sidebarCollapsed } = useSharedContext();
const { platform } = useDetectPlatform();
- const [sidebarCollapsed, setSidebarCollapsed] = useState(
- JSON.parse(localStorage.getItem("sidebarCollapsed") || "false")
- );
- const toggleCollapse = () => {
- setSidebarCollapsed(!sidebarCollapsed);
- localStorage.setItem("sidebarCollapsed", JSON.stringify(!sidebarCollapsed));
- };
const cmdSymbol = platform === "macos" ? "⌘" : "Ctrl";
useEffect(() => {
@@ -28,7 +23,7 @@ export const AdminDesktopNav = () => {
event.shiftKey
) {
event.preventDefault();
- toggleCollapse();
+ toggleSidebarCollapsed();
}
};
@@ -37,7 +32,7 @@ export const AdminDesktopNav = () => {
return () => {
window.removeEventListener("keydown", handleKeyDown);
};
- }, [toggleCollapse]);
+ }, [toggleSidebarCollapsed]);
return (
<>
@@ -68,7 +63,7 @@ export const AdminDesktopNav = () => {
/>
</Link>
</div>
- <AdminNavItems collapsed={sidebarCollapsed} />
+ <AdminNavItems />
</div>
</div>
@@ -79,7 +74,7 @@ export const AdminDesktopNav = () => {
content="Toggle collapse"
>
<button
- onClick={toggleCollapse}
+ onClick={toggleSidebarCollapsed}
className="absolute right-[-12px] hover:border-gray-5 hover:bg-gray-5 top-[50%] transform -translate-y-1/2 rounded-full p-1 border bg-gray-3 border-gray-4 transition-colors z-10"
>
<ChevronRight size={16} className={clsx("transition-transform duration-200 text-gray-12", sidebarCollapsed ? "rotate-180" : "")} />
diff --git a/apps/web/app/dashboard/_components/AdminNavbar/AdminMobileNav.tsx b/apps/web/app/dashboard/_components/AdminNavbar/AdminMobileNav.tsx
index 8248948f8..82c27b74f 100644
--- a/apps/web/app/dashboard/_components/AdminNavbar/AdminMobileNav.tsx
+++ b/apps/web/app/dashboard/_components/AdminNavbar/AdminMobileNav.tsx
@@ -18,13 +18,13 @@ export const AdminMobileNav = () => {
const { theme, setThemeHandler } = useTheme();
return (
<>
- <AnimatePresence mode="wait">
- {sidebarOpen && (
+ <AnimatePresence>
+ {sidebarOpen ? (
<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
- exit={{ opacity: 0 }}
- className="flex fixed inset-0 z-[1000000] lg:hidden bg-gray-1/50"
+ exit={{ opacity: 0, display: "none" }}
+ className="flex fixed inset-0 z-[60] lg:hidden bg-gray-1/50"
>
<motion.div
ref={sidebarRef}
@@ -42,10 +42,10 @@ export const AdminMobileNav = () => {
>
<X className="text-gray-12 size-7" aria-hidden="true" />
</div>
- <AdminNavItems />
+ <AdminNavItems toggleMobileNav={() => setSidebarOpen(false)} />
</motion.div>
</motion.div>
- )}
+ ) : null}
</AnimatePresence>
<div className="flex fixed z-50 justify-between w-full h-16 border-b border-gray-3 bg-gray-1 lg:border-none lg:hidden">
<div className="flex flex-shrink-0 items-center px-4 h-full lg:hidden">
diff --git a/apps/web/app/dashboard/_components/AdminNavbar/AdminNavItems.tsx b/apps/web/app/dashboard/_components/AdminNavbar/AdminNavItems.tsx
index 7a1d34cbb..bd3e9f36f 100644
--- a/apps/web/app/dashboard/_components/AdminNavbar/AdminNavItems.tsx
+++ b/apps/web/app/dashboard/_components/AdminNavbar/AdminNavItems.tsx
@@ -38,14 +38,18 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import clsx from "clsx";
import { motion } from "framer-motion";
import Image from "next/image";
-
+
import { useRef, useState } from "react";
import { updateActiveOrganization } from "./server";
-export const AdminNavItems = ({ collapsed }: { collapsed?: boolean }) => {
+interface Props {
+ toggleMobileNav?: () => void;
+}
+
+export const AdminNavItems = ({ toggleMobileNav }: Props) => {
const pathname = usePathname();
const [open, setOpen] = useState(false);
- const { user } =
+ const { user, sidebarCollapsed } =
useSharedContext();
const manageNavigation = [
@@ -99,7 +103,7 @@ export const AdminNavItems = ({ collapsed }: { collapsed?: boolean }) => {
<Dialog open={dialogOpen} onOpenChange={setDialogOpen}>
<Popover open={open} onOpenChange={setOpen}>
<Tooltip
- disable={open || collapsed === false}
+ disable={open || sidebarCollapsed === false}
position="right"
content={
activeOrg?.organization.name ?? "No organization found"
@@ -142,15 +146,15 @@ export const AdminNavItems = ({ collapsed }: { collapsed?: boolean }) => {
"No organization found"}
</p>
</div>
- {!collapsed && (
+ {!sidebarCollapsed && (
<ChevronDown className="w-5 h-auto text-gray-8" />
)}
</div>
</div>
<PopoverContent
className={clsx(
- "p-0 w-[calc(100%-12px)] z-[60]",
- collapsed ? "ml-3" : "mx-auto"
+ "p-0 w-full min-w-[287px] md:min-w-fit md:w-[calc(100%-12px)] z-[120]",
+ sidebarCollapsed ? "ml-3" : "mx-auto"
)}
>
<Command>
@@ -203,11 +207,11 @@ export const AdminNavItems = ({ collapsed }: { collapsed?: boolean }) => {
</CommandItem>
);
})}
- <DialogTrigger className="mt-3 w-full">
+ <DialogTrigger asChild>
<Button
variant="dark"
size="sm"
- className="flex gap-1 items-center w-full"
+ className="flex gap-1 items-center mt-3 w-full"
>
<Plus className="w-4 h-auto" />
Add new organization
@@ -225,19 +229,19 @@ export const AdminNavItems = ({ collapsed }: { collapsed?: boolean }) => {
aria-label="Sidebar"
>
<div
- className={clsx("mt-8 space-y-2.5", collapsed ? "items-center" : "")}
+ className={clsx("mt-8 space-y-2.5", sidebarCollapsed ? "items-center" : "")}
>
{manageNavigation.map((item) => (
<div key={item.name} className="flex relative justify-center">
{pathname.includes(item.href) ? (
<motion.div
initial={{
- width: collapsed ? 40 : "100%",
- height: collapsed ? 40 : "100%",
+ width: sidebarCollapsed ? 40 : "100%",
+ height: sidebarCollapsed ? 40 : "100%",
}}
animate={{
- width: collapsed ? 40 : "100%",
- height: collapsed ? 40 : "100%",
+ width: sidebarCollapsed ? 40 : "100%",
+ height: sidebarCollapsed ? 40 : "100%",
}}
transition={{
type: "spring",
@@ -254,11 +258,12 @@ export const AdminNavItems = ({ collapsed }: { collapsed?: boolean }) => {
) : null}
<Tooltip
content={item.name}
- disable={collapsed === false}
+ disable={sidebarCollapsed === false}
position="right"
>
<Link
passHref
+ onClick={() => toggleMobileNav?.()}
prefetch={false}
href={item.href}
className={classNames(
@@ -270,7 +275,7 @@ export const AdminNavItems = ({ collapsed }: { collapsed?: boolean }) => {
icon={item.icon as IconDefinition}
className={classNames(
"flex-shrink-0 w-5 h-5 transition-colors duration-200 stroke-[1.5px]",
- collapsed ? "text-gray-12" : "text-gray-10"
+ sidebarCollapsed ? "text-gray-12" : "text-gray-10"
)}
aria-hidden="true"
/>
@@ -284,7 +289,9 @@ export const AdminNavItems = ({ collapsed }: { collapsed?: boolean }) => {
</div>
<div className="pb-0 w-full lg:pb-5">
<UsageButton
- collapsed={collapsed ?? false}
+ toggleMobileNav={() =>
+ toggleMobileNav?.()
+ }
subscribed={userIsSubscribed}
/>
<p className="mt-4 text-xs text-center truncate text-gray-10">
diff --git a/apps/web/app/dashboard/_components/DashboardInner.tsx b/apps/web/app/dashboard/_components/DashboardInner.tsx
index 7f36ad5b6..cd7088382 100644
--- a/apps/web/app/dashboard/_components/DashboardInner.tsx
+++ b/apps/web/app/dashboard/_components/DashboardInner.tsx
@@ -46,14 +46,14 @@ export default function DashboardInner({
const title = titles[pathname] || "";
const { theme, setThemeHandler } = useTheme();
return (
- <div className="flex flex-col pt-5 min-h-screen lg:gap-5">
- {/* Top Bar */}
- <div
+ <div className="flex flex-col w-full h-full">
+ {/* Top Bar - Fixed at top with proper z-index */}
+ <header
className={clsx(
- "flex sticky z-50 justify-between items-center px-5 mt-10 w-full h-16 border-b bg-gray-1 lg:bg-transparent border-gray-3 lg:border-b-0 lg:pl-0 lg:pr-5 lg:top-0 lg:relative top-[64px] lg:mt-0 lg:h-8"
+ "flex sticky z-50 justify-between items-center px-5 mt-10 w-full h-16 border-b bg-gray-1 lg:bg-transparent border-gray-3 lg:border-b-0 lg:pl-0 lg:pr-5 lg:top-0 lg:relative top-[64px] lg:mt-5 lg:h-8"
)}
>
- <p className="relative text-xl text-gray-12 lg:text-2xl">{title}</p>
+ <p className="relative text-xl truncate text-gray-12 lg:text-2xl w-fit max-w-[150px]">{title}</p>
<div className="flex gap-4 items-center">
<div
onClick={() => {
@@ -68,15 +68,16 @@ export default function DashboardInner({
</div>
<User />
</div>
- </div>
- {/* Content Area */}
- <div
+ </header>
+ {/* Content Area - Scrollable content with proper spacing */}
+ <main
className={clsx(
- "flex overflow-y-auto flex-col flex-1 p-5 pb-5 border border-b-0 bg-gray-1 border-gray-3 lg:rounded-tl-2xl lg:p-8"
+ "flex overflow-y-auto flex-col flex-1 p-5 pb-5 border border-b-0 bg-gray-1 border-gray-3 lg:rounded-tl-2xl lg:p-8",
+ "mt-5 min-h-screen"
)}
>
- <div className="flex flex-col flex-1 gap-4 h-full">{children}</div>
- </div>
+ <div className="flex flex-col gap-4">{children}</div>
+ </main>
</div>
);
}
diff --git a/apps/web/app/dashboard/_components/DynamicSharedLayout.tsx b/apps/web/app/dashboard/_components/DynamicSharedLayout.tsx
index 3473575a1..3ace6bc82 100644
--- a/apps/web/app/dashboard/_components/DynamicSharedLayout.tsx
+++ b/apps/web/app/dashboard/_components/DynamicSharedLayout.tsx
@@ -1,9 +1,10 @@
"use client";
import AdminMobileNav from "@/app/dashboard/_components/AdminNavbar/AdminMobileNav";
import { Organization } from "@/app/dashboard/layout";
+import { UpgradeModal } from "@/components/UpgradeModal";
import { users } from "@cap/database/schema";
import Cookies from "js-cookie";
-import React, { createContext, useContext, useEffect, useState } from "react";
+import { createContext, useContext, useEffect, useState } from "react";
import AdminDesktopNav from "./AdminNavbar/AdminDesktopNav";
type SharedContext = {
@@ -11,6 +12,10 @@ type SharedContext = {
activeOrganization: Organization | null;
user: typeof users.$inferSelect;
isSubscribed: boolean;
+ toggleSidebarCollapsed: () => void;
+ sidebarCollapsed: boolean;
+ upgradeModalOpen: boolean;
+ setUpgradeModalOpen: (open: boolean) => void;
};
type ITheme = "light" | "dark";
@@ -34,6 +39,7 @@ export default function DynamicSharedLayout({
user,
isSubscribed,
initialTheme,
+ initialSidebarCollapsed,
}: {
children: React.ReactNode;
organizationData: SharedContext["organizationData"];
@@ -41,8 +47,11 @@ export default function DynamicSharedLayout({
user: SharedContext["user"];
isSubscribed: SharedContext["isSubscribed"];
initialTheme: ITheme;
+ initialSidebarCollapsed: boolean;
}) {
const [theme, setTheme] = useState<ITheme>(initialTheme);
+ const [sidebarCollapsed, setSidebarCollapsed] = useState(initialSidebarCollapsed);
+ const [upgradeModalOpen, setUpgradeModalOpen] = useState(false);
const setThemeHandler = (newTheme: ITheme) => {
setTheme(newTheme);
Cookies.set("theme", newTheme, {
@@ -54,10 +63,20 @@ export default function DynamicSharedLayout({
if (Cookies.get("theme")) {
document.body.className = Cookies.get("theme") as ITheme;
}
+ if (Cookies.get("sidebarCollapsed")) {
+ setSidebarCollapsed(Cookies.get("sidebarCollapsed") === "true");
+ }
return () => {
document.body.className = "light";
};
}, [theme]);
+ const toggleSidebarCollapsed = () => {
+ setSidebarCollapsed(!sidebarCollapsed);
+ Cookies.set("sidebarCollapsed", !sidebarCollapsed ? "true" : "false", {
+ expires: 365,
+ });
+ };
+
return (
<ThemeContext.Provider value={{ theme, setThemeHandler }}>
<Context.Provider
@@ -66,6 +85,10 @@ export default function DynamicSharedLayout({
activeOrganization,
user,
isSubscribed,
+ toggleSidebarCollapsed,
+ sidebarCollapsed,
+ upgradeModalOpen,
+ setUpgradeModalOpen
}}
>
{/* CSS Grid layout for dashboard */}
@@ -80,6 +103,12 @@ export default function DynamicSharedLayout({
<AdminMobileNav />
{children}
</div>
+
+ {/* Global upgrade modal that persists regardless of navigation state */}
+ <UpgradeModal
+ open={upgradeModalOpen}
+ onOpenChange={setUpgradeModalOpen}
+ />
</div>
</Context.Provider>
</ThemeContext.Provider>
diff --git a/apps/web/app/dashboard/layout.tsx b/apps/web/app/dashboard/layout.tsx
index a6687d88c..4511ca69e 100644
--- a/apps/web/app/dashboard/layout.tsx
+++ b/apps/web/app/dashboard/layout.tsx
@@ -157,6 +157,7 @@ export default async function DashboardLayout({
!!user.thirdPartyStripeSubscriptionId;
const theme = cookies().get("theme")?.value ?? "light";
+ const sidebar = cookies().get("sidebarCollapsed")?.value ?? "false";
return (
<DynamicSharedLayout
@@ -165,6 +166,7 @@ export default async function DashboardLayout({
user={user}
isSubscribed={isSubscribed}
initialTheme={theme as "light" | "dark"}
+ initialSidebarCollapsed={sidebar === "true"}
>
<div className="full-layout">
<DashboardTemplate>{children}</DashboardTemplate>
diff --git a/apps/web/app/s/[videoId]/_components/AuthOverlay.tsx b/apps/web/app/s/[videoId]/_components/AuthOverlay.tsx
index 2b043726c..e848e780b 100644
--- a/apps/web/app/s/[videoId]/_components/AuthOverlay.tsx
+++ b/apps/web/app/s/[videoId]/_components/AuthOverlay.tsx
@@ -10,7 +10,7 @@ interface AuthOverlayProps {
onClose: () => void;
}
-const MotionDialogContent = motion(DialogContent);
+const MotionDialogContent = motion.create(DialogContent);
export const AuthOverlay: React.FC<AuthOverlayProps> = ({
isOpen,
@@ -119,7 +119,7 @@ export const AuthOverlay: React.FC<AuthOverlayProps> = ({
toast.error("Error sending email - try again?");
}
})
- .catch((err) => {
+ .catch(() => {
setEmailSent(false);
setLoading(false);
toast.error("Error sending email - try again?");
diff --git a/apps/web/components/UsageButton.tsx b/apps/web/components/UsageButton.tsx
index abfcf0287..090ac11b3 100644
--- a/apps/web/components/UsageButton.tsx
+++ b/apps/web/components/UsageButton.tsx
@@ -1,20 +1,19 @@
+import { useSharedContext } from "@/app/dashboard/_components/DynamicSharedLayout";
import { Tooltip } from "@/components/Tooltip";
import { Button } from "@cap/ui";
import { faArrowUp, faCheck } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import clsx from "clsx";
import Link from "next/link";
-import { useState } from "react";
-import { UpgradeModal } from "./UpgradeModal";
export const UsageButton = ({
subscribed,
- collapsed,
+ toggleMobileNav,
}: {
subscribed: boolean;
- collapsed: boolean;
+ toggleMobileNav?: () => void;
}) => {
- const [upgradeModalOpen, setUpgradeModalOpen] = useState(false);
+ const { sidebarCollapsed, setUpgradeModalOpen } = useSharedContext();
if (subscribed) {
return (
@@ -27,7 +26,7 @@ export const UsageButton = ({
size="lg"
className={clsx(
"overflow-hidden truncate",
- collapsed ? "p-0 w-10 h-10 rounded-full min-w-10" : "w-full"
+ sidebarCollapsed ? "p-0 w-10 h-10 rounded-full min-w-10" : "w-full"
)}
variant="primary"
>
@@ -42,11 +41,11 @@ export const UsageButton = ({
<FontAwesomeIcon
className={clsx(
"text-gray-50 drop-shadow-[0_0_2px_rgba(255,255,255,0.5)]",
- collapsed ? "mr-0" : "mr-1"
+ sidebarCollapsed ? "mr-0" : "mr-1"
)}
icon={faCheck}
/>
- {collapsed ? null : (
+ {sidebarCollapsed ? null : (
<p className="text-gray-50 drop-shadow-[0_0_2px_rgba(255,255,255,0.5)]">
Cap Pro
</p>
@@ -65,10 +64,13 @@ export const UsageButton = ({
size="lg"
className={clsx(
"overflow-hidden truncate",
- collapsed ? "p-0 w-10 h-10 rounded-full min-w-10" : "w-full"
+ sidebarCollapsed ? "p-0 w-10 h-10 rounded-full min-w-10" : "w-full"
)}
variant="primary"
- onClick={() => setUpgradeModalOpen(true)}
+ onClick={() => {
+ setUpgradeModalOpen(true);
+ toggleMobileNav?.();
+ }}
>
<img
src="/illustrations/cloud-1.png"
@@ -81,11 +83,11 @@ export const UsageButton = ({
<FontAwesomeIcon
className={clsx(
"text-gray-50 drop-shadow-[0_0_2px_rgba(255,255,255,0.5)]",
- collapsed ? "mr-0" : "mr-1"
+ sidebarCollapsed ? "mr-0" : "mr-1"
)}
icon={faArrowUp}
/>
- {collapsed ? null : (
+ {sidebarCollapsed ? null : (
<p className="text-gray-50 drop-shadow-[0_0_2px_rgba(255,255,255,0.5)]">
Upgrade to Pro
</p>
@@ -93,10 +95,7 @@ export const UsageButton = ({
</Button>
</div>
</Tooltip>
- <UpgradeModal
- open={upgradeModalOpen}
- onOpenChange={setUpgradeModalOpen}
- />
+ {/* UpgradeModal is now rendered at the root level in DynamicSharedLayout */}
</>
);
};