@@ -175,14 +175,16 @@ const TopicHistogram: FC = () => {
175175 const [ selectedTopics , setSelectedTopics ] = useState < string [ ] > ( [ ] ) ;
176176
177177 // State for frequency range
178- const [ frequencyRange , setFrequencyRange ] = useState ( { min : 0 , max : 100 } ) ;
178+ const [ frequencyRange , setFrequencyRange ] = useState ( { min : 0 , max : 1 } ) ;
179179 const [ hasAdjustedRange , setHasAdjustedRange ] = useState ( false ) ;
180180 const maxCount = Math . max ( ...extractedTopics . map ( item => item . count || 0 ) , 1 ) ;
181181
182- // Update frequency range when maxCount changes
182+ // Update frequency range when maxCount changes, but only if it hasn't been adjusted yet
183183 useEffect ( ( ) => {
184- setFrequencyRange ( { min : 0 , max : maxCount } ) ;
185- } , [ maxCount ] ) ;
184+ if ( ! hasAdjustedRange ) {
185+ setFrequencyRange ( { min : 0 , max : 1 } ) ; // Keep it at 0-1 until user adjusts
186+ }
187+ } , [ maxCount , hasAdjustedRange ] ) ;
186188
187189 // State for final topics
188190 const [ finalTopics , setFinalTopics ] = useState < string [ ] > ( [ ] ) ;
@@ -208,12 +210,17 @@ const TopicHistogram: FC = () => {
208210
209211 // Function to handle topic click
210212 const handleTopicClick = ( topic : string ) => {
213+ console . log ( 'Topic clicked:' , topic ) ;
214+ console . log ( 'Current API key:' , apiKey ? 'Present' : 'Missing' ) ;
215+
211216 if ( ! apiKey ) {
217+ console . log ( 'No API key, showing modal' ) ;
212218 // Show API key modal if no key is set
213219 setShowApiKeyModal ( true ) ;
214220 return ;
215221 }
216222
223+ console . log ( 'Starting explanation fetch for topic:' , topic ) ;
217224 // Show explanation modal immediately with loading state
218225 setSelectedTopicForExplanation ( topic ) ;
219226 setTopicExplanation ( "" ) ; // Clear previous explanation
@@ -334,7 +341,9 @@ const TopicHistogram: FC = () => {
334341
335342 // Function to fetch topic explanation
336343 const fetchTopicExplanation = async ( topic : string ) => {
344+ console . log ( 'Fetching explanation for topic:' , topic ) ;
337345 if ( ! apiKey ) {
346+ console . log ( 'No API key in fetchTopicExplanation' ) ;
338347 notify ( {
339348 message : "Please set your Google API key first" ,
340349 type : "warning"
@@ -344,6 +353,7 @@ const TopicHistogram: FC = () => {
344353 }
345354
346355 try {
356+ console . log ( 'Making API request to:' , API_ENDPOINTS . EXPLAIN_TOPIC ) ;
347357 const response = await fetch ( API_ENDPOINTS . EXPLAIN_TOPIC , {
348358 method : 'POST' ,
349359 headers : {
@@ -357,11 +367,13 @@ const TopicHistogram: FC = () => {
357367 } )
358368 } ) ;
359369
370+ console . log ( 'Response status:' , response . status ) ;
360371 if ( ! response . ok ) {
361372 throw new Error ( `HTTP error! status: ${ response . status } ` ) ;
362373 }
363374
364375 const data = await response . json ( ) ;
376+ console . log ( 'Response data:' , data ) ;
365377 if ( data . success ) {
366378 setTopicExplanation ( data . explanation ) ;
367379 } else {
0 commit comments