import React from 'react' import { connect, ConnectedProps } from 'react-redux' import { t, c } from 'ttag' import { loadConfiguration, resetConfiguration, deleteSave } from '../actions/saves' import { migrateConfiguration } from '../utils' import ShareURL from '../components/ShareURL' const connector = connect(null, (dispatch: (event: any) => any, { onClick }: { onClick: () => any }) => { return { onClick: () => { onClick() }, onLoad: (save: any) => { dispatch(resetConfiguration()) const migratedConfiguration = migrateConfiguration(save.configuration, save.version) /* In some cases where the loaded configuration is similar to the previous one, certain events aren't * fired if the event is dispatched in the same event cycle as the reset event */ setTimeout(() => dispatch(loadConfiguration(migratedConfiguration, save)), 0) }, onDelete: (saveId: string) => { dispatch(deleteSave(saveId)) }, } }) type SavedRunProps = ConnectedProps & { active: boolean save: any } const SavedRun = ({ active, save, onClick, onLoad, onDelete }: SavedRunProps) => { let className = 'configuration-item' const { modified, title } = save if (active) { className += ' focused' } return (
{ onClick() }} >
{title}
{t`Last modified:`} {modified.getMonth() + 1}/{modified.getDate()}/{modified.getYear()}
) } export default connector(SavedRun)