2023-08-25 18:42:31 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { store as interactivityApiStore } from '@woocommerce/interactivity';
|
|
|
|
|
|
|
|
interface State {
|
|
|
|
[ key: string ]: unknown;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface Context {
|
2023-08-31 15:13:40 +00:00
|
|
|
woocommerce: {
|
2023-09-12 07:36:44 +00:00
|
|
|
selectedImage: string;
|
|
|
|
imageId: string;
|
2023-09-15 08:54:49 +00:00
|
|
|
isDialogOpen: boolean;
|
2023-08-31 15:13:40 +00:00
|
|
|
};
|
2023-08-25 18:42:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
interface Selectors {
|
2023-08-31 15:13:40 +00:00
|
|
|
woocommerce: {
|
2023-09-12 07:36:44 +00:00
|
|
|
isSelected: ( store: unknown ) => boolean;
|
2023-09-21 19:35:25 +00:00
|
|
|
pagerDotFillOpacity: ( store: SelectorsStore ) => number;
|
2023-09-15 08:54:49 +00:00
|
|
|
isDialogOpen: ( store: unknown ) => boolean;
|
2023-09-12 07:36:44 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
interface Actions {
|
|
|
|
woocommerce: {
|
2023-09-15 08:54:49 +00:00
|
|
|
thumbnails: {
|
|
|
|
handleClick: ( context: Context ) => void;
|
|
|
|
};
|
2023-08-25 18:42:31 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
interface Store {
|
|
|
|
state: State;
|
|
|
|
context: Context;
|
|
|
|
selectors: Selectors;
|
2023-09-12 07:36:44 +00:00
|
|
|
actions: Actions;
|
|
|
|
ref?: HTMLElement;
|
2023-08-25 18:42:31 +00:00
|
|
|
}
|
|
|
|
|
2023-09-21 19:35:25 +00:00
|
|
|
type SelectorsStore = Pick< Store, 'context' | 'selectors' | 'ref' >;
|
|
|
|
|
2023-08-25 18:42:31 +00:00
|
|
|
interactivityApiStore( {
|
2023-09-12 07:36:44 +00:00
|
|
|
state: {},
|
2023-08-25 18:42:31 +00:00
|
|
|
selectors: {
|
2023-08-31 15:13:40 +00:00
|
|
|
woocommerce: {
|
2023-09-12 07:36:44 +00:00
|
|
|
isSelected: ( { context }: Store ) => {
|
|
|
|
return (
|
|
|
|
context?.woocommerce.selectedImage ===
|
|
|
|
context?.woocommerce.imageId
|
|
|
|
);
|
|
|
|
},
|
2023-09-21 19:35:25 +00:00
|
|
|
pagerDotFillOpacity( store: SelectorsStore ) {
|
|
|
|
const { context } = store;
|
|
|
|
|
|
|
|
return context?.woocommerce.selectedImage ===
|
|
|
|
context?.woocommerce.imageId
|
|
|
|
? 1
|
|
|
|
: 0.2;
|
|
|
|
},
|
2023-09-15 08:54:49 +00:00
|
|
|
isDialogOpen: ( { context }: Store ) => {
|
2023-10-02 12:36:48 +00:00
|
|
|
return context.woocommerce.isDialogOpen;
|
2023-09-15 08:54:49 +00:00
|
|
|
},
|
2023-09-12 07:36:44 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
actions: {
|
|
|
|
woocommerce: {
|
2023-09-15 08:54:49 +00:00
|
|
|
thumbnails: {
|
|
|
|
handleClick: ( { context }: Store ) => {
|
|
|
|
context.woocommerce.selectedImage =
|
|
|
|
context.woocommerce.imageId;
|
|
|
|
},
|
2023-08-25 18:42:31 +00:00
|
|
|
},
|
2023-10-02 12:36:48 +00:00
|
|
|
dialog: {
|
|
|
|
handleCloseButtonClick: ( { context }: Store ) => {
|
|
|
|
context.woocommerce.isDialogOpen = false;
|
|
|
|
},
|
|
|
|
},
|
2023-09-21 19:35:25 +00:00
|
|
|
handleSelectImage: ( { context }: Store ) => {
|
|
|
|
context.woocommerce.selectedImage = context.woocommerce.imageId;
|
|
|
|
},
|
2023-08-25 18:42:31 +00:00
|
|
|
},
|
|
|
|
},
|
2023-09-12 07:36:44 +00:00
|
|
|
} );
|