@@ -14,31 +14,46 @@ import { PiImageSquare } from "@react-icons/all-files/pi/PiImageSquare"
1414import { PiImagesSquare } from "@react-icons/all-files/pi/PiImagesSquare"
1515import { PiX } from "@react-icons/all-files/pi/PiX"
1616import React , { useMemo } from "react"
17- import { useEditorStore } from "../../store"
17+ import {
18+ type FileElement ,
19+ type RequiredMetadata ,
20+ useEditorStore ,
21+ } from "../../store"
1822
19- interface ExportOptionButton {
23+ interface ExportOptionButton <
24+ Metadata extends RequiredMetadata = RequiredMetadata ,
25+ > {
2026 type : "button"
2127 label : string
2228 icon ?: React . ReactElement
2329 isVisible : boolean | ( ( images : string [ ] , currentImage ?: string ) => boolean )
24- onClick : ( images : string [ ] , currentImage ?: string ) => void
30+ onClick : (
31+ images : { url : string ; file : FileElement < Metadata > } [ ] ,
32+ currentImage ?: { url : string ; file : FileElement < Metadata > } ,
33+ ) => void
2534}
2635
27- interface ExportOptionMenu {
36+ interface ExportOptionMenu <
37+ Metadata extends RequiredMetadata = RequiredMetadata ,
38+ > {
2839 type : "menu"
2940 label : string
3041 icon ?: React . ReactElement
3142 isVisible : boolean | ( ( images : string [ ] , currentImage ?: string ) => boolean )
32- options : Array < Omit < ExportOptionButton , "type" > >
43+ options : Array < Omit < ExportOptionButton < Metadata > , "type" > >
3344}
3445
35- export interface HeaderProps {
46+ export interface HeaderProps <
47+ Metadata extends RequiredMetadata = RequiredMetadata ,
48+ > {
3649 onClose : ( ) => void
37- exportOptions ?: Array < ExportOptionButton | ExportOptionMenu >
50+ exportOptions ?: Array <
51+ ExportOptionButton < Metadata > | ExportOptionMenu < Metadata >
52+ >
3853}
3954
4055export const Header = ( { onClose, exportOptions } : HeaderProps ) => {
41- const { imageList, currentImage } = useEditorStore ( )
56+ const { imageList, originalImageList , currentImage } = useEditorStore ( )
4257
4358 const headerText = useMemo ( ( ) => {
4459 if ( imageList . length === 1 ) {
@@ -92,7 +107,19 @@ export const Header = ({ onClose, exportOptions }: HeaderProps) => {
92107 borderRadius = "0"
93108 px = "8"
94109 size = "sm"
95- onClick = { ( ) => exportOption . onClick ( imageList , currentImage ) }
110+ onClick = { ( ) => {
111+ const images = imageList . map ( ( image , index ) => ( {
112+ url : image ,
113+ file : originalImageList [ index ] ,
114+ } ) )
115+ const cImage = images . find (
116+ ( image ) => image . url === currentImage ,
117+ )
118+ exportOption . onClick ( images , {
119+ url : cImage ! . url ,
120+ file : cImage ! . file ,
121+ } )
122+ } }
96123 >
97124 { exportOption . label }
98125 </ Button >
@@ -121,7 +148,19 @@ export const Header = ({ onClose, exportOptions }: HeaderProps) => {
121148 . map ( ( option ) => (
122149 < MenuItem
123150 key = { `export-menu-option-${ option . label } ` }
124- onClick = { ( ) => option . onClick ( imageList , currentImage ) }
151+ onClick = { ( ) => {
152+ const images = imageList . map ( ( image , index ) => ( {
153+ url : image ,
154+ file : originalImageList [ index ] ,
155+ } ) )
156+ const cImage = images . find (
157+ ( image ) => image . url === currentImage ,
158+ )
159+ option . onClick ( images , {
160+ url : cImage ! . url ,
161+ file : cImage ! . file ,
162+ } )
163+ } }
125164 >
126165 { option . label }
127166 </ MenuItem >
0 commit comments