@@ -3,7 +3,7 @@ import { useNavigate } from "@tanstack/react-router";
33import { useAtomValue } from "@effect/atom-react" ;
44import type { ServerProvider } from "@t3tools/contracts" ;
55import { CircleCheckIcon , DownloadIcon , TriangleAlertIcon , XIcon } from "lucide-react" ;
6- import { useCallback , useEffect , useState , type CSSProperties } from "react" ;
6+ import { useEffect , useEffectEvent , useState , type CSSProperties } from "react" ;
77
88import { primaryServerProvidersAtom } from "../../state/server" ;
99import {
@@ -56,15 +56,13 @@ export function SidebarProviderUpdatePill() {
5656 dismissedKeys,
5757 } ) ;
5858
59- useEffect ( ( ) => {
60- if ( visibleAfterIso === undefined && effectiveVisibleAfterIso !== undefined ) {
61- setVisibleAfterIso ( effectiveVisibleAfterIso ) ;
62- }
63- } , [ effectiveVisibleAfterIso , visibleAfterIso ] ) ;
59+ if ( visibleAfterIso === undefined && effectiveVisibleAfterIso !== undefined ) {
60+ setVisibleAfterIso ( effectiveVisibleAfterIso ) ;
61+ }
6462
65- const openProviderSettings = useCallback ( ( ) => {
63+ const openProviderSettings = ( ) => {
6664 void navigate ( { to : "/settings/providers" } ) ;
67- } , [ navigate ] ) ;
65+ } ;
6866 const displayedView = renderedView ?? view ;
6967 const dismissAfterVisibleMs = displayedView ?. dismissAfterVisibleMs ;
7068 const viewKey = displayedView ?. key ?? null ;
@@ -73,37 +71,32 @@ export function SidebarProviderUpdatePill() {
7371 displayedView ?. tone !== "loading" &&
7472 exitingKey !== viewKey ;
7573
76- const startExit = useCallback (
77- ( key : string , nextView : ProviderUpdateSidebarPillView | null , dismissKey ?: string ) => {
78- if ( exitingKey === key ) {
79- return ;
80- }
81- setPendingView ( nextView ) ;
82- setExitingKey ( key ) ;
83- setDismissAfterExitKey ( dismissKey ?? null ) ;
84- } ,
85- [ exitingKey ] ,
86- ) ;
87-
88- useEffect ( ( ) => {
89- if ( exitingKey !== null ) {
74+ const startExit = (
75+ key : string ,
76+ nextView : ProviderUpdateSidebarPillView | null ,
77+ dismissKey ?: string ,
78+ ) => {
79+ if ( exitingKey === key ) {
9080 return ;
9181 }
82+ setPendingView ( nextView ) ;
83+ setExitingKey ( key ) ;
84+ setDismissAfterExitKey ( dismissKey ?? null ) ;
85+ } ;
86+
87+ if ( exitingKey === null ) {
9288 if ( ! renderedView ) {
9389 if ( view ) {
9490 setRenderedView ( view ) ;
9591 }
96- return ;
97- }
98- if ( ! view ) {
92+ } else if ( ! view ) {
9993 startExit ( renderedView . key , null ) ;
100- return ;
101- }
102- if ( view . key !== renderedView . key ) {
94+ } else if ( view . key !== renderedView . key ) {
10395 startExit ( renderedView . key , view ) ;
104- return ;
10596 }
106- } , [ exitingKey , renderedView , startExit , view ] ) ;
97+ }
98+
99+ const exitAfterVisible = useEffectEvent ( ( key : string ) => startExit ( key , null , key ) ) ;
107100
108101 useEffect ( ( ) => {
109102 if ( ! dismissAfterVisibleMs || ! viewKey ) {
@@ -113,11 +106,11 @@ export function SidebarProviderUpdatePill() {
113106 return ;
114107 }
115108 const timeoutId = window . setTimeout ( ( ) => {
116- startExit ( viewKey , null , viewKey ) ;
109+ exitAfterVisible ( viewKey ) ;
117110 } , dismissAfterVisibleMs ) ;
118111
119112 return ( ) => window . clearTimeout ( timeoutId ) ;
120- } , [ dismissAfterVisibleMs , exitingKey , startExit , viewKey ] ) ;
113+ } , [ dismissAfterVisibleMs , exitingKey , viewKey ] ) ;
121114
122115 if ( ! displayedView ) {
123116 return null ;
0 commit comments