11import { DA_ORIGIN } from '../public/utils/constants.js' ;
22import { loadBlock } from '../scripts/nexter.js' ;
33
4+ const DEF_SANDBOX = 'aem-sandbox' ;
45const TOAST_PATH = '/fragments/toasts/sandbox' ;
56
67async function getIsSandbox ( org ) {
@@ -16,18 +17,20 @@ async function getIsSandbox(org) {
1617 return json . length > 0 ;
1718}
1819
19- ( async function orgCheck ( ) {
20- const { pathname, hash } = window . location ;
20+ async function orgCheck ( ) {
21+ // Remove existing toast if it exists
22+ document . querySelector ( '.toast.sandbox-org' ) ?. remove ( ) ;
2123
24+ const { pathname, hash } = window . location ;
2225 // Do not show on app screens
2326 if ( pathname . startsWith ( '/app' ) ) return ;
2427 if ( ! hash ) return ;
2528 const hashVal = hash . replace ( '#' , '' ) ;
2629 // Do nothing if not a path
2730 if ( ! hashVal . startsWith ( '/' ) ) return ;
2831 const [ org ] = hashVal . substring ( 1 ) . split ( '/' ) ;
29- // Do nothing if no org
30- if ( ! org ) return ;
32+ // Do nothing if no org or known sandbox
33+ if ( ! org || org === DEF_SANDBOX ) return ;
3134 const isSandbox = await getIsSandbox ( org ) ;
3235 // Do nothing if not a sandbox
3336 if ( ! isSandbox ) return ;
@@ -36,5 +39,9 @@ async function getIsSandbox(org) {
3639 const link = document . createElement ( 'a' ) ;
3740 link . href = TOAST_PATH ;
3841 link . className = 'nx-toast' ;
42+ link . id = 'sandbox-org' ;
3943 loadBlock ( link ) ;
40- } ( ) ) ;
44+ }
45+
46+ orgCheck ( ) ;
47+ window . addEventListener ( 'hashchange' , orgCheck ) ;
0 commit comments