Skip to content

Commit 576627e

Browse files
committed
Support hash changes
1 parent 4e14f05 commit 576627e

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

nx/blocks/toast/toast.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ export default async function init(a) {
1919
}
2020

2121
// Setup basic styles
22-
toast.classList.add('toast', 'toast-warning');
22+
toast.classList.add('toast', 'toast-warning', 'sandbox-org');
2323
document.body.append(toast);
2424
}

nx/utils/org-check.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { DA_ORIGIN } from '../public/utils/constants.js';
22
import { loadBlock } from '../scripts/nexter.js';
33

4+
const DEF_SANDBOX = 'aem-sandbox';
45
const TOAST_PATH = '/fragments/toasts/sandbox';
56

67
async 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

Comments
 (0)