@@ -4,19 +4,18 @@ import type { AppToast } from "../utils/studioHelpers";
44
55interface ToastItem extends AppToast {
66 id : number ;
7- /** True while the exit animation plays, just before removal. */
8- leaving ?: boolean ;
97}
108
119const AUTO_DISMISS_MS = 4000 ;
12- const EXIT_MS = 160 ;
1310const MAX_TOASTS = 3 ;
1411
12+ /** Error toasts persist until dismissed so failures can't silently vanish. */
13+ export const toastPersists = ( tone : AppToast [ "tone" ] ) => tone === "error" ;
14+
1515let nextToastId = 1 ;
1616
1717/**
18- * Stacked toasts (max 3). Info toasts auto-dismiss after 4s; error toasts
19- * persist until explicitly dismissed so failures can't silently vanish.
18+ * Stacked toasts (max 3). Info toasts auto-dismiss after 4s; error toasts persist.
2019 */
2120export function useToast ( ) {
2221 const [ toasts , setToasts ] = useState < ToastItem [ ] > ( [ ] ) ;
@@ -30,25 +29,14 @@ export function useToast() {
3029 }
3130 } , [ ] ) ;
3231
33- const removeToast = useCallback (
32+ const dismissToast = useCallback (
3433 ( id : number ) => {
3534 clearTimer ( id ) ;
3635 setToasts ( ( prev ) => prev . filter ( ( t ) => t . id !== id ) ) ;
3736 } ,
3837 [ clearTimer ] ,
3938 ) ;
4039
41- const dismissToast = useCallback (
42- ( id : number ) => {
43- clearTimer ( id ) ;
44- // Mark leaving so the exit animation plays, then remove.
45- setToasts ( ( prev ) => prev . map ( ( t ) => ( t . id === id ? { ...t , leaving : true } : t ) ) ) ;
46- const timer = setTimeout ( ( ) => removeToast ( id ) , EXIT_MS ) ;
47- timersRef . current . set ( id , timer ) ;
48- } ,
49- [ clearTimer , removeToast ] ,
50- ) ;
51-
5240 const showToast = useCallback (
5341 ( message : string , tone : AppToast [ "tone" ] = "error" ) : number => {
5442 const id = nextToastId ++ ;
@@ -61,7 +49,7 @@ export function useToast() {
6149 }
6250 return next ;
6351 } ) ;
64- if ( tone !== "error" ) {
52+ if ( ! toastPersists ( tone ) ) {
6553 const timer = setTimeout ( ( ) => dismissToast ( id ) , AUTO_DISMISS_MS ) ;
6654 timersRef . current . set ( id , timer ) ;
6755 }
0 commit comments