@veracity/vui
Version:
Veracity UI is a React component library crafted for use within Veracity applications and pages. Based on Styled Components and @xstyled.
47 lines (45 loc) • 1.29 kB
JavaScript
import { cdnUrls } from "../core/consts.js";
import { isObject } from "../utils/assertion.js";
import { useLinks } from "../core/links.js";
import { useEffect, useState } from "react";
//#region src/header/helpers.ts
/** Loads templates for Header links and enriches them with urls from LinksContext. */
function useHeaderLinks(env) {
const [templates, setTemplates] = useState({});
const [links] = useLinks();
useEffect(() => {
loadHeaderLinks();
async function loadHeaderLinks() {
try {
const response = await fetch(`${cdnUrls[env]}/common/data/links/header.json`);
if (!response.ok) return;
const data = await response.json();
if (isObject(data)) setTemplates({
accountSections: data.accountSections,
mainLinks: data.mainLinks
});
} catch {
console.error("Failed to retrieve header data.");
}
}
}, [env]);
return {
accountSections: templates.accountSections?.map((section) => {
return {
...section,
links: section.links?.map((link) => ({
...link,
url: links[link?.id ?? ""]
}))
};
}),
mainLinks: templates.mainLinks?.map((link) => ({
...link,
url: links[link?.id ?? ""]
}))
};
}
//#endregion
export { useHeaderLinks };
globalThis.__vuiVersion__ = "5.3.1"
//# sourceMappingURL=helpers.js.map