feat(web): render similar schools on both detail templates
Inside SchoolDetailShell rather than after it, because the sticky nav's scroll-spy finds sections with getElementById and can only reach one that lives in the shell. Last in the order, and last in the nav, because the two must agree or the nav links to an anchor that was never rendered. hasSimilarSchools is optional on NavItemsInput, matching hasLocation beside it: absent has to mean "no section", and making it required would have churned ten unrelated call sites for no added safety. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
91314a80b5
commit
4e0d8bcf87
5 files changed
+86
-5
No files matched your search
@@ -128,6 +128,10 @@ export interface NavItemsInput {
|
||||
* measure a postcode, so the nav must gate on them too or it will link to an
|
||||
* anchor that was never rendered. */
|
||||
hasLocation?: boolean;
|
||||
/** Whether the similar-schools section will render. Optional for the same
|
||||
* reason hasLocation is: the nav must never link to an anchor that was not
|
||||
* rendered, and absent has to mean "no section". */
|
||||
hasSimilarSchools?: boolean;
|
||||
yearlyDataLength: number;
|
||||
}
|
||||
|
||||
@@ -142,7 +146,10 @@ export interface NavItemsInput {
|
||||
*/
|
||||
export function buildNavItems(
|
||||
flags: SchoolFlags,
|
||||
{ ofsted, admissions, admissionDistance, hasLocation, yearlyDataLength }: NavItemsInput,
|
||||
{
|
||||
ofsted, admissions, admissionDistance, hasLocation,
|
||||
hasSimilarSchools, yearlyDataLength,
|
||||
}: NavItemsInput,
|
||||
): NavItem[] {
|
||||
const navItems: NavItem[] = [];
|
||||
if (ofsted) navItems.push({ id: 'ofsted', label: 'Ofsted' });
|
||||
@@ -161,6 +168,8 @@ export function buildNavItems(
|
||||
if (flags.hasSchoolLife) navItems.push({ id: 'school-life', label: 'School Life' });
|
||||
if (flags.hasDeprivation) navItems.push({ id: 'local-area', label: 'Local Area' });
|
||||
if (flags.hasFinance) navItems.push({ id: 'finances', label: 'Finances' });
|
||||
// Last, because the section renders last — the scroll-spy reads this order.
|
||||
if (hasSimilarSchools) navItems.push({ id: 'similar', label: 'Similar schools' });
|
||||
return navItems;
|
||||
}
|
||||
|
||||
@@ -239,7 +248,10 @@ export function computeSecondaryFlags({
|
||||
*/
|
||||
export function buildSecondaryNavItems(
|
||||
flags: SecondaryFlags,
|
||||
{ ofsted, admissions, admissionDistance, hasLocation, yearlyDataLength }: NavItemsInput,
|
||||
{
|
||||
ofsted, admissions, admissionDistance, hasLocation,
|
||||
hasSimilarSchools, yearlyDataLength,
|
||||
}: NavItemsInput,
|
||||
): NavItem[] {
|
||||
const navItems: NavItem[] = [];
|
||||
if (ofsted) navItems.push({ id: 'ofsted', label: 'Ofsted' });
|
||||
@@ -257,5 +269,7 @@ export function buildSecondaryNavItems(
|
||||
if (yearlyDataLength > 1) navItems.push({ id: 'history', label: 'History' });
|
||||
if (flags.hasWellbeing) navItems.push({ id: 'wellbeing', label: 'Wellbeing' });
|
||||
if (flags.hasFinance) navItems.push({ id: 'finances', label: 'Finances' });
|
||||
// Last, because the section renders last — the scroll-spy reads this order.
|
||||
if (hasSimilarSchools) navItems.push({ id: 'similar', label: 'Similar schools' });
|
||||
return navItems;
|
||||
}
|
||||
Reference in new issue
Block a user