Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions apps/web/app/(org)/dashboard/caps/Caps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ import { Button } from "@cap/ui";
import type { Video } from "@cap/web-domain";
import { faFolderPlus, faInfoCircle } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { useQuery } from "@tanstack/react-query";
import { Effect, Exit } from "effect";
import { useRouter, useSearchParams } from "next/navigation";
import { useEffect, useMemo, useRef, useState } from "react";
import { toast } from "sonner";
import { useEffectMutation, useEffectQuery } from "@/lib/EffectRuntime";
import {
AnalyticsRequest,
useVideosAnalyticsQuery,
} from "@/lib/Requests/AnalyticsRequest";
import { useEffectMutation } from "@/lib/EffectRuntime";
import { useVideosAnalyticsQuery } from "@/lib/Queries/Analytics";
import { AnalyticsRequest } from "@/lib/Requests/AnalyticsRequest";
import { Rpc, withRpc } from "@/lib/Rpcs";
import { useDashboardContext } from "../Contexts";
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"use client";

import type { Video } from "@cap/web-domain";
import { useQuery } from "@tanstack/react-query";
import { Effect, Exit } from "effect";
import { useRouter } from "next/navigation";
import { useMemo, useRef, useState } from "react";
import { toast } from "sonner";
import { useDashboardContext } from "@/app/(org)/dashboard/Contexts";
import { useEffectMutation } from "@/lib/EffectRuntime";
import { useVideosAnalyticsQuery } from "@/lib/Requests/AnalyticsRequest";
import { useVideosAnalyticsQuery } from "@/lib/Queries/Analytics";
import { AnalyticsRequest } from "@/lib/Requests/AnalyticsRequest";
Comment on lines +10 to +11
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

🧩 Analysis chain

Verify the necessity of the AnalyticsRequest import.

Similar to other files in this PR, the AnalyticsRequest import on line 11 appears unused. Consider removing it unless it's required for type definitions.

Run the following script to check usage:


🏁 Script executed:

#!/bin/bash
# Check if AnalyticsRequest is used beyond the import statement
rg -n 'AnalyticsRequest' apps/web/app/\(org\)/dashboard/folder/\[id\]/components/FolderVideosSection.tsx

Length of output: 70


Remove unused import of AnalyticsRequest. The import on line 11 isn’t referenced elsewhere in this file—delete it.

🤖 Prompt for AI Agents
In apps/web/app/(org)/dashboard/folder/[id]/components/FolderVideosSection.tsx
around lines 10 to 11, the import AnalyticsRequest is unused; remove the
AnalyticsRequest import (delete the ", AnalyticsRequest" from the import
statement or remove the entire import line if it becomes empty) and then run the
TypeScript/ESLint checks to ensure no other unused imports remain.

import { Rpc, withRpc } from "@/lib/Rpcs";
import type { VideoData } from "../../../caps/Caps";
import { CapCard } from "../../../caps/components/CapCard/CapCard";
Expand Down
3 changes: 2 additions & 1 deletion apps/web/app/(org)/dashboard/spaces/[spaceId]/SharedCaps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { useQuery } from "@tanstack/react-query";
import { useRouter, useSearchParams } from "next/navigation";
import { useState } from "react";
import { useVideosAnalyticsQuery } from "@/lib/Requests/AnalyticsRequest";
import { useVideosAnalyticsQuery } from "@/lib/Queries/Analytics";
import { AnalyticsRequest } from "@/lib/Requests/AnalyticsRequest";
import { useDashboardContext } from "../../Contexts";
import { CapPagination } from "../../caps/components/CapPagination";
import Folder, { type FolderDataType } from "../../caps/components/Folder";
Expand Down
47 changes: 47 additions & 0 deletions apps/web/lib/Queries/Analytics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import type { Video } from "@cap/web-domain";
import { Effect } from "effect";
import { useEffectQuery } from "../EffectRuntime";
import { AnalyticsRequest } from "../Requests/AnalyticsRequest";

export function useVideosAnalyticsQuery(
videoIds: Video.VideoId[],
dubApiKeyEnabled?: boolean,
) {
return useEffectQuery({
queryKey: ["analytics", videoIds],
queryFn: Effect.fn(function* () {
if (!dubApiKeyEnabled) return {};

const dataloader = yield* AnalyticsRequest.DataLoaderResolver;

const results = yield* Effect.all(
videoIds.map((videoId) =>
Effect.request(
new AnalyticsRequest.AnalyticsRequest({ videoId }),
dataloader,
).pipe(
Effect.catchAll((e) => {
console.warn(
`Failed to fetch analytics for video ${videoId}:`,
e,
);
return Effect.succeed({ count: 0 });
}),
Effect.map(({ count }) => ({ videoId, count })),
),
),
{ concurrency: "unbounded" },
);

return results.reduce(
(acc, current) => {
acc[current.videoId] = current.count;
return acc;
},
{} as Record<Video.VideoId, number>,
);
}),
refetchOnWindowFocus: false,
refetchOnMount: true,
});
}
44 changes: 0 additions & 44 deletions apps/web/lib/Requests/AnalyticsRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { dataLoader } from "@effect/experimental/RequestResolver";
import { Effect, Exit, Request, RequestResolver } from "effect";
import type { NonEmptyArray } from "effect/Array";
import { Rpc } from "@/lib/Rpcs";
import { useEffectQuery } from "../EffectRuntime";

export namespace AnalyticsRequest {
export class AnalyticsRequest extends Request.Class<
Expand Down Expand Up @@ -50,46 +49,3 @@ export namespace AnalyticsRequest {
},
) {}
}

export function useVideosAnalyticsQuery(
videoIds: Video.VideoId[],
dubApiKeyEnabled?: boolean,
) {
return useEffectQuery({
queryKey: ["analytics", videoIds],
queryFn: Effect.fn(function* () {
if (!dubApiKeyEnabled) return {};

const dataloader = yield* AnalyticsRequest.DataLoaderResolver;

const results = yield* Effect.all(
videoIds.map((videoId) =>
Effect.request(
new AnalyticsRequest.AnalyticsRequest({ videoId }),
dataloader,
).pipe(
Effect.catchAll((e) => {
console.warn(
`Failed to fetch analytics for video ${videoId}:`,
e,
);
return Effect.succeed({ count: 0 });
}),
Effect.map(({ count }) => ({ videoId, count })),
),
),
{ concurrency: "unbounded" },
);

return results.reduce(
(acc, current) => {
acc[current.videoId] = current.count;
return acc;
},
{} as Record<Video.VideoId, number>,
);
}),
refetchOnWindowFocus: false,
refetchOnMount: true,
});
}
Loading