(file: KeyFile)
| 411 | }; |
| 412 | |
| 413 | const handleFileClick = async (file: KeyFile) => { |
| 414 | setSelectedFile(file); |
| 415 | setIsDialogOpen(true); |
| 416 | |
| 417 | // First check if the file already has content |
| 418 | if (file.content) { |
| 419 | console.log('Using existing file content from keyFiles'); |
| 420 | setFileContent(file.content); |
| 421 | |
| 422 | // If we don't have detailed analysis yet, fetch it |
| 423 | if (!file.detailedAnalysis) { |
| 424 | try { |
| 425 | const analysis = await getDetailedFileAnalysis(repoFullName, file.path); |
| 426 | |
| 427 | // Update the file with the analysis |
| 428 | const updatedKeyFiles = keyFiles.map(f => |
| 429 | f.path === file.path ? { ...f, detailedAnalysis: analysis } : f |
| 430 | ); |
| 431 | setKeyFiles(updatedKeyFiles); |
| 432 | |
| 433 | // Update keyFiles cache |
| 434 | getKeyFilesCache()[repoFullName] = updatedKeyFiles; |
| 435 | } catch (error) { |
| 436 | console.error('Error fetching detailed analysis:', error); |
| 437 | } |
| 438 | } |
| 439 | return; |
| 440 | } |
| 441 | |
| 442 | // Then check our content cache |
| 443 | const cacheKey = `${repoFullName}:${file.path}`; |
| 444 | if (cachedFileContentsRef.current[cacheKey]) { |
| 445 | console.log('Using cached file content'); |
| 446 | const cachedContent = cachedFileContentsRef.current[cacheKey]; |
| 447 | setFileContent(cachedContent); |
| 448 | |
| 449 | // Update the file in keyFiles with the cached content |
| 450 | const updatedKeyFiles = keyFiles.map(f => |
| 451 | f.path === file.path ? { ...f, content: cachedContent } : f |
| 452 | ); |
| 453 | setKeyFiles(updatedKeyFiles); |
| 454 | |
| 455 | // Update keyFiles cache |
| 456 | getKeyFilesCache()[repoFullName] = updatedKeyFiles; |
| 457 | |
| 458 | // If we don't have detailed analysis yet, fetch it |
| 459 | if (!file.detailedAnalysis) { |
| 460 | try { |
| 461 | const analysis = await getDetailedFileAnalysis(repoFullName, file.path); |
| 462 | |
| 463 | // Update the file with the analysis |
| 464 | const updatedKeyFiles = keyFiles.map(f => |
| 465 | f.path === file.path ? { ...f, detailedAnalysis: analysis } : f |
| 466 | ); |
| 467 | setKeyFiles(updatedKeyFiles); |
| 468 | |
| 469 | // Update keyFiles cache |
| 470 | getKeyFilesCache()[repoFullName] = updatedKeyFiles; |
no test coverage detected