fix: Handle FileData structure from backend in UI components #19
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
When clicking on files in the UI, a runtime error occurs:
codeTree.value[0].value.split is not a function.The root cause is a type mismatch between the backend and frontend:
FileDataobjects with structure{content: string[], created_at: string, modified_at: string}Record<string, string>Solution
This PR fixes the type mismatch by:
Added FileData type (
src/app/types/types.ts)FileDatainterface matching backend structureFileItemfor UI layer with plain string contentUpdated useChat hook (
src/app/hooks/useChat.ts)StateType.filestoRecord<string, FileData>Updated page component (
src/app/page.tsx)Record<string, FileData>Changes
src/app/types/types.ts: AddedFileDatainterfacesrc/app/hooks/useChat.ts: Type updates and conversion logicsrc/app/page.tsx: Thread state handling updatesTesting
The fix maintains clean separation:
FileDataobjectsThis ensures files can now be clicked and viewed without errors while preserving all file metadata from the backend.