Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public componentDidUpdate(prevProps: ISiteProps, prevState: ISiteState): void {
if (prevState.pagePath !== this.state.pagePath) {
this._jumpToAnchor(extractAnchorLink(location.hash));
}
const { activePages, pagePlatforms } = this.state;
const { siteDefinition } = this.props;
// If current page doesn't have pages for the active platform, switch to its first platform.
if (Object.keys(pagePlatforms).length > 0 && activePages.length === 0) {
const firstPlatform = getPageFirstPlatform(getSiteArea(siteDefinition.pages), siteDefinition);
this._onPlatformChanged(firstPlatform);
}
}
} catch (ex) {
// ignore
}
// Set active platform for each top level page to local storage platform or the first platform defined for that page.
topLevelPages.forEach(item => {
activePlatforms[item] = activePlatforms[item] || getPageFirstPlatform(item, siteDefinition);
});
}
const navData = this._getNavData(activePlatforms);
let platform = 'default' as TPlatforms;
// If current page doesn't have pages for the active platform, switch to its first platform.
if (Object.keys(navData.pagePlatforms).length > 0 && navData.activePages.length === 0) {
const firstPlatform = getPageFirstPlatform(getSiteArea(siteDefinition.pages), siteDefinition);
const currentPage = getSiteArea(siteDefinition.pages);
platform = firstPlatform;
activePlatforms = {
...activePlatforms,
[currentPage]: firstPlatform
};
}
this.state = {
activePlatforms,
platform,
...navData
};
}
topLevelPages.forEach(item => {
activePlatforms[item] = activePlatforms[item] || getPageFirstPlatform(item, siteDefinition);
});
}