@@ -93,6 +93,38 @@ export function useDevPresence() {
9393 return context ;
9494}
9595
96+ /**
97+ * We need this for the legacy v1 engine, where we show the banner after a delay if there are no events.
98+ */
99+ export function useCrossEngineIsConnected ( { logCount } : { logCount : number } ) {
100+ const project = useProject ( ) ;
101+ const environment = useEnvironment ( ) ;
102+ const { isConnected } = useDevPresence ( ) ;
103+ const [ crossEngineIsConnected , setCrossEngineIsConnected ] = useState < boolean | undefined > (
104+ undefined
105+ ) ;
106+
107+ useEffect ( ( ) => {
108+ if ( project . engine === "V2" ) {
109+ setCrossEngineIsConnected ( isConnected ) ;
110+ return ;
111+ }
112+
113+ if ( project . engine === "V1" ) {
114+ if ( logCount <= 1 ) {
115+ const timer = setTimeout ( ( ) => {
116+ setCrossEngineIsConnected ( false ) ;
117+ } , 5000 ) ;
118+ return ( ) => clearTimeout ( timer ) ;
119+ } else {
120+ setCrossEngineIsConnected ( true ) ;
121+ }
122+ }
123+ } , [ environment . type , project . engine , logCount , isConnected ] ) ;
124+
125+ return crossEngineIsConnected ;
126+ }
127+
96128export function ConnectionIcon ( { isConnected } : { isConnected : boolean | undefined } ) {
97129 if ( isConnected === undefined ) {
98130 return < CheckingConnectionIcon className = "size-5" /> ;
@@ -104,88 +136,75 @@ export function ConnectionIcon({ isConnected }: { isConnected: boolean | undefin
104136 ) ;
105137}
106138
107- export function DevConnection ( {
108- children,
109- } : {
110- children : ( props : { isConnected : boolean | undefined } ) => React . ReactNode ;
111- } ) {
112- const { isConnected } = useDevPresence ( ) ;
113-
139+ export function DevPresencePanel ( { isConnected } : { isConnected : boolean | undefined } ) {
114140 return (
115- < Dialog >
116- { children ( { isConnected } ) }
117- < DialogContent >
118- < DialogHeader >
119- { isConnected === undefined
120- ? "Checking connection..."
121- : isConnected
122- ? "Your dev server is connected"
123- : "Your dev server is not connected" }
124- </ DialogHeader >
125- < div className = "mt-2 flex flex-col gap-3 px-2" >
126- < div className = "flex flex-col items-center justify-center gap-6 px-6 py-10" >
127- < img
128- src = { isConnected === true ? connectedImage : disconnectedImage }
129- alt = { isConnected === true ? "Connected" : "Disconnected" }
130- width = { 282 }
131- height = { 45 }
132- />
133- < Paragraph variant = "small" className = { isConnected ? "text-success" : "text-error" } >
134- { isConnected === undefined
135- ? "Checking connection..."
136- : isConnected
137- ? "Your local dev server is connected to Trigger.dev"
138- : "Your local dev server is not connected to Trigger.dev" }
141+ < DialogContent >
142+ < DialogHeader >
143+ { isConnected === undefined
144+ ? "Checking connection..."
145+ : isConnected
146+ ? "Your dev server is connected"
147+ : "Your dev server is not connected" }
148+ </ DialogHeader >
149+ < div className = "mt-2 flex flex-col gap-3 px-2" >
150+ < div className = "flex flex-col items-center justify-center gap-6 px-6 py-10" >
151+ < img
152+ src = { isConnected === true ? connectedImage : disconnectedImage }
153+ alt = { isConnected === true ? "Connected" : "Disconnected" }
154+ width = { 282 }
155+ height = { 45 }
156+ />
157+ < Paragraph variant = "small" className = { isConnected ? "text-success" : "text-error" } >
158+ { isConnected === undefined
159+ ? "Checking connection..."
160+ : isConnected
161+ ? "Your local dev server is connected to Trigger.dev"
162+ : "Your local dev server is not connected to Trigger.dev" }
163+ </ Paragraph >
164+ </ div >
165+ { isConnected ? null : (
166+ < div className = "space-y-3" >
167+ < PackageManagerProvider >
168+ < TriggerDevStepV3 title = "Run this command to connect" />
169+ </ PackageManagerProvider >
170+ < Paragraph variant = "small" >
171+ Run this CLI < InlineCode variant = "extra-small" > dev</ InlineCode > command to connect to
172+ the Trigger.dev servers to start developing locally. Keep it running while you develop
173+ to stay connected. Learn more in the{ " " }
174+ < TextLink to = { docsPath ( "cli-dev" ) } > CLI docs</ TextLink > .
139175 </ Paragraph >
140176 </ div >
141- { isConnected ? null : (
142- < div className = "space-y-3" >
143- < PackageManagerProvider >
144- < TriggerDevStepV3 title = "Run this command to connect" />
145- </ PackageManagerProvider >
146- < Paragraph variant = "small" >
147- Run this CLI < InlineCode variant = "extra-small" > dev</ InlineCode > command to connect
148- to the Trigger.dev servers to start developing locally. Keep it running while you
149- develop to stay connected. Learn more in the{ " " }
150- < TextLink to = { docsPath ( "cli-dev" ) } > CLI docs</ TextLink > .
151- </ Paragraph >
152- </ div >
153- ) }
154- </ div >
155- </ DialogContent >
156- </ Dialog >
177+ ) }
178+ </ div >
179+ </ DialogContent >
157180 ) ;
158181}
159182
160- export function DevPresenceBanner ( ) {
161- const environment = useEnvironment ( ) ;
162- const { isConnected } = useDevPresence ( ) ;
163-
183+ export function DevDisconnectedBanner ( { isConnected } : { isConnected : boolean | undefined } ) {
164184 return (
165- < AnimatePresence >
166- { environment . type === "DEVELOPMENT" && ! isConnected && (
185+ < Dialog >
186+ < AnimatePresence >
167187 < motion . div
168188 initial = { { opacity : 0 } }
169189 animate = { { opacity : 1 } }
170190 exit = { { opacity : 0 } }
171191 transition = { { duration : 0.3 } }
172192 className = "flex"
173193 >
174- < DevConnection >
175- { ( { isConnected } ) => (
176- < DialogTrigger asChild >
177- < Button
178- variant = "minimal/small"
179- className = "py-1 pl-1 pr-2 text-error"
180- LeadingIcon = { < ConnectionIcon isConnected = { isConnected } /> }
181- >
182- Your local dev server is not connected to Trigger.dev
183- </ Button >
184- </ DialogTrigger >
185- ) }
186- </ DevConnection >
194+ { isConnected === false && (
195+ < DialogTrigger asChild >
196+ < Button
197+ variant = "minimal/small"
198+ className = "py-1 pl-1 pr-2 text-error"
199+ LeadingIcon = { < ConnectionIcon isConnected = { false } /> }
200+ >
201+ Your local dev server is not connected to Trigger.dev
202+ </ Button >
203+ </ DialogTrigger >
204+ ) }
187205 </ motion . div >
188- ) }
189- </ AnimatePresence >
206+ </ AnimatePresence >
207+ < DevPresencePanel isConnected = { isConnected } />
208+ </ Dialog >
190209 ) ;
191210}
0 commit comments