introduce `persistOnNavigate` option for toasts (#1095)

ensure that post auto-delete success toasts are preserved
when navigating back to the prior page
This commit is contained in:
SatsAllDay 2024-04-21 18:25:48 -04:00 committed by GitHub
parent fa5adac297
commit fbd3f8efed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 2 deletions

View File

@ -110,7 +110,7 @@ export const ToastProvider = ({ children }) => {
// Only clear toasts with no cancel function on page navigation
// since navigation should not interfere with being able to cancel an action.
useEffect(() => {
const handleRouteChangeStart = () => setToasts(toasts => toasts.length > 0 ? toasts.filter(({ onCancel, onUndo }) => onCancel || onUndo) : toasts)
const handleRouteChangeStart = () => setToasts(toasts => toasts.length > 0 ? toasts.filter(({ onCancel, onUndo, persistOnNavigate }) => onCancel || onUndo || persistOnNavigate) : toasts)
router.events.on('routeChangeStart', handleRouteChangeStart)
return () => {

View File

@ -40,6 +40,7 @@ export const toastDeleteScheduled = (toaster, upsertResponseData, dataKey, isEdi
}[dataKey] ?? 'item'
const message = `${itemType === 'comment' ? 'your comment' : isEdit ? `this ${itemType}` : `your new ${itemType}`} will be deleted at ${deleteScheduledAt.toLocaleString()}`
toaster.success(message)
// only persist this on navigation for posts, not comments
toaster.success(message, { persistOnNavigate: itemType !== 'comment' })
}
}