Skip to content

Commit

Permalink
Adding onReady and onError callback for standalone footer
Browse files Browse the repository at this point in the history
  • Loading branch information
bandana147 committed Feb 24, 2025
1 parent b365db2 commit a85deb5
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 20 deletions.
14 changes: 12 additions & 2 deletions libs/blocks/global-footer/global-footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,16 @@ class Footer {
shouldDecorateLinks: false,
});

if (!this.body) return;
if (!this.body) {
const error = new Error('Could not create global footer. Content not found!');
error.tags = 'global-footer';
error.url = url;
error.errorType = 'error';
lanaLog({ message: error.message, ...error });
const { onFooterError } = getConfig();
onFooterError?.(error);
return;
}

const [region, social] = ['.region-selector', '.social'].map((selector) => this.body.querySelector(selector));
const [regionParent, socialParent] = [region?.parentElement, social?.parentElement];
Expand Down Expand Up @@ -112,8 +121,9 @@ class Footer {

const mepMartech = mep?.martech || '';
this.block.setAttribute('daa-lh', `gnav|${getExperienceName()}|footer${mepMartech}`);

this.block.append(this.elements.footer);
const { onFooterReady } = getConfig();
onFooterReady?.();
}, 'Failed to decorate footer content', 'global-footer', 'error');

loadMenuLogic = async () => {
Expand Down
1 change: 1 addition & 0 deletions libs/navigation/bootstrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default async function bootstrapBlock(initBlock, blockConfig) {
{ key: 'unavComponents', name: 'universal-nav' },
{ key: 'redirect', name: 'adobe-home-redirect' },
{ key: 'mobileGnavV2', name: 'mobile-gnav-v2' },
{ key: 'footerSource', name: 'footer-source' },
];
metaTags.forEach((tag) => {
const { key } = tag;
Expand Down
49 changes: 31 additions & 18 deletions libs/navigation/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,20 @@ export default async function loadBlock(configs, customLib) {
stageDomainsMap: getStageDomainsMap(stageDomainsMap),
origin: `https://main--federal--adobecom.aem.${env === 'prod' ? 'live' : 'page'}`,
allowedOrigins: [...allowedOrigins, `https://main--federal--adobecom.aem.${env === 'prod' ? 'live' : 'page'}`],
onFooterReady: footer?.onReady,
onFooterError: footer?.onError,
...paramConfigs,
};
setConfig(clientConfig);
for await (const block of blockConfig) {
const configBlock = configs[block.key];
const config = getConfig();
const gnavSource = `${config?.locale?.contentRoot}/gnav`;
try {
if (configBlock) {
if (block.key === 'header') {
const footerSource = `${config?.locale?.contentRoot}/footer`;

if (configBlock) {
if (block.key === 'header') {
try {
const { default: init } = await import('../blocks/global-navigation/global-navigation.js');
await bootstrapBlock(init, {
...block,
Expand All @@ -146,24 +150,33 @@ export default async function loadBlock(configs, customLib) {
isLocalNav: configBlock.isLocalNav,
mobileGnavV2: configBlock.mobileGnavV2 || 'off',
});
} else if (block.key === 'footer') {
try {
await import('./footer.css');
} catch (e) {
loadStyle(`${miloLibs}/libs/navigation/footer.css`);
}
configBlock.onReady?.();
} catch (e) {
configBlock.onError?.(e);
window.lana.log(`${e.message} | gnav-source: ${gnavSource} | href: ${window.location.href}`, {
clientId: 'feds-milo',
tags: 'standalone-gnav',
errorType: e.errorType,
});
}
} else if (block.key === 'footer') {
try {
await import('./footer.css');
} catch (e) {
loadStyle(`${miloLibs}/libs/navigation/footer.css`);
}
try {
const { default: init } = await import('../blocks/global-footer/global-footer.js');
await bootstrapBlock(init, { ...block });
await bootstrapBlock(init, { ...block, footerSource });
} catch (e) {
configBlock.onError?.(e);
window.lana.log(`${e.message} | footer-source: ${footerSource} | href: ${window.location.href}`, {
clientId: 'feds-milo',
tags: 'standalone-footer',
errorType: e.errorType,
});
}
configBlock.onReady?.();
}
} catch (e) {
configBlock.onError?.(e);
window.lana.log(`${e.message} | gnav-source: ${gnavSource} | href: ${window.location.href}`, {
clientId: 'feds-milo',
tags: 'standalone-gnav',
errorType: e.errorType,
});
}
}
}
Expand Down

0 comments on commit a85deb5

Please sign in to comment.