MCPcopy Index your code
hub / github.com/CapSoftware/Cap / useTranscript

Function useTranscript

apps/web/hooks/use-transcript.ts:6–48  ·  view source on GitHub ↗
(
	videoId: Video.VideoId,
	transcriptionStatus?: string | null,
)

Source from the content-addressed store, hash-verified

4import { getTranscript } from "@/actions/videos/get-transcript";
5
6export const useTranscript = (
7 videoId: Video.VideoId,
8 transcriptionStatus?: string | null,
9) => {
10 const queryClient = useQueryClient();
11 const previousStatus = useRef(transcriptionStatus);
12
13 useEffect(() => {
14 if (
15 previousStatus.current !== "COMPLETE" &&
16 transcriptionStatus === "COMPLETE"
17 ) {
18 queryClient.invalidateQueries({ queryKey: ["transcript", videoId] });
19 }
20 previousStatus.current = transcriptionStatus;
21 }, [transcriptionStatus, videoId, queryClient]);
22
23 return useQuery({
24 queryKey: ["transcript", videoId],
25 queryFn: async () => {
26 const result = await getTranscript(videoId);
27
28 if (result.success && result.content) {
29 return result.content;
30 }
31 if (result.message === "Transcript is not ready yet") {
32 throw new Error("TRANSCRIPT_NOT_READY");
33 }
34 throw new Error(result.message);
35 },
36 enabled: transcriptionStatus === "COMPLETE",
37 staleTime: 30 * 60 * 1000,
38 gcTime: 60 * 60 * 1000,
39 refetchOnWindowFocus: false,
40 retry: (failureCount, error) => {
41 if (error.message === "TRANSCRIPT_NOT_READY") {
42 return failureCount < 3;
43 }
44 return false;
45 },
46 retryDelay: 1000,
47 });
48};
49
50export const useInvalidateTranscript = () => {
51 const queryClient = useQueryClient();

Callers 3

ShareVideo.tsxFile · 0.90
TranscriptFunction · 0.90
EmbedVideo.tsxFile · 0.90

Calls 1

getTranscriptFunction · 0.90

Tested by

no test coverage detected