@@ -13,6 +13,7 @@ import type { Dialog } from "@/components/ui/dialog";
1313import {
1414 bgClass ,
1515 type BrowserConnectionChange ,
16+ type BrowserOriginsChange ,
1617 type ProfileBrowser ,
1718} from "@/features/browser-profiles/profile-browser" ;
1819import type {
@@ -24,6 +25,14 @@ import type { Profile } from "@/types/crawler";
2425import { isApiError } from "@/utils/api" ;
2526import { tw } from "@/utils/tailwind" ;
2627
28+ enum BrowserStatus {
29+ Initial ,
30+ Pending ,
31+ Ready ,
32+ Complete ,
33+ Error ,
34+ }
35+
2736/**
2837 * @fires btrix-updated
2938 */
@@ -43,7 +52,7 @@ export class ProfileBrowserDialog extends BtrixElement {
4352 open = false ;
4453
4554 @state ( )
46- private isBrowserLoaded = false ;
55+ private browserStatus = BrowserStatus . Initial ;
4756
4857 @state ( )
4958 private showConfirmation = false ;
@@ -77,7 +86,7 @@ export class ProfileBrowserDialog extends BtrixElement {
7786 if ( changedProperties . has ( "open" ) ) {
7887 if ( ! this . open ) {
7988 this . showConfirmation = false ;
80- this . isBrowserLoaded = false ;
89+ this . browserStatus = BrowserStatus . Initial ;
8190 this . #savedBrowserId = undefined ;
8291 this . browserIdTask . abort ( ) ;
8392 }
@@ -142,6 +151,7 @@ export class ProfileBrowserDialog extends BtrixElement {
142151 render ( ) {
143152 const isCrawler = this . appState . isCrawler ;
144153 const creatingNew = this . duplicating || ! this . profile ;
154+ const incomplete = this . browserStatus !== BrowserStatus . Complete ;
145155 const saving = this . saveProfileTask . status === TaskStatus . PENDING ;
146156
147157 return html `< btrix-dialog
@@ -245,7 +255,9 @@ export class ProfileBrowserDialog extends BtrixElement {
245255 >
246256 < sl-button
247257 size ="small "
248- @click =${ this . showConfirmation || ! this . isBrowserLoaded
258+ @click =${ this . showConfirmation ||
259+ this . browserStatus < BrowserStatus . Ready ||
260+ this . browserStatus === BrowserStatus . Error
249261 ? ( ) => void this . dialog ?. hide ( )
250262 : ( ) => ( this . showConfirmation = true ) }
251263 >
@@ -254,13 +266,13 @@ export class ProfileBrowserDialog extends BtrixElement {
254266 </ btrix-popover >
255267
256268 < btrix-popover
257- content =${ msg ( "Save disabled during load. " ) }
258- ?disabled =${ this . isBrowserLoaded }
269+ content =${ msg ( "Disabled until page is finished loading " ) }
270+ ?disabled =${ ! incomplete }
259271 >
260272 < sl-button
261273 size ="small "
262274 variant ="primary "
263- ?disabled =${ ! this . isBrowserLoaded || saving }
275+ ?disabled =${ incomplete || saving }
264276 ?loading =${ saving }
265277 @click=${ ( ) => void this . submit ( ) }
266278 >
@@ -289,12 +301,16 @@ export class ProfileBrowserDialog extends BtrixElement {
289301 ? html `< btrix-profile-browser
290302 browserId =${ browserId }
291303 initialNavigateUrl =${ ifDefined ( this . config ?. url ) }
292- .initialOrigins=${ this . profile ?. origins }
304+ .initialOrigins=${ this . config ?. profileId
305+ ? this . profile ?. origins
306+ : // Profile is being replaced if ID is not specified
307+ undefined }
293308 @btrix-browser-load=${ this . onBrowserLoad }
294309 @btrix-browser-reload=${ this . onBrowserReload }
295310 @btrix-browser-error=${ this . onBrowserError }
296311 @btrix-browser-connection-change=${ this
297312 . onBrowserConnectionChange }
313+ @btrix-browser-origins-change=${ this . onBrowserOriginsChange }
298314 hideControls
299315 tabindex="0"
300316 .autofocus=${ true }
@@ -306,25 +322,35 @@ export class ProfileBrowserDialog extends BtrixElement {
306322 }
307323
308324 private readonly closeBrowser = ( ) => {
309- this . isBrowserLoaded = false ;
325+ this . browserStatus = BrowserStatus . Initial ;
310326 } ;
311327
312328 private readonly onBrowserLoad = ( ) => {
313- this . isBrowserLoaded = true ;
329+ this . browserStatus = BrowserStatus . Ready ;
314330 } ;
315331
316332 private readonly onBrowserReload = ( ) => {
317- this . isBrowserLoaded = false ;
333+ this . browserStatus = BrowserStatus . Pending ;
318334 } ;
319335
320336 private readonly onBrowserError = ( ) => {
321- this . isBrowserLoaded = false ;
337+ this . browserStatus = BrowserStatus . Error ;
338+ } ;
339+
340+ private readonly onBrowserOriginsChange = (
341+ e : CustomEvent < BrowserOriginsChange > ,
342+ ) => {
343+ if ( e . detail . origins . length ) {
344+ this . browserStatus = BrowserStatus . Complete ;
345+ }
322346 } ;
323347
324348 private readonly onBrowserConnectionChange = (
325349 e : CustomEvent < BrowserConnectionChange > ,
326350 ) => {
327- this . isBrowserLoaded = e . detail . connected ;
351+ this . browserStatus = e . detail . connected
352+ ? BrowserStatus . Pending
353+ : BrowserStatus . Initial ;
328354 } ;
329355
330356 private async submit ( ) {
0 commit comments