Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Refactor dashboard analytics and navbar UI

Richie McIlroyabfbad82a91c
diff --git a/apps/web/app/(org)/dashboard/_components/Navbar/Desktop.tsx b/apps/web/app/(org)/dashboard/_components/Navbar/Desktop.tsx
index e683f4dd3..237571194 100644
--- a/apps/web/app/(org)/dashboard/_components/Navbar/Desktop.tsx
+++ b/apps/web/app/(org)/dashboard/_components/Navbar/Desktop.tsx
@@ -46,39 +46,45 @@ export const DesktopNav = () => {
)}
>
<div className="flex flex-col mx-auto w-full h-full">
- <div className="flex justify-start items-center px-3 pt-5 mb-3.5 w-full truncate min-h-8">
+ <div className="flex justify-between items-center px-3 pt-5 mb-3.5 w-full truncate min-h-8">
<Link href="/dashboard">
<Logo
hideLogoName={sidebarCollapsed}
viewBoxDimensions={sidebarCollapsed ? "0 0 40 40" : "0 0 120 40"}
- className="mx-auto w-[120px] h-[40px]"
+ className={clsx(
+ "w-[120px] h-[40px]",
+ sidebarCollapsed ? "mx-auto" : "",
+ )}
/>
</Link>
+ <Tooltip
+ kbd={[cmdSymbol, "Shift", "S"]}
+ position="right"
+ content="Toggle collapse"
+ >
+ <Button
+ variant="white"
+ onClick={toggleSidebarCollapsed}
+ className={clsx(
+ "size-7 p-0 min-w-[unset] rounded-full transition-all z-10 opacity-0 group-hover:opacity-100",
+ sidebarCollapsed ? "hidden" : "",
+ )}
+ >
+ <ChevronRight
+ size={14}
+ className={clsx(
+ "transition-transform duration-200 text-gray-12",
+ !sidebarCollapsed ? "rotate-180" : "",
+ )}
+ />
+ </Button>
+ </Tooltip>
</div>
<div className="flex overflow-y-auto flex-col flex-grow">
<div className="flex flex-col px-3 h-full">
<AdminNavItems />
</div>
</div>
- <Tooltip
- kbd={[cmdSymbol, "Shift", "S"]}
- position="right"
- content="Toggle collapse"
- >
- <Button
- variant="white"
- onClick={toggleSidebarCollapsed}
- className="absolute right-[-12px] size-7 p-0 min-w-[unset] top-[50%] transform -translate-y-1/2 rounded-full transition-colors z-10"
- >
- <ChevronRight
- size={14}
- className={clsx(
- "transition-transform duration-200 text-gray-12",
- sidebarCollapsed ? "rotate-180" : "",
- )}
- />
- </Button>
- </Tooltip>
</div>
</motion.aside>
);
diff --git a/apps/web/app/(org)/dashboard/analytics/data.ts b/apps/web/app/(org)/dashboard/analytics/data.ts
index 3aaf07180..a4aca4b2a 100644
--- a/apps/web/app/(org)/dashboard/analytics/data.ts
+++ b/apps/web/app/(org)/dashboard/analytics/data.ts
@@ -91,9 +91,10 @@ const getLifetimeRangeStart = async (
orgId: OrgId,
videoIds?: VideoId[],
): Promise<Date | undefined> => {
- const whereClause = videoIds && videoIds.length > 0
- ? and(eq(videos.orgId, orgId), inArray(videos.id, videoIds))
- : eq(videos.orgId, orgId);
+ const whereClause =
+ videoIds && videoIds.length > 0
+ ? and(eq(videos.orgId, orgId), inArray(videos.id, videoIds))
+ : eq(videos.orgId, orgId);
const rows = await db()
.select({ minCreatedAt: sql<Date>`MIN(${videos.createdAt})` })
@@ -151,15 +152,13 @@ const withTinybirdFallback = <Row>(
Effect.map((res: unknown) => {
const response = res as { data?: unknown[] };
const data = response.data ?? [];
- return data.filter((item): item is Row =>
- typeof item === "object" && item !== null,
+ return data.filter(
+ (item): item is Row => typeof item === "object" && item !== null,
) as Row[];
}),
);
-const getSpaceVideoIds = async (
- spaceId: SpaceOrOrgId,
-): Promise<VideoId[]> => {
+const getSpaceVideoIds = async (spaceId: SpaceOrOrgId): Promise<VideoId[]> => {
const rows = await db()
.select({ videoId: spaceVideos.videoId })
.from(spaceVideos)
@@ -225,27 +224,13 @@ export const getOrgAnalyticsData = async (
const [capsSeries, commentSeries, reactionSeries] = await Promise.all([
queryVideoSeries(typedOrgId, from, to, bucket, videoIds),
- queryCommentsSeries(
- typedOrgId,
- from,
- to,
- "text",
- bucket,
- videoIds,
- ),
- queryCommentsSeries(
- typedOrgId,
- from,
- to,
- "emoji",
- bucket,
- videoIds,
- ),
+ queryCommentsSeries(typedOrgId, from, to, "text", bucket, videoIds),
+ queryCommentsSeries(typedOrgId, from, to, "emoji", bucket, videoIds),
]);
- const tinybirdData = await runPromise(
- Effect.gen(function* () {
- const tinybird = yield* Tinybird;
+ const tinybirdData = await runPromise(
+ Effect.gen(function* () {
+ const tinybird = yield* Tinybird;
const viewSeries = yield* queryViewSeries(
tinybird,
@@ -316,8 +301,14 @@ export const getOrgAnalyticsData = async (
(sum: number, row: ViewSeriesRow) => sum + row.views,
0,
);
- const totalCaps = capsSeries.reduce((sum: number, row: CountSeriesRow) => sum + row.count, 0);
- const totalComments = commentSeries.reduce((sum: number, row: CountSeriesRow) => sum + row.count, 0);
+ const totalCaps = capsSeries.reduce(
+ (sum: number, row: CountSeriesRow) => sum + row.count,
+ 0,
+ );
+ const totalComments = commentSeries.reduce(
+ (sum: number, row: CountSeriesRow) => sum + row.count,
+ 0,
+ );
const totalReactions = reactionSeries.reduce(
(sum: number, row: CountSeriesRow) => sum + row.count,
0,
@@ -325,15 +316,25 @@ export const getOrgAnalyticsData = async (
const chartData = buckets.map((bucket) => ({
bucket,
- caps: capsSeries.find((row: CountSeriesRow) => row.bucket === bucket)?.count ?? 0,
+ caps:
+ capsSeries.find((row: CountSeriesRow) => row.bucket === bucket)?.count ??
+ 0,
views:
- tinybirdData.viewSeries.find((row: ViewSeriesRow) => row.bucket === bucket)?.views ?? 0,
- comments: commentSeries.find((row: CountSeriesRow) => row.bucket === bucket)?.count ?? 0,
- reactions: reactionSeries.find((row: CountSeriesRow) => row.bucket === bucket)?.count ?? 0,
+ tinybirdData.viewSeries.find(
+ (row: ViewSeriesRow) => row.bucket === bucket,
+ )?.views ?? 0,
+ comments:
+ commentSeries.find((row: CountSeriesRow) => row.bucket === bucket)
+ ?.count ?? 0,
+ reactions:
+ reactionSeries.find((row: CountSeriesRow) => row.bucket === bucket)
+ ?.count ?? 0,
}));
const videoNames = await loadVideoNames(
- tinybirdData.topCapsRaw.map((cap: TopCapRow) => cap.videoId).filter(Boolean),
+ tinybirdData.topCapsRaw
+ .map((cap: TopCapRow) => cap.videoId)
+ .filter(Boolean),
);
let capName: string | undefined;
@@ -953,7 +954,9 @@ const queryTopCaps = (
videoId: row.pathname?.split("/s/")[1] ?? row.pathname,
views: Number(row.views) || 0,
}))
- .filter((row: { videoId: string; views: number }): row is TopCapRow => Boolean(row.videoId)),
+ .filter((row: { videoId: string; views: number }): row is TopCapRow =>
+ Boolean(row.videoId),
+ ),
),
);
};
diff --git a/apps/web/app/api/analytics/track/route.ts b/apps/web/app/api/analytics/track/route.ts
index 4cdca5e76..cec82400c 100644
--- a/apps/web/app/api/analytics/track/route.ts
+++ b/apps/web/app/api/analytics/track/route.ts
@@ -81,7 +81,7 @@ export async function POST(request: NextRequest) {
return;
}
- const tinybird = yield* Tinybird;
+ const tinybird = yield* Tinybird;
yield* tinybird.appendEvents([
{
timestamp: timestamp.toISOString(),