Files
DeepTutor/web/components/reading/workspace/LegacyWatchingSession.tsx
Bingxi Zhao (Frank) 8986c31580 feat(reading): complete Watching convergence with safe legacy migration (#1378)
Adapted the migration foundation from PR #1384 while preserving current workspace, caption and turn-admission safeguards.

Co-authored-by: XZH <cto@xzh.ai>
2026-10-08 02:48:50 +08:00

27 lines
1.2 KiB
TypeScript

"use client";
import { useEffect, useState } from "react";
import { useRouter } from "next/navigation";
import { useTranslation } from "react-i18next";
import { migrateWatchingSession } from "@/lib/session-api";
import { sessionRoute } from "@/lib/mastery-session";
export default function LegacyWatchingSession({ sessionId }: { sessionId: string }) {
const router = useRouter();
const { t } = useTranslation();
const [error, setError] = useState("");
const [retry, setRetry] = useState(0);
useEffect(() => {
let cancelled = false;
migrateWatchingSession(sessionId).then(session => {
if (!cancelled) router.replace(sessionRoute({ ...session, message_count: session.messages.length, last_message: session.messages.at(-1)?.content ?? "" }), { scroll: false });
}).catch(caught => {
if (!cancelled) setError(caught instanceof Error ? caught.message : t("Could not load this section."));
});
return () => { cancelled = true; };
}, [sessionId, router, retry, t]);
return <div className="p-6 text-sm" role={error ? "alert" : "status"}>
{error || t("Loading…")}
{error && <button type="button" className="ml-3 underline" onClick={() => { setError(""); setRetry(value => value + 1); }}>{t("Retry")}</button>}
</div>;
}