From 61055e13c8d71d578ddcce9669255de4a8283a5b Mon Sep 17 00:00:00 2001 From: Danial Beg Date: Sun, 1 Nov 2026 09:47:36 -0800 Subject: [PATCH 1/2] Let the sidebar leave an article, not just the Back button MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reading a checklist article left exactly one way out. The open article was the Overview tab's own state, so nothing outside it could close it: clicking the tab you were already on changes no tab id, nothing unmounted, and the article stayed up. The sidebar looked live and did nothing. The breadcrumb was worse — it rendered its tab label as plain text while reading, because pageLabel was only ever set for a school's page. The open article now lives where a school's page already lived: in the URL, under its tab, held by the module. Picking any tab clears it, including the tab it is already on, so the sidebar works. The breadcrumb names the article and its tab label becomes a button back to the list. And the article has a URL, so a refresh keeps it and the browser's Back leaves it. Four ways out where there was one, all of them the ones a student would try first. This covers every module with a sidebar: Application Tracking and College Essays through the shared ModuleOverviewTab, whose reader is now the module's state rather than its own, and Financial Aid for both Overview and Scholarships 101. Financial Aid's two scholarship detail views had the same dead sidebar and are fixed differently. A detail there is a scored object out of a paginated in-memory list, so an id in the URL could not rebuild it after a refresh. Instead the module bumps a counter on every sidebar click and those two tabs close their detail when it changes — adjusted during render, as the module already does with `wasOpen`, since starting level with the counter also means a tab opened straight onto a scholarship is not closed on arrival. The regression guard is in hashRoute's own tests: re-picking the tab you are on must drop the open page, which is the whole mechanism. moduleReaderNav covers the wiring every module repeats — open an article, then leave it from the active tab, from another tab, and with Back. --- .../components/ApplicationTrackingModule.tsx | 27 +++--- web/src/components/EssaysModule.tsx | 12 ++- .../components/FinancialAidModule.test.tsx | 8 +- web/src/components/FinancialAidModule.tsx | 71 +++++++++++---- web/src/components/ModuleOverviewTab.tsx | 19 +++- web/src/components/moduleReaderNav.test.tsx | 86 +++++++++++++++++++ web/src/lib/hashRoute.test.ts | 12 +++ 7 files changed, 200 insertions(+), 35 deletions(-) create mode 100644 web/src/components/moduleReaderNav.test.tsx diff --git a/web/src/components/ApplicationTrackingModule.tsx b/web/src/components/ApplicationTrackingModule.tsx index 5d6ca65..3d6ef43 100644 --- a/web/src/components/ApplicationTrackingModule.tsx +++ b/web/src/components/ApplicationTrackingModule.tsx @@ -96,12 +96,17 @@ export default function ApplicationTrackingModule({ open, onClose, onEditIncome, const [showTour, setShowTour] = useState(false) // Opens on Application Status: a returning student wants to see where each // application stands. The nav keeps its teaching order (the tour walks it). - // The school whose page is open is in the URL too, under its tab, so Back - // returns to the list and a link or refresh lands on the school. - const [tab, setTab, routedSchool, setSchool] = useRoutedTab('Application Tracking', open, TAB_IDS, 'status') - // Changing tab closes the school's page (useRoutedTab does that). + // Whatever page is open inside the tab is in the URL under it, so Back + // returns to the tab and a link or refresh lands on the page. Under Status + // that is a school; under Overview it is the checklist article being read. + // Holding it here rather than inside the tab is what lets the sidebar and + // the breadcrumb leave an article — clicking the tab you are already on + // changes no tab id, so only clearing this closes the reader. + const [tab, setTab, routedPage, setPage] = useRoutedTab('Application Tracking', open, TAB_IDS, 'status') + // Changing tab closes it (useRoutedTab does that). const switchTab = setTab - const school = tab === 'status' ? routedSchool : null + const school = tab === 'status' ? routedPage : null + const article = tab === 'overview' ? routedPage : null // The module stays mounted while closed — it holds the college list and its // checklist — so without this it reopens wherever it was left. Someone who @@ -112,10 +117,10 @@ export default function ApplicationTrackingModule({ open, onClose, onEditIncome, if (open !== wasOpen) { setWasOpen(open) // A tab named in the URL (back/forward, or a refresh) wins over the default. - if (open) { setTab(routedTab('Application Tracking', TAB_IDS) ?? 'status'); setSchool(routedItem('Application Tracking', TAB_IDS)) } + if (open) { setTab(routedTab('Application Tracking', TAB_IDS) ?? 'status'); setPage(routedItem('Application Tracking', TAB_IDS)) } } // From the Overview list strip: a school's page, or the whole list. - const openInStatus = useCallback((collegeId: string | null) => { setTab('status'); setSchool(collegeId) }, [setTab, setSchool]) + const openInStatus = useCallback((collegeId: string | null) => { setTab('status'); setPage(collegeId) }, [setTab, setPage]) // Dismissal persists via mark_intro_seen, but that round-trips through a // profile refresh; track it locally so the banner goes away on the click. const [feeWaiverDismissed, setFeeWaiverDismissed] = useState(false) @@ -226,10 +231,10 @@ export default function ApplicationTrackingModule({ open, onClose, onEditIncome, && shouldShowFeeWaiverNotice(incomeLevel, profile?.settings?.intros_seen) const content = - tab === 'overview' ? switchTab('discover')} onSeeAll={() => openInStatus(ALL_SCHOOLS)} />} /> : + tab === 'overview' ? switchTab('discover')} onSeeAll={() => openInStatus(ALL_SCHOOLS)} />} /> : tab === 'aid-compare' && FEATURES.aidCompare ? a.collegeId)} accent={MC} /> : tab === 'discover' ? : - switchTab('discover')} apps={apps} onUpdate={handleUpdateApp} onRemove={handleRemoveApp} onSetShared={handleSetSharedTask} onSetSharedDue={handleSetSharedDue} gradeStartIdx={profile?.grade_start_idx} openId={school} onOpen={setSchool} colleges={collegeRows} /> + switchTab('discover')} apps={apps} onUpdate={handleUpdateApp} onRemove={handleRemoveApp} onSetShared={handleSetSharedTask} onSetSharedDue={handleSetSharedDue} gradeStartIdx={profile?.grade_start_idx} openId={school} onOpen={setPage} colleges={collegeRows} /> const openApp = school ? apps.find((a) => a.collegeId === school) : undefined return ( @@ -238,8 +243,8 @@ export default function ApplicationTrackingModule({ open, onClose, onEditIncome, onClose={onClose} breadcrumbLabel="Application Tracking" tabLabel={TABS.find((t) => t.id === tab)?.label} - pageLabel={openApp && schoolDisplay(openApp).name} - onBack={openApp && (() => setSchool(null))} + pageLabel={openApp ? schoolDisplay(openApp).name : article ? APPLICATIONS_CONTENT_MAP[article]?.title : undefined} + onBack={(openApp || article) ? (() => setPage(null)) : undefined} year={year} scrollKey={tab} nav={ setShowTour(true)} />} diff --git a/web/src/components/EssaysModule.tsx b/web/src/components/EssaysModule.tsx index 3e8bab1..43853df 100644 --- a/web/src/components/EssaysModule.tsx +++ b/web/src/components/EssaysModule.tsx @@ -390,7 +390,12 @@ export default function EssaysModule({ open, onClose, aside, year }: Props) { const { user, profile, refreshProfile } = useAuth() const tourSeen = profile?.settings?.intros_seen?.includes(TOUR_INTRO_KEY) ?? false const [showTour, setShowTour] = useState(false) - const [tab, setTab] = useRoutedTab('College Essays', open, TAB_IDS, 'overview') + // The article being read lives in the URL under its tab, so the sidebar, + // the breadcrumb and Back can all leave it. Held here rather than inside + // the Overview tab: clicking the tab you are already on changes no tab id, + // so nothing unmounts and only clearing this closes the reader. + const [tab, setTab, routedPage, setPage] = useRoutedTab('College Essays', open, TAB_IDS, 'overview') + const article = tab === 'overview' ? routedPage : null const { progress, handleToggle, handleMarkComplete } = useModuleChecklist(MODULE_NAME, open) const { data: drafts, saveData: handleSaveDrafts, dataRef: draftsRef, loadFailed: draftsLoadFailed } = useModuleData(MODULE_NAME, DRAFTS_KEY, open) @@ -410,7 +415,7 @@ export default function EssaysModule({ open, onClose, aside, year }: Props) { const content = tab === 'overview' - ? + ? : return ( @@ -418,6 +423,9 @@ export default function EssaysModule({ open, onClose, aside, year }: Props) { open={open} onClose={onClose} breadcrumbLabel="College Essays" + tabLabel={TABS.find((t) => t.id === tab)?.label} + pageLabel={article ? ESSAYS_CONTENT_MAP[article]?.title : undefined} + onBack={article ? (() => setPage(null)) : undefined} fillContent year={year} scrollKey={tab} diff --git a/web/src/components/FinancialAidModule.test.tsx b/web/src/components/FinancialAidModule.test.tsx index 142483d..bc7a577 100644 --- a/web/src/components/FinancialAidModule.test.tsx +++ b/web/src/components/FinancialAidModule.test.tsx @@ -1,3 +1,4 @@ +import { useState } from 'react' import { describe, it, expect, vi } from 'vitest' import { render, screen } from '@testing-library/react' import userEvent from '@testing-library/user-event' @@ -59,7 +60,12 @@ describe('AidForms', () => { describe('Scholarships 101', () => { it('lists the six steps in order and opens each one', async () => { const onToggle = vi.fn() - render() + // The open article belongs to the module now, so stand in for it. + const Harness = () => { + const [activeId, setActiveId] = useState(null) + return + } + render() expect(screen.getByText('1/6 completed')).toBeInTheDocument() await userEvent.click(screen.getByText('Understanding scholarships: types, eligibility, and how they work')) expect(onToggle).toHaveBeenCalledWith('sr-5') diff --git a/web/src/components/FinancialAidModule.tsx b/web/src/components/FinancialAidModule.tsx index e8b6903..199bf81 100644 --- a/web/src/components/FinancialAidModule.tsx +++ b/web/src/components/FinancialAidModule.tsx @@ -66,7 +66,7 @@ import AidGuideSections, { type AidGuideDestination, type GuideRowId } from './A import { stateFromZip } from '../data/aidPrograms' import { Bar, CollegeLogo, SecLabel, Tag } from './moduleUI' import { logoUrlForDomain } from '../lib/collegeLogo' -import { formatRoute, routedTab, useRoutedTab } from '../lib/hashRoute' +import { formatRoute, routedItem, routedTab, useRoutedTab } from '../lib/hashRoute' import { MODULE_ICONS } from './moduleIcons' import ModuleTabNav from './ModuleTabNav' import { ModuleHeaderEnd, TEXT_FIELD } from './ModuleShell' @@ -285,8 +285,16 @@ const FA_TAB_IDS = FA_TABS.map((t) => t.id) ═══════════════════════════════════════════════════════════════ */ /** The item open for reading, and the status moves that come with it: * opening one starts it, and its button walks it to complete and back. */ -function useChecklistReader(progress: ChecklistProgressMap, onToggle: (itemId: string) => void) { - const [activeId, setActiveId] = useState(null) +// `activeId` is the module's, not this hook's. Held inside a tab, nothing +// outside could close it: clicking the tab you were already on changes no tab +// id, so nothing unmounted and the article stayed up with the sidebar and the +// breadcrumb both looking live and doing nothing. +function useChecklistReader( + progress: ChecklistProgressMap, + onToggle: (itemId: string) => void, + activeId: string | null, + setActiveId: (itemId: string | null) => void, +) { const statusOf = (id: string): ChecklistItemStatus => progress[id] ?? 'available' const open = (itemId: string) => { if (statusOf(itemId) === 'available') onToggle(itemId) @@ -325,8 +333,8 @@ const ChecklistProgress = ({ done, total, tour }: { done: number; total: number; /* ═══════════════════════════════════════════════════════════════ TAB: SCHOLARSHIPS 101 ═══════════════════════════════════════════════════════════════ */ -export const Scholarships101Tab = ({ progress, onToggle }: { progress: ChecklistProgressMap; onToggle: (itemId: string) => void }) => { - const reader = useChecklistReader(progress, onToggle) +export const Scholarships101Tab = ({ progress, onToggle, activeId, onOpenContent }: { progress: ChecklistProgressMap; onToggle: (itemId: string) => void; activeId: string | null; onOpenContent: (itemId: string | null) => void }) => { + const reader = useChecklistReader(progress, onToggle, activeId, onOpenContent) if (reader.activeId) { return ( void } -const OverviewTab = ({ progress, onToggle, aside, homeState, aid, onGoToTab, year, gradeStartIdx }: OverviewTabProps) => { - const { activeId: activeContentId, setActiveId: setActiveContentId, statusOf, open: openContent, markComplete: handleMarkComplete } = useChecklistReader(progress, onToggle) +const OverviewTab = ({ progress, onToggle, aside, homeState, aid, onGoToTab, year, gradeStartIdx, activeId, onOpenContent }: OverviewTabProps) => { + const { activeId: activeContentId, setActiveId: setActiveContentId, statusOf, open: openContent, markComplete: handleMarkComplete } = useChecklistReader(progress, onToggle, activeId, onOpenContent) // Lives here, not in the guide, so it survives opening an article and coming back. const [guideRow, setGuideRow] = useState(null) const [expanded, setExpanded] = useState>({ 0: true, 1: true, 2: true }) @@ -803,7 +814,8 @@ const TaskBox = ({ done }: { done: boolean }) => ( ) -const ScholarshipsTab = ({ api, aid, gradeStartIdx, initialOpenId, onFindScholarships }: { +const ScholarshipsTab = ({ api, aid, gradeStartIdx, initialOpenId, onFindScholarships, navSignal }: { + navSignal: number api: TrackerApi /** The student's schools, for the FAFSA and CSS Profile boxes on top. */ aid: AidCollegesState @@ -814,6 +826,12 @@ const ScholarshipsTab = ({ api, aid, gradeStartIdx, initialOpenId, onFindScholar onFindScholarships: () => void }) => { const [openId, setOpenId] = useState(initialOpenId) + // A sidebar click leaves the scholarship's page, even a click on the tab it + // is already on. Adjusted during render rather than in an effect, as the + // module does with `wasOpen`: starting level with navSignal also means the + // page this tab was opened straight onto is not closed on arrival. + const [seenNav, setSeenNav] = useState(navSignal) + if (navSignal !== seenNav) { setSeenNav(navSignal); setOpenId(null) } const [sort, setSort] = useState('deadline') const [filter, setFilter] = useState(null) const [adding, setAdding] = useState(false) @@ -1699,6 +1717,8 @@ function TrackedStrip({ api, onOpen }: { api: TrackerApi; onOpen: (id: string | } interface AidEngineTabProps { + /** Bumped on every sidebar click, so the detail view can close. */ + navSignal: number api: TrackerApi userDemoTags: string[] userDemographics: Demographics | null @@ -1714,7 +1734,7 @@ interface AidEngineTabProps { const PAGE = 40 -const AidEngineTab = ({ api, userDemoTags, userDemographics, prefs, prefsLoaded, onSavePrefs, dismissals, onOpenTracked, year }: AidEngineTabProps) => { +const AidEngineTab = ({ api, userDemoTags, userDemographics, prefs, prefsLoaded, onSavePrefs, dismissals, onOpenTracked, year, navSignal }: AidEngineTabProps) => { const [editing, setEditing] = useState(false) const [results, setResults] = useState([]) const [loading, setLoading] = useState(true) @@ -1726,6 +1746,9 @@ const AidEngineTab = ({ api, userDemoTags, userDemographics, prefs, prefsLoaded, const [showHidden, setShowHidden] = useState(false) const [visibleCount, setVisibleCount] = useState(PAGE) const [detail, setDetail] = useState(null) + // A sidebar click leaves the detail view, even a click on this very tab. + const [seenNav, setSeenNav] = useState(navSignal) + if (navSignal !== seenNav) { setSeenNav(navSignal); setDetail(null) } // Picks tracked on this visit stay where they are, showing "Tracked": // dropping one closed up the row and slid the next pick's Track button // under the pointer. @@ -2106,11 +2129,19 @@ export default function FinancialAidModule({ open, onClose, year = 11, aside }: const isNarrow = useIsNarrow() // Opens on Aid Tracker, as Application Tracking opens on Application // Status: a returning student wants to see where each one stands. - const [tab, setTab] = useRoutedTab('Financial Aid', open, FA_TAB_IDS, 'scholarships') + // The article being read lives in the URL under its tab, so the sidebar, + // the breadcrumb and Back can all leave it. + const [tab, setTab, routedPage, setPage] = useRoutedTab('Financial Aid', open, FA_TAB_IDS, 'scholarships') + const article = tab === 'overview' || tab === 'scholarships-101' ? routedPage : null // A tracked scholarship to open straight onto when switching to My // Scholarships (from the Scholarship Engine's strip). Any other tab change clears it. const [openScholarship, setOpenScholarship] = useState(null) - const switchTab = useCallback((t: TabId) => { setOpenScholarship(null); setTab(t) }, [setTab]) + // Bumped on every sidebar click, including one on the tab already active. + // A scholarship detail is a scored object out of a paginated in-memory list, + // not something an id in the URL could rebuild after a refresh, so those two + // tabs close their detail on this instead of routing it like the articles. + const [navSignal, setNavSignal] = useState(0) + const switchTab = useCallback((t: TabId) => { setNavSignal((n) => n + 1); setOpenScholarship(null); setTab(t) }, [setTab]) // Reopens on Aid Tracker rather than wherever it was left. The module // stays mounted while closed, so the tab would otherwise survive from a // visit the student no longer remembers. Adjusted on the open transition, @@ -2118,7 +2149,7 @@ export default function FinancialAidModule({ open, onClose, year = 11, aside }: const [wasOpen, setWasOpen] = useState(open) if (open !== wasOpen) { setWasOpen(open) - if (open) { setTab(routedTab('Financial Aid', FA_TAB_IDS) ?? 'scholarships'); setOpenScholarship(null) } // a tab in the URL wins + if (open) { setTab(routedTab('Financial Aid', FA_TAB_IDS) ?? 'scholarships'); setPage(routedItem('Financial Aid', FA_TAB_IDS)); setOpenScholarship(null) } // a tab in the URL wins } const [progress, setProgress] = useState({}) const [progressError, setProgressError] = useState(null) @@ -2357,10 +2388,10 @@ export default function FinancialAidModule({ open, onClose, year = 11, aside }: if (!open) return null const content = - tab === 'overview' ? : - tab === 'scholarships-101' ? : - tab === 'scholarships' ? switchTab('scholarship-search')} /> : - void saveAidPrefsOrSay(p)} dismissals={dismissals} onOpenTracked={openTracked} year={year} /> + tab === 'overview' ? : + tab === 'scholarships-101' ? : + tab === 'scholarships' ? switchTab('scholarship-search')} /> : + void saveAidPrefsOrSay(p)} dismissals={dismissals} onOpenTracked={openTracked} year={year} /> return (
@@ -2380,7 +2411,13 @@ export default function FinancialAidModule({ open, onClose, year = 11, aside }: {/* On a phone the tab strip right below already says which tab. */} {!isNarrow && <> · - {FA_TABS.find((t) => t.id === tab)?.label} + {article + ? + : {FA_TABS.find((t) => t.id === tab)?.label}} + {article && <> + / + {CHECKLIST_CONTENT_MAP[article]?.title} + } }
diff --git a/web/src/components/ModuleOverviewTab.tsx b/web/src/components/ModuleOverviewTab.tsx index 91c44f4..0c6dbc2 100644 --- a/web/src/components/ModuleOverviewTab.tsx +++ b/web/src/components/ModuleOverviewTab.tsx @@ -5,6 +5,12 @@ * of checklist items (each a status Ring + type icon + label). Clicking an * item opens its ChecklistContentView reader. Modules supply their own * checklist data, content map, accent, and copy. + * + * The reader's open item is the MODULE's state, not this component's. It used + * to live here, which meant nothing outside could close it: clicking the tab + * you were already on left the article up, because the tab id never changed + * and nothing unmounted. The sidebar and the breadcrumb both looked live and + * did nothing, leaving the in-page Back as the only way out. */ import { useState, type ReactNode } from 'react' @@ -42,6 +48,10 @@ interface Props { * student's college list and map here, so the module's front page opens on * what they have before it teaches what to do next. */ before?: ReactNode + /** The checklist item being read, or null for the list. Owned by the module + * so the sidebar, the breadcrumb and the browser's Back can all leave it. */ + activeContentId: string | null + onOpenContent: (itemId: string | null) => void } export default function ModuleOverviewTab({ @@ -58,10 +68,11 @@ export default function ModuleOverviewTab({ before, itemTypeIcon, aside, + activeContentId, + onOpenContent, }: Props) { const [expanded, setExpanded] = useState>(() => Object.fromEntries(checklist.map((_, i) => [i, true]))) - const [activeContentId, setActiveContentId] = useState(null) const statusOf = (id: string): ChecklistItemStatus => progress[id] ?? 'available' const done = checklist.reduce( (a, s) => a + s.items.filter((x) => statusOf(x.id) === 'completed').length, @@ -76,9 +87,9 @@ export default function ModuleOverviewTab({ contentMap={contentMap} allIds={allIds} accentColor={accent} - onBack={() => setActiveContentId(null)} + onBack={() => onOpenContent(null)} onMarkComplete={onMarkComplete} - onNavigate={setActiveContentId} + onNavigate={onOpenContent} /> ) } @@ -136,7 +147,7 @@ export default function ModuleOverviewTab({