@@ -10,53 +10,20 @@ import {
1010 normalizeModelId ,
1111} from "../../types/aiService" ;
1212import { aiService } from "../../services/aiService" ;
13+ import {
14+ ExplanationResult ,
15+ globalExplanationListeners ,
16+ explanationCache ,
17+ setGlobalExplanationState ,
18+ getGlobalExplanationState ,
19+ } from "./explanationState" ;
1320
1421interface ExplanationDrawerProps {
1522 isOpen : boolean ;
1623 onClose : ( ) => void ;
1724 text : string ;
1825}
1926
20- interface ExplanationResult {
21- explanation : string ;
22- usage ?: {
23- promptTokens : number ;
24- completionTokens : number ;
25- totalTokens : number ;
26- } ;
27- model : string ;
28- provider : AIProvider ;
29- }
30-
31- // Global explanation state management (shared with TranscriptSegment)
32- interface ExplanationState {
33- text : string ;
34- status : "idle" | "loading" | "completed" | "error" ;
35- result ?: ExplanationResult ;
36- error ?: string ;
37- }
38-
39- const globalExplanationStates = new Map < string , ExplanationState > ( ) ;
40- const globalExplanationListeners = new Set < ( ) => void > ( ) ;
41-
42- const setGlobalExplanationState = (
43- text : string ,
44- state : Partial < ExplanationState >
45- ) => {
46- const existing = globalExplanationStates . get ( text ) || {
47- text,
48- status : "idle" ,
49- } ;
50- globalExplanationStates . set ( text , { ...existing , ...state } ) ;
51- globalExplanationListeners . forEach ( ( listener ) => listener ( ) ) ;
52- } ;
53-
54- const getGlobalExplanationState = ( text : string ) : ExplanationState => {
55- return globalExplanationStates . get ( text ) || { text, status : "idle" } ;
56- } ;
57-
58- const explanationCache = new Map < string , ExplanationResult > ( ) ;
59-
6027export const ExplanationDrawer : React . FC < ExplanationDrawerProps > = ( {
6128 isOpen,
6229 onClose,
@@ -67,9 +34,19 @@ export const ExplanationDrawer: React.FC<ExplanationDrawerProps> = ({
6734 const [ isLoading , setIsLoading ] = useState ( false ) ;
6835 const [ error , setError ] = useState < string | null > ( null ) ;
6936
70- const [ selectedProvider , setSelectedProvider ] = useState < AIProvider > ( "openai" ) ;
71- const [ selectedModel , setSelectedModel ] = useState ( "" ) ;
72- const [ targetLanguage , setTargetLanguage ] = useState ( "English" ) ;
37+ const [ selectedProvider , setSelectedProvider ] = useState < AIProvider > (
38+ ( ) => ( localStorage . getItem ( "preferred_ai_provider" ) as AIProvider ) || "openai"
39+ ) ;
40+ const [ targetLanguage , setTargetLanguage ] = useState (
41+ ( ) => localStorage . getItem ( "target_language" ) || "English"
42+ ) ;
43+ const [ selectedModel , setSelectedModel ] = useState ( ( ) => {
44+ const provider = ( localStorage . getItem ( "preferred_ai_provider" ) as AIProvider ) || "openai" ;
45+ return normalizeModelId (
46+ provider ,
47+ localStorage . getItem ( `${ provider } _model` ) || DEFAULT_MODELS [ provider ]
48+ ) ;
49+ } ) ;
7350
7451 // Handle ESC key
7552 useEffect ( ( ) => {
0 commit comments