feat: pass author and video context to predict and stop persisting on debounce
Browse filesThe predict client now accepts an options object so callers can attach video_id and author when they want the prediction stored, and listPredictions can request a specific source. The debounce hook used by live scoring sets persist to false to avoid filling Supabase with drafts the user never published.
frontend/src/api/client.ts
CHANGED
|
@@ -37,10 +37,22 @@ async function request<T>(path: string, init?: RequestInit): Promise<T> {
|
|
| 37 |
return res.json() as Promise<T>;
|
| 38 |
}
|
| 39 |
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
return request<PredictResponse>("/predict", {
|
| 42 |
method: "POST",
|
| 43 |
-
body: JSON.stringify({
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
});
|
| 45 |
}
|
| 46 |
|
|
@@ -86,9 +98,10 @@ export function getSuggestedVideos() {
|
|
| 86 |
return request<{ videos: SuggestedVideo[]; max_comments: number }>("/videos/suggested");
|
| 87 |
}
|
| 88 |
|
| 89 |
-
export function listPredictions(videoId?: string, limit =
|
| 90 |
const params = new URLSearchParams();
|
| 91 |
if (videoId) params.set("video_id", videoId);
|
|
|
|
| 92 |
params.set("limit", String(limit));
|
| 93 |
return request<PredictionsListResponse>(`/predictions?${params.toString()}`);
|
| 94 |
}
|
|
|
|
| 37 |
return res.json() as Promise<T>;
|
| 38 |
}
|
| 39 |
|
| 40 |
+
type PredictOptions = {
|
| 41 |
+
videoId?: string;
|
| 42 |
+
author?: string;
|
| 43 |
+
persist?: boolean;
|
| 44 |
+
};
|
| 45 |
+
|
| 46 |
+
export function predict(text: string, threshold: number, options: PredictOptions = {}) {
|
| 47 |
return request<PredictResponse>("/predict", {
|
| 48 |
method: "POST",
|
| 49 |
+
body: JSON.stringify({
|
| 50 |
+
text,
|
| 51 |
+
threshold,
|
| 52 |
+
video_id: options.videoId,
|
| 53 |
+
author: options.author,
|
| 54 |
+
persist: options.persist ?? true,
|
| 55 |
+
}),
|
| 56 |
});
|
| 57 |
}
|
| 58 |
|
|
|
|
| 98 |
return request<{ videos: SuggestedVideo[]; max_comments: number }>("/videos/suggested");
|
| 99 |
}
|
| 100 |
|
| 101 |
+
export function listPredictions(videoId?: string, limit = 200, source?: string) {
|
| 102 |
const params = new URLSearchParams();
|
| 103 |
if (videoId) params.set("video_id", videoId);
|
| 104 |
+
if (source) params.set("source", source);
|
| 105 |
params.set("limit", String(limit));
|
| 106 |
return request<PredictionsListResponse>(`/predictions?${params.toString()}`);
|
| 107 |
}
|
frontend/src/hooks/useDebouncedPredict.ts
CHANGED
|
@@ -21,7 +21,7 @@ export function useDebouncedPredict(text: string, threshold: number, delayMs = 4
|
|
| 21 |
abortRef.current?.abort();
|
| 22 |
setLoading(true);
|
| 23 |
setError(null);
|
| 24 |
-
predict(trimmed, threshold)
|
| 25 |
.then(setResult)
|
| 26 |
.catch((e: Error) => setError(e.message))
|
| 27 |
.finally(() => setLoading(false));
|
|
|
|
| 21 |
abortRef.current?.abort();
|
| 22 |
setLoading(true);
|
| 23 |
setError(null);
|
| 24 |
+
predict(trimmed, threshold, { persist: false })
|
| 25 |
.then(setResult)
|
| 26 |
.catch((e: Error) => setError(e.message))
|
| 27 |
.finally(() => setLoading(false));
|