-
Notifications
You must be signed in to change notification settings - Fork 4
feat(app): image preview in file tabs #218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 files reviewed, 2 comments
packages/app/src/pages/session.tsx
Outdated
| ) | ||
| const path = tab.startsWith("file://") ? tab.replace("file://", "") : undefined | ||
| // Trigger the file load | ||
| if (path) local.file.init(path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: redundant call to init() - FileTabContent already calls local.file.node() which internally calls init()
| if (path) local.file.init(path) | |
| // File will be loaded by FileTabContent's createResource |
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/app/src/pages/session.tsx
Line: 946:946
Comment:
**style:** redundant call to `init()` - `FileTabContent` already calls `local.file.node()` which internally calls `init()`
```suggestion
// File will be loaded by FileTabContent's createResource
```
How can I resolve this? If you propose a fix, please make it concise.| if (parent) { | ||
| await list(parent) | ||
| } | ||
| await list(parent) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: verify list("") handles empty path correctly for root-level files
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/app/src/context/local.tsx
Line: 367:367
Comment:
**style:** verify `list("")` handles empty path correctly for root-level files
How can I resolve this? If you propose a fix, please make it concise.
Summary
list()for parent directory in file fetch (removes unnecessary conditional)Changes
packages/app/src/context/local.tsx: Remove conditional check beforelist(parent)packages/app/src/pages/session.tsx: NewFileTabContentcomponent for rendering images and code with SVG toggleProof
Before:
Before.mp4
After:
After.mp4
Greptile Summary
Added image preview functionality to file tabs with special handling for SVG files. Users can now view images directly in tabs, and SVG files get a toggle to switch between rendered preview and source code view.
FileTabContentcomponent detects base64-encoded images by mimeType and renders them with proper stylinglist(parent)regardless of parent pathFileTabContentcomponent for better separation of concernsMinor optimization opportunity: redundant
local.file.init()call on line 946 sinceFileTabContentalready handles initialization throughlocal.file.node().Confidence Score: 4/5
Important Files Changed
list(parent)- now always calls even when parent is empty stringFileTabContentcomponent with image preview and SVG toggle functionality, refactored tab content renderingSequence Diagram
sequenceDiagram participant User participant FileTabContent participant LocalContext participant SDK User->>FileTabContent: Opens file tab FileTabContent->>LocalContext: createResource(() => local.file.node(path)) LocalContext->>LocalContext: init(path) LocalContext->>LocalContext: fetch(path) LocalContext->>LocalContext: Calculate parent directory LocalContext->>SDK: list(parent + "/") SDK-->>LocalContext: Return parent directory contents LocalContext->>SDK: read file content SDK-->>LocalContext: Return file with content & mimeType LocalContext-->>FileTabContent: Return file node alt Image file (base64 encoded) alt SVG file FileTabContent->>User: Show image with "View code" toggle User->>FileTabContent: Click "View code" FileTabContent->>FileTabContent: setShowCode(true) FileTabContent->>User: Show decoded SVG source with "View image" toggle else Non-SVG image FileTabContent->>User: Show image preview end else Text file FileTabContent->>User: Show code editor end