mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 10:20:23 +08:00
Ship folder-based workspaces and data migration, daily practice, redesigned provider and model settings, and streaming conversation improvements. Synchronize README translations and document the archive/permanent-delete upgrade behavior in assets/releases/ver1-6-9.md. Reduce initial JavaScript by deduplicating English resources and loading animation features after hydration. Keep the existing route size budgets. Update regression fixtures and browser audits for scoped URLs and the new settings and learning interfaces.
152 lines
4.6 KiB
TypeScript
152 lines
4.6 KiB
TypeScript
"use client";
|
|
|
|
import { scopedUrl } from "@/lib/workspace-scope";
|
|
import { WATCHING_HOME } from "@/lib/learning-routes";
|
|
|
|
import { useEffect, useRef, useState } from "react";
|
|
import { useSearchParams, useParams } from "next/navigation";
|
|
import { invidiousAccountResultMessage } from "@/lib/invidious-account-result";
|
|
import { WatchingBrowser } from "./WatchingBrowser";
|
|
import { useTranslation } from "react-i18next";
|
|
import { useWatching } from "@/context/WatchingContext";
|
|
import type { SessionConfiguration } from "@/features/chat/ChatStateAdapter";
|
|
import { WatchingPane, WATCHING_ASK_EVENT } from "./WatchingPane";
|
|
|
|
/** Bind the existing player to the selected conversation, never browser-global history. */
|
|
export function WatchingSessionBridge({
|
|
sessionKey,
|
|
materialId,
|
|
onMaterial,
|
|
sourceUrl,
|
|
}: {
|
|
sourceUrl?: string | null;
|
|
sessionKey: string;
|
|
materialId: string | null;
|
|
onMaterial(configuration: SessionConfiguration): void;
|
|
}) {
|
|
const { material, loading, error, restore, close, openUrl } = useWatching();
|
|
const [restoredKey, setRestoredKey] = useState<string | null>(null);
|
|
const binding = useRef(materialId);
|
|
useEffect(() => {
|
|
binding.current = materialId;
|
|
}, [materialId]);
|
|
useEffect(() => {
|
|
let cancelled = false;
|
|
void restore(sourceUrl ? null : binding.current).then(async () => {
|
|
if (cancelled) return;
|
|
if (sourceUrl) await openUrl(sourceUrl);
|
|
if (!cancelled) setRestoredKey(sessionKey);
|
|
});
|
|
return () => {
|
|
cancelled = true;
|
|
close();
|
|
};
|
|
}, [sessionKey, sourceUrl, restore, close, openUrl]);
|
|
useEffect(() => {
|
|
if (
|
|
restoredKey !== sessionKey ||
|
|
loading ||
|
|
error ||
|
|
(material?.material_id ?? null) === materialId
|
|
)
|
|
return;
|
|
onMaterial({ timedMediaId: material?.material_id ?? null });
|
|
}, [
|
|
restoredKey,
|
|
sessionKey,
|
|
material,
|
|
materialId,
|
|
loading,
|
|
error,
|
|
onMaterial,
|
|
]);
|
|
return null;
|
|
}
|
|
|
|
/** Responsive presentation only; ChatWorkspace continues to own the single chat runtime. */
|
|
export function WatchingSurface() {
|
|
const { t } = useTranslation();
|
|
const { material } = useWatching();
|
|
const params = useSearchParams();
|
|
const route = useParams();
|
|
const [browsing, setBrowsing] = useState(
|
|
!params.get("video") && !route.sessionId,
|
|
);
|
|
const [accountResult, setAccountResult] = useState(params.get("account"));
|
|
const accountMessage = invidiousAccountResultMessage(accountResult);
|
|
useEffect(() => {
|
|
if (params.has("account"))
|
|
window.history.replaceState(null, "", scopedUrl(WATCHING_HOME));
|
|
}, [params]);
|
|
const showBrowser = browsing && !params.get("video");
|
|
const [view, setView] = useState<"video" | "chat">("video");
|
|
useEffect(() => {
|
|
const showChat = () => setView("chat");
|
|
window.addEventListener(WATCHING_ASK_EVENT, showChat);
|
|
return () => window.removeEventListener(WATCHING_ASK_EVENT, showChat);
|
|
}, []);
|
|
return (
|
|
<div
|
|
className="watching-surface"
|
|
data-mobile-view={view}
|
|
data-browsing={showBrowser || undefined}
|
|
>
|
|
{accountMessage && showBrowser && (
|
|
<div
|
|
role={accountResult === "connected" ? "status" : "alert"}
|
|
className="watching-account-error flex items-center justify-between gap-3"
|
|
>
|
|
<span>{t(accountMessage)}</span>
|
|
<button
|
|
type="button"
|
|
className="watching-browser-button shrink-0"
|
|
onClick={() => setAccountResult(null)}
|
|
>
|
|
{t("Dismiss")}
|
|
</button>
|
|
</div>
|
|
)}
|
|
{showBrowser && (
|
|
<WatchingBrowser
|
|
canDismiss={!!material}
|
|
onDismiss={() => setBrowsing(false)}
|
|
/>
|
|
)}
|
|
{!showBrowser && (
|
|
<button
|
|
className="watching-browse-toggle watching-browser-button"
|
|
onClick={() => {
|
|
window.history.replaceState(null, "", scopedUrl(window.location.pathname));
|
|
setBrowsing(true);
|
|
}}
|
|
>
|
|
{t("Browse videos")}
|
|
</button>
|
|
)}
|
|
<div
|
|
className="watching-mobile-tabs"
|
|
role="group"
|
|
aria-label={t("Immersive Watching")}
|
|
>
|
|
<button
|
|
type="button"
|
|
aria-pressed={view === "video"}
|
|
onClick={() => setView("video")}
|
|
>
|
|
{t("Video")}
|
|
</button>
|
|
<button
|
|
type="button"
|
|
aria-pressed={view === "chat"}
|
|
onClick={() => setView("chat")}
|
|
>
|
|
{t("Conversation")}
|
|
</button>
|
|
</div>
|
|
<div className="dt-watching-shell" data-watching-open="true">
|
|
<WatchingPane onClose={() => setView("chat")} />
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|