MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / ImageCard

Function ImageCard

cli/src/components/image-card.tsx:49–167  ·  view source on GitHub ↗
({
  image,
  onRemove,
  showRemoveButton = true,
}: ImageCardProps)

Source from the content-addressed store, hash-verified

47}
48
49export const ImageCard = ({
50 image,
51 onRemove,
52 showRemoveButton = true,
53}: ImageCardProps) => {
54 const theme = useTheme()
55 const [thumbnailSequence, setThumbnailSequence] = useState<string | null>(
56 null,
57 )
58 const canShowInlineImages = supportsInlineImages()
59
60 // Load thumbnail if terminal supports inline images (iTerm2/Kitty)
61 useEffect(() => {
62 if (!canShowInlineImages) return
63 // Skip loading while image is processing or has error to avoid race condition and unnecessary failed reads
64 if ((image.status ?? 'ready') !== 'ready') return
65
66 let cancelled = false
67
68 const loadThumbnail = async () => {
69 try {
70 let base64Data: string | undefined
71
72 if (image.processedImage) {
73 base64Data = image.processedImage.base64
74 } else if (!image.path.startsWith('clipboard:')) {
75 const imageData = fs.readFileSync(image.path)
76 base64Data = imageData.toString('base64')
77 }
78
79 if (base64Data) {
80 const sequence = renderInlineImage(base64Data, {
81 width: INLINE_IMAGE_WIDTH,
82 height: INLINE_IMAGE_HEIGHT,
83 filename: image.filename,
84 })
85 if (!cancelled) {
86 setThumbnailSequence(sequence)
87 }
88 } else {
89 if (!cancelled) {
90 setThumbnailSequence(null)
91 }
92 }
93 } catch {
94 // Failed to load image, will show icon fallback
95 if (!cancelled) {
96 setThumbnailSequence(null)
97 }
98 }
99 }
100
101 loadThumbnail()
102
103 return () => {
104 cancelled = true
105 }
106 }, [image, image.filename, canShowInlineImages])

Callers

nothing calls this directly

Calls 4

useThemeFunction · 0.90
supportsInlineImagesFunction · 0.90
loadThumbnailFunction · 0.70
truncateFilenameFunction · 0.70

Tested by

no test coverage detected