UNPKG

@jeremyckahn/farmhand

Version:
33 lines (31 loc) 945 B
// 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: farmhand.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 }), } }