Skip to content

Commit

Permalink
Merge pull request #50 from Royal-lobster/fix-image-preview
Browse files Browse the repository at this point in the history
Fix image preview click
  • Loading branch information
Royal-lobster authored Nov 26, 2023
2 parents e43e28c + 875582d commit b9668df
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/rare-countries-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"syncia": patch
---

Fixes preview to open image in new tab properly
Binary file modified artifacts/chrome.zip
Binary file not shown.
29 changes: 22 additions & 7 deletions src/components/Sidebar/chat/FilePreviewBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,37 @@ const FilePreviewBar = ({ files, removeFile }: FilePreviewBarProps) => {
return (
<div className="cdx-flex cdx-gap-2 cdx-m-2">
{files.map((file) => {
const imageUrl = file.src
const handlePreviewImageClick = async () => {
const image = new Image()
image.src = file.src
image.style.maxWidth = '100vw'
image.style.maxHeight = '100vh'
const newTab = window.open()
if (!newTab) return

const body = newTab.document.body
body.innerHTML = image.outerHTML
body.style.margin = '0'
body.style.display = 'grid'
body.style.placeItems = 'center'
body.style.height = '100vh'
body.style.width = '100vw'
body.style.backgroundColor = '#262626'
}

return (
<div key={file.id} className="cdx-flex cdx-relative">
<a
href={imageUrl}
target="_blank"
rel="noopener noreferrer"
<button
type="button"
onClick={handlePreviewImageClick}
className="cdx-block cdx-flex-grow"
>
<img
src={imageUrl}
src={file.src}
alt="preview"
className="cdx-w-14 cdx-h-14 cdx-object-contain cdx-rounded dark:cdx-bg-neutral-800 cdx-bg-neutral-400"
/>
</a>
</button>
{removeFile && (
<button
onClick={() => removeFile(file.id)}
Expand Down

0 comments on commit b9668df

Please sign in to comment.