UNPKG

@jeremyckahn/farmhand

Version:
34 lines (32 loc) • 990 B
import { notificationSeverity } from '../../enums.js' // TODO: Change showNotification to accept a configuration object instead of so // many formal parameters. /** * @param severity Corresponds to the `severity` prop here: https://material-ui.com/api/alert/ * @see ://material-ui.com/api/alert/ */ export const showNotification = ( state: farmhand.state, message: string, severity: notificationSeverity = 'info', onClick: import('@mui/material/Alert').AlertProps['onClick'] = undefined ): farmhand.state => { const { showNotifications, todaysNotifications } = state return { ...state, ...(showNotifications && { latestNotification: { message, onClick, severity, }, }), // Don't show redundant notifications todaysNotifications: todaysNotifications.find( notification => notification.message === message ) ? todaysNotifications : todaysNotifications.concat({ message, onClick, severity }), } }