From c5005be2cb2e41708cf2b31cbecdda3d7dd6ad20 Mon Sep 17 00:00:00 2001 From: Rajpreet0 Date: Sun, 27 Sep 2026 16:06:22 +0200 Subject: [PATCH] see comments --- .github/workflows/ci.yml | 36 +++++++++++++++++++ app/admin/layout.tsx | 6 ++-- app/client/layout.tsx | 6 ++-- hooks/use-mobile.ts | 30 ++++++++-------- modules/shared/ui/components/app-sidebar.tsx | 4 ++- .../ui/components/sidebar-menu-link.tsx | 5 +-- 6 files changed, 66 insertions(+), 21 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..a9a1c06 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,36 @@ +name: CI + +on: + pull_request: + branches: [dev] + push: + branches: [main] + +jobs: + ci: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: 22 + cache: npm + + - name: Install dependencies + run: npm ci + + - name: Lint + run: npm run lint + + - name: Type check + run: npx tsc --noEmit + + - name: Build + run: npm run build + env: + NEXT_PUBLIC_SUPABASE_URL: ${{ secrets.NEXT_PUBLIC_SUPABASE_URL }} + NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY: ${{ secrets.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY }} + SUPABASE_SECRET_KEY: ${{ secrets.SUPABASE_SECRET_KEY }} \ No newline at end of file diff --git a/app/admin/layout.tsx b/app/admin/layout.tsx index 5221208..18b7698 100644 --- a/app/admin/layout.tsx +++ b/app/admin/layout.tsx @@ -1,3 +1,4 @@ +import { cookies } from "next/headers"; import { SidebarProvider, SidebarTrigger } from "@/components/ui/sidebar"; import { verifySession } from "@/lib/supabase/dal"; import { AppSidebar } from "@/modules/shared/ui/components/app-sidebar"; @@ -5,10 +6,11 @@ import { AppSidebar } from "@/modules/shared/ui/components/app-sidebar"; export default async function AdminLayout({ children }: { children: React.ReactNode }) { const session = await verifySession() - + const cookieStore = await cookies() + const defaultOpen = cookieStore.get("sidebar_state")?.value !== "false" return ( - +
diff --git a/app/client/layout.tsx b/app/client/layout.tsx index 2ef6f50..41d181e 100644 --- a/app/client/layout.tsx +++ b/app/client/layout.tsx @@ -1,3 +1,4 @@ +import { cookies } from "next/headers"; import { SidebarProvider, SidebarTrigger } from "@/components/ui/sidebar"; import { verifySession } from "@/lib/supabase/dal"; import { AppSidebar } from "@/modules/shared/ui/components/app-sidebar"; @@ -5,10 +6,11 @@ import { AppSidebar } from "@/modules/shared/ui/components/app-sidebar"; export default async function ClientLayout({ children }: { children: React.ReactNode }) { const session = await verifySession() - + const cookieStore = await cookies() + const defaultOpen = cookieStore.get("sidebar_state")?.value !== "false" return ( - +
diff --git a/hooks/use-mobile.ts b/hooks/use-mobile.ts index 2b0fe1d..64eaff6 100644 --- a/hooks/use-mobile.ts +++ b/hooks/use-mobile.ts @@ -2,18 +2,20 @@ import * as React from "react" const MOBILE_BREAKPOINT = 768 -export function useIsMobile() { - const [isMobile, setIsMobile] = React.useState(undefined) - - React.useEffect(() => { - const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`) - const onChange = () => { - setIsMobile(window.innerWidth < MOBILE_BREAKPOINT) - } - mql.addEventListener("change", onChange) - setIsMobile(window.innerWidth < MOBILE_BREAKPOINT) - return () => mql.removeEventListener("change", onChange) - }, []) - - return !!isMobile +function subscribe(callback: () => void) { + const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`) + mql.addEventListener("change", callback) + return () => mql.removeEventListener("change", callback) +} + +function getSnapshot() { + return window.innerWidth < MOBILE_BREAKPOINT +} + +function getServerSnapshot() { + return false +} + +export function useIsMobile() { + return React.useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot) } diff --git a/modules/shared/ui/components/app-sidebar.tsx b/modules/shared/ui/components/app-sidebar.tsx index f18ed93..b7a287b 100644 --- a/modules/shared/ui/components/app-sidebar.tsx +++ b/modules/shared/ui/components/app-sidebar.tsx @@ -6,6 +6,7 @@ import { SidebarGroupContent, SidebarHeader, SidebarMenu, + SidebarRail, } from "@/components/ui/sidebar"; import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; import { Session } from "../../types/user"; @@ -16,7 +17,7 @@ import UserBadge from "./user-badge"; export function AppSidebar({ session }: { session: Session }) { const menu = session.isAdmin ? adminMenu : clientMenu; - const avatarUrl = `https://api.dicebear.com/10.x/waves/svg?seed=${encodeURIComponent(session.email)}`; + const avatarUrl = `https://api.dicebear.com/10.x/waves/svg?seed=${encodeURIComponent(session.userId)}`; return ( @@ -52,6 +53,7 @@ export function AppSidebar({ session }: { session: Session }) {

{session.email}

+
) } \ No newline at end of file diff --git a/modules/shared/ui/components/sidebar-menu-link.tsx b/modules/shared/ui/components/sidebar-menu-link.tsx index 54e0be6..167d91d 100644 --- a/modules/shared/ui/components/sidebar-menu-link.tsx +++ b/modules/shared/ui/components/sidebar-menu-link.tsx @@ -2,7 +2,7 @@ import Link from "next/link"; import { usePathname } from "next/navigation"; -import { SidebarMenuButton, SidebarMenuItem } from "@/components/ui/sidebar"; +import { SidebarMenuButton, SidebarMenuItem, useSidebar } from "@/components/ui/sidebar"; export function SidebarMenuLink({ title, @@ -14,12 +14,13 @@ export function SidebarMenuLink({ icon: React.ReactNode; }) { const pathname = usePathname(); + const { setOpenMobile } = useSidebar(); const isActive = pathname === url; return ( } + render={ setOpenMobile(false)} />} isActive={isActive} className="h-10 text-[0.95rem]" >