Skip to content

Commit 71a6f94

Browse files
authored
fix: ai transcription loading state (#991)
* preview console logs * Update Share.tsx * Update Share.tsx * correct type and improve transcription loading * Update Share.tsx * formatting * Update Share.tsx * console logs * adjustments * Update Share.tsx
1 parent 737c7ee commit 71a6f94

3 files changed

Lines changed: 59 additions & 33 deletions

File tree

apps/web/actions/videos/get-status.ts

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -213,16 +213,43 @@ export async function getVideoStatus(
213213
}
214214
})();
215215

216-
return {
217-
transcriptionStatus:
218-
(video.transcriptionStatus as "PROCESSING" | "COMPLETE" | "ERROR") ||
219-
null,
220-
aiProcessing: true,
221-
aiTitle: metadata.aiTitle || null,
222-
summary: metadata.summary || null,
223-
chapters: metadata.chapters || null,
224-
// generationError: metadata.generationError || null,
225-
};
216+
const updatedVideo = await db()
217+
.select({
218+
transcriptionStatus: videos.transcriptionStatus,
219+
metadata: videos.metadata,
220+
})
221+
.from(videos)
222+
.where(eq(videos.id, videoId))
223+
.limit(1);
224+
if (updatedVideo.length > 0) {
225+
const row = updatedVideo[0];
226+
if (!row) {
227+
return {
228+
transcriptionStatus:
229+
(video.transcriptionStatus as
230+
| "PROCESSING"
231+
| "COMPLETE"
232+
| "ERROR") || null,
233+
aiProcessing: metadata.aiProcessing || false,
234+
aiTitle: metadata.aiTitle || null,
235+
summary: metadata.summary || null,
236+
chapters: metadata.chapters || null,
237+
// generationError: metadata.generationError || null,
238+
};
239+
}
240+
const updatedMetadata = (row.metadata as VideoMetadata) || {};
241+
242+
return {
243+
transcriptionStatus:
244+
(row.transcriptionStatus as "PROCESSING" | "COMPLETE" | "ERROR") ||
245+
null,
246+
aiProcessing: updatedMetadata.aiProcessing || false,
247+
aiTitle: updatedMetadata.aiTitle || null,
248+
summary: updatedMetadata.summary || null,
249+
chapters: updatedMetadata.chapters || null,
250+
// generationError: updatedMetadata.generationError || null,
251+
};
252+
}
226253
} else {
227254
const videoOwner = videoOwnerQuery[0];
228255
console.log(

apps/web/app/s/[videoId]/Share.tsx

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,16 @@ const useVideoStatus = (
114114
}
115115

116116
if (data.transcriptionStatus === "COMPLETE") {
117-
if (!aiGenerationEnabled) {
118-
return false;
117+
if (aiGenerationEnabled) {
118+
const noAiData = !(
119+
data.aiTitle ||
120+
data.summary ||
121+
(data.chapters && data.chapters.length > 0)
122+
);
123+
if (data.aiProcessing || noAiData) {
124+
return true;
125+
}
119126
}
120-
121-
if (data.aiProcessing) {
122-
return true;
123-
}
124-
125-
if (!data.summary && !data.chapters) {
126-
return true;
127-
}
128-
129127
return false;
130128
}
131129

@@ -184,10 +182,7 @@ export const Share = ({
184182
);
185183

186184
const shouldShowLoading = () => {
187-
if (!aiGenerationEnabled) {
188-
return false;
189-
}
190-
185+
// Show loading while transcription is pending or processing regardless of AI flag
191186
if (!transcriptionStatus || transcriptionStatus === "PROCESSING") {
192187
return true;
193188
}
@@ -197,22 +192,25 @@ export const Share = ({
197192
}
198193

199194
if (transcriptionStatus === "COMPLETE") {
200-
// if (aiData.generationError) {
201-
// return false;
202-
// }
203-
if (aiData.processing === true) {
204-
return true;
205-
}
206-
if (!aiData.summary && !aiData.chapters) {
195+
// Only show loading for AI if enabled and currently processing
196+
if (aiGenerationEnabled && aiData.processing === true) {
207197
return true;
208198
}
199+
return false;
209200
}
210201

211202
return false;
212203
};
213204

214205
const aiLoading = shouldShowLoading();
215206

207+
console.log({
208+
aiLoading,
209+
aiData,
210+
transcriptionStatus,
211+
aiGenerationEnabled,
212+
});
213+
216214
const handleSeek = (time: number) => {
217215
if (playerRef.current) {
218216
playerRef.current.currentTime = time;

apps/web/lib/transcribe.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { db } from "@cap/database";
22
import { s3Buckets, videos } from "@cap/database/schema";
33
import { serverEnv } from "@cap/env";
4+
import type { Video } from "@cap/web-domain";
45
import { createClient } from "@deepgram/sdk";
56
import { eq } from "drizzle-orm";
67
import { generateAiMetadata } from "@/actions/videos/generate-ai-metadata";
@@ -12,7 +13,7 @@ type TranscribeResult = {
1213
};
1314

1415
export async function transcribeVideo(
15-
videoId: string,
16+
videoId: Video.VideoId,
1617
userId: string,
1718
aiGenerationEnabled = false,
1819
): Promise<TranscribeResult> {

0 commit comments

Comments
 (0)