-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Aleksander Theo Strand/Users/aleksandertheostrand/repos/tetgpt-chat/venv/bin/python
committed
Nov 6, 2024
1 parent
ec3085e
commit cb86d5a
Showing
3 changed files
with
123 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,4 @@ dist-ssr | |
.aider* | ||
.coverage | ||
|
||
backend/README.md | ||
|
||
myenv | ||
backend/README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
frontend/src/components/atoms/elements/LightboxWrapper.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import Lightbox from 'yet-another-react-lightbox'; | ||
import Download from 'yet-another-react-lightbox/plugins/download'; | ||
import Zoom from 'yet-another-react-lightbox/plugins/zoom'; | ||
|
||
import 'yet-another-react-lightbox/styles.css'; | ||
|
||
interface LightboxWrapperProps { | ||
isOpen: boolean; | ||
onClose: () => void; | ||
imageUrl: string; | ||
imageName: string; | ||
} | ||
|
||
const LightboxWrapper = ({ | ||
isOpen, | ||
onClose, | ||
imageUrl, | ||
imageName | ||
}: LightboxWrapperProps) => { | ||
return ( | ||
<Lightbox | ||
open={isOpen} | ||
close={onClose} | ||
slides={[{ src: imageUrl }]} | ||
carousel={{ finite: true }} | ||
render={{ buttonPrev: () => null, buttonNext: () => null }} | ||
plugins={[Zoom, Download]} | ||
zoom={{ | ||
maxZoomPixelRatio: 5, | ||
zoomInMultiplier: 2 | ||
}} | ||
download={{ | ||
download: async ({ slide }) => { | ||
try { | ||
const response = await fetch(slide.src, { mode: 'cors' }); | ||
const blob = await response.blob(); | ||
const url = window.URL.createObjectURL(blob); | ||
const link = document.createElement('a'); | ||
link.href = url; | ||
link.download = imageName || 'image'; | ||
link.click(); | ||
window.URL.revokeObjectURL(url); | ||
} catch (error) { | ||
console.error('Failed to download image:', error); | ||
} | ||
} | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
export default LightboxWrapper; |