import { KeyboardEvent } from 'react'; import { connect } from 'react-redux'; import { App, GlobalState } from '../../../interfaces'; import { pinApp, deleteApp } from '../../../store/actions'; import classes from './AppTable.module.css'; import Icon from '../../UI/Icons/Icon/Icon'; interface ComponentProps { apps: App[]; pinApp: (app: App) => void; deleteApp: (id: number) => void; updateAppHandler: (app: App) => void; } const AppTable = (props: ComponentProps): JSX.Element => { const deleteAppHandler = (app: App): void => { const proceed = window.confirm(`Are you sure you want to delete ${app.name} at ${app.url} ?`); if (proceed) { props.deleteApp(app.id); } } const keyboardActionHandler = (e: KeyboardEvent, app: App, handler: Function) => { if (e.key === 'Enter') { handler(app); } } return (
Name | Url | Icon | Actions |
---|---|---|---|
{app.name} | {app.url} | {app.icon} |
deleteAppHandler(app)}
onKeyDown={(e) => keyboardActionHandler(e, app, deleteAppHandler)}
tabIndex={0}>
props.updateAppHandler(app)}
onKeyDown={(e) => keyboardActionHandler(e, app, props.updateAppHandler)}
tabIndex={0}>
props.pinApp(app)}
onKeyDown={(e) => keyboardActionHandler(e, app, props.pinApp)}
tabIndex={0}>
{app.isPinned
?
|