11'use client' ;
22
3- import { useEditorEngine } from '@/components/store/editor' ;
4- import { MessageContextType , type LocalImageMessageContext } from '@onlook/models/chat' ;
3+ import { observer } from 'mobx-react-lite' ;
4+
5+ import type { ImageMessageContext } from '@onlook/models/chat' ;
6+ import { MessageContextType } from '@onlook/models/chat' ;
57import { Icons } from '@onlook/ui/icons' ;
68import { toast } from '@onlook/ui/sonner' ;
79import { convertToBase64DataUrl , getMimeType } from '@onlook/utility' ;
8- import { observer } from 'mobx-react-lite' ;
10+
11+ import { useEditorEngine } from '@/components/store/editor' ;
912import { BreadcrumbNavigation } from './breadcrumb-navigation' ;
1013import { FolderList } from './folder-list' ;
1114import { useImageOperations } from './hooks/use-image-operations' ;
@@ -30,7 +33,9 @@ export const ImagesTab = observer(() => {
3033 } = useNavigation ( ) ;
3134
3235 // Get the CodeEditorApi for the active branch
33- const branchData = editorEngine . branches . getBranchDataById ( editorEngine . branches . activeBranch . id ) ;
36+ const branchData = editorEngine . branches . getBranchDataById (
37+ editorEngine . branches . activeBranch . id ,
38+ ) ;
3439
3540 // Image operations and data
3641 const {
@@ -54,7 +59,9 @@ export const ImagesTab = observer(() => {
5459 toast . success ( 'Image renamed successfully' ) ;
5560 } catch ( error ) {
5661 console . error ( 'Failed to rename image:' , error ) ;
57- toast . error ( `Failed to rename image: ${ error instanceof Error ? error . message : 'Unknown error' } ` ) ;
62+ toast . error (
63+ `Failed to rename image: ${ error instanceof Error ? error . message : 'Unknown error' } ` ,
64+ ) ;
5865 throw error ;
5966 }
6067 } ;
@@ -65,7 +72,9 @@ export const ImagesTab = observer(() => {
6572 toast . success ( 'Image deleted successfully' ) ;
6673 } catch ( error ) {
6774 console . error ( 'Failed to delete image:' , error ) ;
68- toast . error ( `Failed to delete image: ${ error instanceof Error ? error . message : 'Unknown error' } ` ) ;
75+ toast . error (
76+ `Failed to delete image: ${ error instanceof Error ? error . message : 'Unknown error' } ` ,
77+ ) ;
6978 throw error ;
7079 }
7180 } ;
@@ -81,20 +90,19 @@ export const ImagesTab = observer(() => {
8190 throw new Error ( 'Failed to load image file' ) ;
8291 }
8392
84- // Convert to base64 data URL
8593 const base64Content = convertToBase64DataUrl ( fileContent , mimeType ) ;
8694
87- // Create LOCAL_IMAGE context with actual image data
88- const localImageContext : LocalImageMessageContext = {
89- type : MessageContextType . LOCAL_IMAGE ,
95+ const imageContext : ImageMessageContext = {
96+ type : MessageContextType . IMAGE ,
97+ source : 'local' ,
9098 path : imagePath ,
9199 branchId : branchId ,
92100 content : base64Content ,
93101 displayName : fileName ,
94102 mimeType : mimeType ,
95103 } ;
96104
97- editorEngine . chat . context . addContexts ( [ localImageContext ] ) ;
105+ editorEngine . chat . context . addContexts ( [ imageContext ] ) ;
98106 toast . success ( 'Image added to chat' ) ;
99107 } catch ( error ) {
100108 console . error ( 'Failed to add image to chat:' , error ) ;
@@ -104,23 +112,23 @@ export const ImagesTab = observer(() => {
104112
105113 if ( loading ) {
106114 return (
107- < div className = "w-full h-full flex items-center justify-center gap-2" >
108- < Icons . LoadingSpinner className = "w -4 h -4 animate-spin" />
115+ < div className = "flex h-full w-full items-center justify-center gap-2" >
116+ < Icons . LoadingSpinner className = "h -4 w -4 animate-spin" />
109117 Loading images...
110118 </ div >
111119 ) ;
112120 }
113121
114122 if ( error ) {
115123 return (
116- < div className = "w-full h-full flex items-center justify-center text-sm text-red-500" >
124+ < div className = "flex h-full w-full items-center justify-center text-sm text-red-500" >
117125 Error: { error . message }
118126 </ div >
119127 ) ;
120128 }
121129
122130 return (
123- < div className = "w-full h-full flex flex-col gap-3 p-3" >
131+ < div className = "flex h-full w-full flex-col gap-3 p-3" >
124132 < SearchUploadBar
125133 search = { search }
126134 setSearch = { setSearch }
@@ -133,10 +141,7 @@ export const ImagesTab = observer(() => {
133141 onNavigate = { navigateToFolder }
134142 />
135143
136- < FolderList
137- folders = { folders }
138- onFolderClick = { handleFolderClick }
139- />
144+ < FolderList folders = { folders } onFolderClick = { handleFolderClick } />
140145
141146 < ImageGrid
142147 images = { images }
@@ -150,4 +155,4 @@ export const ImagesTab = observer(() => {
150155 />
151156 </ div >
152157 ) ;
153- } ) ;
158+ } ) ;
0 commit comments