import "./PhotoCard.scss"; import { Card, ContextMenuTarget, Menu, MenuItem, Spinner, } from "@blueprintjs/core"; import * as React from "react"; import { IPhotoReqJSON } from "~/src/shared/types"; import { getPhotoThumbPath } from "../redux/api/photos"; import { showDeletionToast } from "../AppToaster"; import { Dispatch } from "redux"; import { photosDeleteCancel, photosDeleteStart } from "../redux/photos/actions"; import { connect } from "react-redux"; import { RouteComponentProps, withRouter } from "react-router"; import { PreviewSize } from "./helper"; export interface IPhotoCardComponentProps extends RouteComponentProps { photo: IPhotoReqJSON; selected: boolean; id: string; deletePhoto: (photos: IPhotoReqJSON[]) => void; cancelDelete: (photos: IPhotoReqJSON[]) => void; onClick: (e: React.MouseEvent) => void; } export interface IPhotoCardComponentState { loaded: boolean; } const defaultPhotoCardState: IPhotoCardComponentState = { loaded: false, }; @ContextMenuTarget export class PhotoCardComponent extends React.PureComponent< IPhotoCardComponentProps, IPhotoCardComponentState > { constructor(props: IPhotoCardComponentProps) { super(props); this.handleDelete = this.handleDelete.bind(this); this.setLoaded = this.setLoaded.bind(this); //this.handleEdit = this.handleEdit.bind(this); this.state = defaultPhotoCardState; } private setLoaded(loaded: boolean) { this.setState({ ...this.state, loaded }); } public handleDelete(): void { showDeletionToast(() => this.props.cancelDelete([this.props.photo])); this.props.deletePhoto([this.props.photo]); } /* public handleEdit() { this.props.history.push(`/docs/${this.props.doc.id}/edit`); } */ public render(): JSX.Element { const fileExists = this.props.photo.uploaded; const preloadImage = (url: string) => { const img = new Image(); img.src = url; }; return ( ) => this.props.onClick(e) } > {fileExists ? ( this.setLoaded(true)} /* onMouseEnter={() => preloadImage( getPhotoThumbPath(this.props.photo, LargeSize), ) } */ > ) : ( )} ); } public renderContextMenu(): JSX.Element { return ( {/* */} ); } } function mapDispatchToProps(dispatch: Dispatch) { return { deletePhoto: (photos: IPhotoReqJSON[]) => dispatch(photosDeleteStart(photos)), cancelDelete: (photos: IPhotoReqJSON[]) => dispatch(photosDeleteCancel(photos)), }; } export const PhotoCard = withRouter( connect(null, mapDispatchToProps)(PhotoCardComponent), );