diff --git a/app/(dashboard)/layout.tsx b/app/(dashboard)/layout.tsx index b877a9f..28325d7 100644 --- a/app/(dashboard)/layout.tsx +++ b/app/(dashboard)/layout.tsx @@ -1,11 +1,14 @@ import Navbar from "@/components/navbar"; import { Sidebar } from "@/components/sidebar"; +import { getApiLimitCount } from "@/lib/api-limit"; const DashboardLayout = async ({ children }: { children: React.ReactNode }) => { + const apiLimitCount = await getApiLimitCount(); + return (
- +
diff --git a/app/globals.css b/app/globals.css index 9e5deb1..a692cec 100644 --- a/app/globals.css +++ b/app/globals.css @@ -25,7 +25,7 @@ body, --border: 220 13% 91%; --input: 220 13% 91%; - --primary: 220.9 39.3% 11%; + --primary: 248 90% 66%; --primary-foreground: 210 20% 98%; --secondary: 220 14.3% 95.9%; diff --git a/components/free-counter.tsx b/components/free-counter.tsx new file mode 100644 index 0000000..97b11bb --- /dev/null +++ b/components/free-counter.tsx @@ -0,0 +1,45 @@ +'use client' + +import { Zap } from "lucide-react"; +import { useEffect, useState } from "react"; + +import { Button } from "@/components/ui/button"; +import { Card, CardContent } from "@/components/ui/card"; +import { Progress } from "@/components/ui/progress"; +import { MAX_FREE_COUNTS } from "@/constants"; +// import { useProModal } from "@/hooks/use-pro-modal"; + +interface FreeCounterProps { + isPro?: boolean; + apiLimitCount: number; +} + +export const FreeCounter: React.FC = ({ isPro = false, apiLimitCount = 0 }) => { + const [mounted, setMounted] = useState(false); + // const proModal = useProModal(); + + useEffect(() => setMounted(true), []); + + if (!mounted) return null + + if (isPro) return null + + return ( +
+ + +
+

+ {apiLimitCount} / {MAX_FREE_COUNTS} Free Generations +

+ +
+ +
+
+
+ ) +} \ No newline at end of file diff --git a/components/mobile-sidebar.tsx b/components/mobile-sidebar.tsx index 88bee20..8e162f2 100644 --- a/components/mobile-sidebar.tsx +++ b/components/mobile-sidebar.tsx @@ -7,7 +7,11 @@ import { Button } from "@/components/ui/button"; import { Sheet, SheetContent, SheetTrigger } from "@/components/ui/sheet"; import { Sidebar } from "@/components/sidebar"; -export const MobileSidebar = () => { +interface MobileSidebarProps { + apiLimitCount: number +} + +export const MobileSidebar: React.FC = ({ apiLimitCount }) => { const [isMounted, setIsMounted] = useState(false); useEffect(() => setIsMounted(true), []); @@ -22,7 +26,7 @@ export const MobileSidebar = () => { - + ); diff --git a/components/navbar.tsx b/components/navbar.tsx index b0b1d95..1427536 100644 --- a/components/navbar.tsx +++ b/components/navbar.tsx @@ -1,12 +1,14 @@ import { UserButton } from "@clerk/nextjs"; import { MobileSidebar } from "@/components/mobile-sidebar"; +import { getApiLimitCount } from "@/lib/api-limit"; const Navbar: React.FC = async () => { + const apiLimitCount = await getApiLimitCount(); return (
- +
diff --git a/components/sidebar.tsx b/components/sidebar.tsx index 7c03ae0..4466310 100644 --- a/components/sidebar.tsx +++ b/components/sidebar.tsx @@ -8,6 +8,8 @@ import { usePathname } from "next/navigation"; import { cn } from "@/lib/utils"; +import { FreeCounter } from "./free-counter"; + const montserrat = Montserrat({ weight: '600', subsets: ['latin'] }); const routes = [ @@ -54,7 +56,11 @@ const routes = [ }, ]; -export const Sidebar = () => { +interface SidebarProps { + apiLimitCount: number; +} + +export const Sidebar: React.FC = ({ apiLimitCount = 0 }) => { const pathname = usePathname(); return ( @@ -86,6 +92,11 @@ export const Sidebar = () => { ))}
+ + ); }; diff --git a/components/ui/progress.tsx b/components/ui/progress.tsx new file mode 100644 index 0000000..999c785 --- /dev/null +++ b/components/ui/progress.tsx @@ -0,0 +1,28 @@ +"use client" + +import * as React from "react" +import * as ProgressPrimitive from "@radix-ui/react-progress" + +import { cn } from "@/lib/utils" + +const Progress = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, value, ...props }, ref) => ( + + + +)) +Progress.displayName = ProgressPrimitive.Root.displayName + +export { Progress }