11import { useAtomValue } from "@effect/atom-react" ;
2- import { useEffect } from "react" ;
2+ import { useEffect , useState } from "react" ;
33
44import { undoLatestThreadAction , useThreadUndoNotice } from "../../hooks/showThreadUndoNotice" ;
55import { shortcutLabelForCommand } from "../../keybindings" ;
@@ -25,17 +25,27 @@ export function SidebarThreadUndoNotice({ className }: { className?: string }) {
2525 else cancelAnnouncement ( "thread-undo-notice" ) ;
2626 } , [ summary , undoLabel ] ) ;
2727
28- if ( ! summary ) return null ;
28+ // Keeps the last text on screen while it fades out, then unmounts on transitionend.
29+ const [ shownSummary , setShownSummary ] = useState ( summary ) ;
30+ if ( summary && summary !== shownSummary ) setShownSummary ( summary ) ;
31+ const text = summary ?? shownSummary ;
32+ if ( ! text ) return null ;
2933
3034 return (
3135 < div
3236 role = "group"
33- className = { cn ( "truncate px-2 text-2xs leading-6 text-sidebar-muted-foreground" , className ) }
37+ aria-hidden = { ! summary }
38+ inert = { ! summary }
39+ onTransitionEnd = { ( event ) => {
40+ if ( ! summary && event . target === event . currentTarget ) setShownSummary ( null ) ;
41+ } }
42+ className = { cn (
43+ "truncate px-2 text-2xs leading-6 text-sidebar-muted-foreground transition-opacity duration-200 ease-out starting:opacity-0" ,
44+ ! summary && "opacity-0" ,
45+ className ,
46+ ) }
3447 >
35- { summary } ,{ " " }
36- < InlineButton onClick = { undoLatestThreadAction } tone = "inherit" >
37- { undoLabel }
38- </ InlineButton >
48+ { text } , < InlineButton onClick = { undoLatestThreadAction } > { undoLabel } </ InlineButton >
3949 </ div >
4050 ) ;
4151}
0 commit comments