Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Move Dashboard Inner to Layout (#469)

Ameer Al Ashhabbe7ae4a13fd6
diff --git a/apps/web/app/dashboard/_components/AdminNavbar/AdminNavItems.tsx b/apps/web/app/dashboard/_components/AdminNavbar/AdminNavItems.tsx
index 3b4e495b4..86c04679a 100644
--- a/apps/web/app/dashboard/_components/AdminNavbar/AdminNavItems.tsx
+++ b/apps/web/app/dashboard/_components/AdminNavbar/AdminNavItems.tsx
@@ -37,6 +37,7 @@ import {
} from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import clsx from "clsx";
+import { motion } from "framer-motion";
import { updateActiveSpace } from "./server";
export const AdminNavItems = ({ collapsed }: { collapsed?: boolean }) => {
@@ -173,7 +174,16 @@ export const AdminNavItems = ({ collapsed }: { collapsed?: boolean }) => {
className={clsx("mt-8 space-y-2.5", collapsed ? "items-center" : "")}
>
{manageNavigation.map((item) => (
- <div key={item.name} className="flex justify-center">
+ <div key={item.name} className="flex relative justify-center">
+ {pathname.includes(item.href) ? (
+ <motion.div
+ layoutId="underline"
+ id="underline"
+ className="bg-transparent size-10 mx-auto inset-0
+ rounded-xl text-gray-400 absolute border-[1px] border-gray-200
+ shadow-sm shadow-gray-200"
+ />
+ ) : null}
<Tooltip
content={item.name}
disable={collapsed === false}
@@ -183,12 +193,7 @@ export const AdminNavItems = ({ collapsed }: { collapsed?: boolean }) => {
passHref
prefetch={false}
href={item.href}
- className={classNames(
- pathname.includes(item.href)
- ? "bg-white text-gray-400 border-[1px] border-gray-200 shadow-sm shadow-gray-200"
- : "hover:opacity-75",
- navItemClass
- )}
+ className={classNames("hover:opacity-75", navItemClass)}
>
<FontAwesomeIcon
icon={item.icon as IconDefinition}
diff --git a/apps/web/app/dashboard/_components/DashboardInner.tsx b/apps/web/app/dashboard/_components/DashboardInner.tsx
index 7957436dd..617bd84c9 100644
--- a/apps/web/app/dashboard/_components/DashboardInner.tsx
+++ b/apps/web/app/dashboard/_components/DashboardInner.tsx
@@ -22,18 +22,21 @@ import { Avatar } from "@/app/s/[videoId]/_components/tabs/Activity";
import clsx from "clsx";
import { signOut } from "next-auth/react";
import Link from "next/link";
+import { usePathname } from "next/navigation";
export default function DashboardInner({
children,
- title,
- emptyCondition,
- emptyComponent,
}: {
children: React.ReactNode;
- title?: string;
- emptyCondition?: boolean;
- emptyComponent?: React.ReactNode;
}) {
+ const pathname = usePathname();
+ const titles: Record<string, string> = {
+ "/dashboard/caps": "Caps",
+ "/dashboard/shared-caps": "Shared Caps",
+ "/dashboard/settings/workspace": "Workspace Settings",
+ "/dashboard/settings/account": "Account Settings",
+ };
+ const title = titles[pathname] || "";
return (
<div className="flex flex-col pt-5 min-h-screen lg:gap-5">
{/* Top Bar */}
@@ -51,11 +54,7 @@ export default function DashboardInner({
"flex overflow-auto flex-col flex-1 p-5 pb-5 bg-gray-100 border border-gray-200 lg:rounded-tl-2xl lg:p-8"
)}
>
- {emptyCondition ? (
- emptyComponent
- ) : (
- <div className="flex flex-col gap-4">{children}</div>
- )}
+ <div className="flex flex-col gap-4">{children}</div>
</div>
</div>
);
diff --git a/apps/web/app/dashboard/caps/Caps.tsx b/apps/web/app/dashboard/caps/Caps.tsx
index 9ed45c834..de0033bdd 100644
--- a/apps/web/app/dashboard/caps/Caps.tsx
+++ b/apps/web/app/dashboard/caps/Caps.tsx
@@ -5,7 +5,6 @@ import { VideoMetadata } from "@cap/database/types";
import { useRouter, useSearchParams } from "next/navigation";
import { useEffect, useState } from "react";
import toast from "react-hot-toast";
-import DashboardInner from "../_components/DashboardInner";
import { CapCard } from "./components/CapCard";
import { CapPagination } from "./components/CapPagination";
import { EmptyCapState } from "./components/EmptyCapState";
@@ -80,31 +79,29 @@ export const Caps = ({
}
};
+ if (data.length === 0) {
+ return <EmptyCapState />;
+ }
+
return (
- <DashboardInner
- title="My Caps"
- emptyCondition={data.length === 0}
- emptyComponent={<EmptyCapState userName={user?.name || ""} />}
- >
- <div className="flex flex-col w-full">
- <div className="grid grid-cols-1 gap-4 sm:gap-6 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5">
- {data.map((cap) => (
- <CapCard
- key={cap.id}
- cap={cap}
- analytics={analytics[cap.id] || 0}
- onDelete={deleteCap}
- userId={user?.id}
- userSpaces={userSpaces}
- />
- ))}
- </div>
- {(data.length > limit || data.length === limit || page !== 1) && (
- <div className="mt-10">
- <CapPagination currentPage={page} totalPages={totalPages} />
- </div>
- )}
+ <div className="flex flex-col w-full">
+ <div className="grid grid-cols-1 gap-4 sm:gap-6 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5">
+ {data.map((cap) => (
+ <CapCard
+ key={cap.id}
+ cap={cap}
+ analytics={analytics[cap.id] || 0}
+ onDelete={deleteCap}
+ userId={user?.id}
+ userSpaces={userSpaces}
+ />
+ ))}
</div>
- </DashboardInner>
+ {(data.length > limit || data.length === limit || page !== 1) && (
+ <div className="mt-10">
+ <CapPagination currentPage={page} totalPages={totalPages} />
+ </div>
+ )}
+ </div>
);
};
diff --git a/apps/web/app/dashboard/caps/page.tsx b/apps/web/app/dashboard/caps/page.tsx
index de61d4dca..0cdb4054a 100644
--- a/apps/web/app/dashboard/caps/page.tsx
+++ b/apps/web/app/dashboard/caps/page.tsx
@@ -1,17 +1,17 @@
-import { Caps } from "./Caps";
import { db } from "@cap/database";
+import { getCurrentUser } from "@cap/database/auth/session";
import {
comments,
- videos,
sharedVideos,
+ spaceMembers,
spaces,
users,
- spaceMembers,
+ videos,
} from "@cap/database/schema";
-import { desc, eq, sql, count, or } from "drizzle-orm";
-import { getCurrentUser } from "@cap/database/auth/session";
+import { count, desc, eq, sql } from "drizzle-orm";
import { Metadata } from "next";
import { redirect } from "next/navigation";
+import { Caps } from "./Caps";
export const metadata: Metadata = {
title: "My Caps — Cap",
diff --git a/apps/web/app/dashboard/settings/layout.tsx b/apps/web/app/dashboard/settings/layout.tsx
deleted file mode 100644
index 5ce1df5a7..000000000
--- a/apps/web/app/dashboard/settings/layout.tsx
+++ /dev/null
@@ -1,11 +0,0 @@
-"use client";
-
-import DashboardInner from "../_components/DashboardInner";
-
-export default function DashboardLayout({
- children,
-}: {
- children: React.ReactNode;
-}) {
- return <DashboardInner title="Settings">{children}</DashboardInner>;
-}
diff --git a/apps/web/app/dashboard/shared-caps/SharedCaps.tsx b/apps/web/app/dashboard/shared-caps/SharedCaps.tsx
index 3cd766b60..3dc6336e6 100644
--- a/apps/web/app/dashboard/shared-caps/SharedCaps.tsx
+++ b/apps/web/app/dashboard/shared-caps/SharedCaps.tsx
@@ -4,7 +4,6 @@ import { useSharedContext } from "@/app/dashboard/_components/DynamicSharedLayou
import { VideoMetadata } from "@cap/database/types";
import { useSearchParams } from "next/navigation";
import { useEffect, useState } from "react";
-import DashboardInner from "../_components/DashboardInner";
import { CapPagination } from "../caps/components/CapPagination";
import { EmptySharedCapState } from "./components/EmptySharedCapState";
import { SharedCapCard } from "./components/SharedCapCard";
@@ -48,31 +47,27 @@ export const SharedCaps = ({
fetchAnalytics();
}, [data]);
+ if (data.length === 0) {
+ return <EmptySharedCapState spaceName={activeSpace?.space.name || ""} />;
+ }
+
return (
- <DashboardInner
- title="Shared Caps"
- emptyCondition={data.length === 0}
- emptyComponent={
- <EmptySharedCapState spaceName={activeSpace?.space.name || ""} />
- }
- >
- <div className="flex flex-col w-full h-full">
- <div className="grid grid-cols-1 gap-4 sm:gap-6 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5">
- {data.map((cap) => (
- <SharedCapCard
- key={cap.id}
- cap={cap}
- analytics={analytics[cap.id] || 0}
- spaceName={activeSpace?.space.name || ""}
- />
- ))}
- </div>
- {(data.length > limit || data.length === limit || page !== 1) && (
- <div className="mt-4">
- <CapPagination currentPage={page} totalPages={totalPages} />
- </div>
- )}
+ <div className="flex flex-col w-full h-full">
+ <div className="grid grid-cols-1 gap-4 sm:gap-6 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5">
+ {data.map((cap) => (
+ <SharedCapCard
+ key={cap.id}
+ cap={cap}
+ analytics={analytics[cap.id] || 0}
+ spaceName={activeSpace?.space.name || ""}
+ />
+ ))}
</div>
- </DashboardInner>
+ {(data.length > limit || data.length === limit || page !== 1) && (
+ <div className="mt-4">
+ <CapPagination currentPage={page} totalPages={totalPages} />
+ </div>
+ )}
+ </div>
);
};
diff --git a/apps/web/components/templates/DashboardTemplate.tsx b/apps/web/components/templates/DashboardTemplate.tsx
index 9e13e727b..d3428a4fb 100644
--- a/apps/web/components/templates/DashboardTemplate.tsx
+++ b/apps/web/components/templates/DashboardTemplate.tsx
@@ -1,15 +1,17 @@
"use client";
+import DashboardInner from "@/app/dashboard/_components/DashboardInner";
+
export const DashboardTemplate = ({
- title,
- description,
- button,
children,
}: {
- title?: string;
- description?: string;
- button?: React.ReactNode;
children?: React.ReactNode;
}) => {
- return <div className="dashboard-page">{children && children}</div>;
+ return (
+ <div className="dashboard-page">
+ <DashboardInner emptyComponent={children}>
+ {children && children}
+ </DashboardInner>
+ </div>
+ );
};
diff --git a/packages/ui/src/components/SkeletonRows.tsx b/packages/ui/src/components/SkeletonRows.tsx
index a2585068f..8b08c800b 100644
--- a/packages/ui/src/components/SkeletonRows.tsx
+++ b/packages/ui/src/components/SkeletonRows.tsx
@@ -5,18 +5,9 @@ import "react-loading-skeleton/dist/skeleton.css";
export const SkeletonRows = () => {
return (
- <div className="flex flex-col pt-5 min-h-screen lg:gap-5">
- {/* Top Bar */}
- <div className="flex sticky z-10 justify-between items-center px-5 mt-10 w-full h-16 bg-gray-50 border-b border-gray-200 lg:border-b-0 lg:pl-0 lg:pr-5 lg:top-0 lg:relative top-[64px] lg:mt-0 lg:h-8">
- <Skeleton
- count={1}
- containerClassName="w-full"
- className="bg-gray-500 h-[30px] w-full max-w-[200px]"
- />
- <Skeleton count={1} className="bg-gray-500 h-[30px] w-[100px]" />
- </div>
+ <div className="flex flex-col min-h-screen lg:gap-5">
{/* Content Area */}
- <div className="flex overflow-auto flex-col flex-1 p-5 pb-5 bg-gray-100 border border-gray-200 lg:rounded-tl-2xl lg:p-8">
+ <div className="flex overflow-auto flex-col flex-1 bg-gray-100 lg:rounded-tl-2xl">
<div className="flex flex-col w-full">
<div className="grid grid-cols-1 gap-4 sm:gap-6 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5">
{Array(15)
@@ -36,7 +27,7 @@ export const SkeletonRows = () => {
</div>
{/* Analytics */}
- <div className="flex flex-wrap gap-3 items-center text-sm mt-auto">
+ <div className="flex flex-wrap gap-3 items-center mt-auto text-sm">
{/* Views */}
<div className="flex gap-1 items-center">
<Skeleton circle width={16} height={16} />
@@ -60,7 +51,7 @@ export const SkeletonRows = () => {
</div>
{/* Pagination */}
- <div className="mt-10 flex justify-center">
+ <div className="flex justify-center mt-10">
<Skeleton className="h-[36px] w-[300px]" />
</div>
</div>