diff --git a/web/src/components/ApplicationTrackingModule.tsx b/web/src/components/ApplicationTrackingModule.tsx index 1aa61ba..f52c21b 100644 --- a/web/src/components/ApplicationTrackingModule.tsx +++ b/web/src/components/ApplicationTrackingModule.tsx @@ -122,13 +122,22 @@ export default function ApplicationTrackingModule({ open, onClose, onEditIncome, const { user, profile, refreshProfile } = useAuth() const tourSeen = profile?.settings?.intros_seen?.includes(TOUR_INTRO_KEY) ?? false const [showTour, setShowTour] = useState(false) - // Opens on Overview, as Financial Aid does. 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, 'overview') - // Changing tab closes the school's page (useRoutedTab does that). + // Opens on Overview, as Financial Aid does. 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 + // Application 101 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, 'overview') + // Changing tab closes it (useRoutedTab does that). const switchTab = setTab - const school = tab === 'status' ? routedSchool : null + const school = tab === 'status' ? routedPage : null + // Only an id this tab owns. The slot is shared with Status's school ids and + // a stale or hand-edited URL can put anything in it, which would otherwise + // render a school id in the article reader with no prev/next and leave the + // breadcrumb back-link unrendered, since it is gated on a resolved title. + const article = tab === 'application-101' && routedPage && APPLICATIONS_ALL_IDS.includes(routedPage) ? 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 @@ -139,10 +148,14 @@ 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) ?? 'overview'); setSchool(routedItem('Application Tracking', TAB_IDS)) } + if (open) { setTab(routedTab('Application Tracking', TAB_IDS) ?? 'overview'); setPage(routedItem('Application Tracking', TAB_IDS)) } } + // The open page is part of the scroll key: the sidebar and breadcrumb now + // leave a reader from any scroll depth, so the list behind it has to start + // at the top rather than at the article's offset. + const scrollKey = `${tab}/${routedPage ?? ''}` // 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) @@ -254,10 +267,10 @@ export default function ApplicationTrackingModule({ open, onClose, onEditIncome, const content = tab === 'overview' ? switchTab('discover')} onSeeAll={() => openInStatus(ALL_SCHOOLS)} />} /> : - tab === 'application-101' ? : + tab === 'application-101' ? : 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 ( @@ -266,10 +279,10 @@ 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} + scrollKey={scrollKey} nav={ setShowTour(true)} />} tour={showTour && ( ('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') + // The module stays mounted while closed, so without this it reopens on + // whatever was last open — and now that the article is module state rather + // than the tab's, that means reopening inside the article the student left. + // Adjusted on the open transition, not in an effect, so the first paint is + // already right. A tab or article named in the URL wins over the default. + const [wasOpen, setWasOpen] = useState(open) + if (open !== wasOpen) { + setWasOpen(open) + if (open) { setTab(routedTab('College Essays', TAB_IDS) ?? 'overview'); setPage(routedItem('College Essays', TAB_IDS)) } + } + // Only an id this tab actually owns: the slot is shared with other tabs and + // a hand-edited or stale URL can put anything in it, which would otherwise + // render the wrong article with no prev/next and a dead breadcrumb. + const article = tab === 'overview' && routedPage && ESSAYS_ALL_IDS.includes(routedPage) ? routedPage : null + // The open page is part of the scroll key: the sidebar and breadcrumb now + // leave a reader from any scroll depth, so the list behind it has to start + // at the top rather than at the article's offset. + const scrollKey = `${tab}/${routedPage ?? ''}` 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 +432,7 @@ export default function EssaysModule({ open, onClose, aside, year }: Props) { const content = tab === 'overview' - ? + ? : return ( @@ -418,9 +440,12 @@ 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} + scrollKey={scrollKey} nav={ setShowTour(true)} />} tour={showTour && ( { describe('Scholarships 101', () => { it('starts with the six scholarship steps 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/18 completed')).toBeInTheDocument() await userEvent.click(screen.getByText('Understanding scholarships: types, eligibility, and how they work')) expect(onToggle).toHaveBeenCalledWith('sr-5') @@ -94,12 +100,13 @@ describe('Scholarships 101', () => { it('holds the rest of the checklist, and opens an article to read without starting it', () => { const onToggle = vi.fn() - const { unmount } = render() + const { unmount } = render() for (const section of ['Scholarships', 'Understanding Aid Types', 'FAFSA Preparation', 'Net Price Calculators']) { expect(screen.getByRole('button', { name: new RegExp(`^${section}`) })).toBeInTheDocument() } unmount() - render() + // Opened straight onto by the module (Overview's "Start FAFSA prep"). + render() expect(screen.getByText('What is FAFSA and why every student should file', { exact: false })).toBeInTheDocument() expect(onToggle).not.toHaveBeenCalled() }) diff --git a/web/src/components/FinancialAidModule.tsx b/web/src/components/FinancialAidModule.tsx index 695d3c6..4046d00 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' @@ -286,8 +286,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, initialId: string | null = null) { - const [activeId, setActiveId] = useState(initialId) +// `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) @@ -326,13 +334,14 @@ const ChecklistProgress = ({ done, total, tour }: { done: number; total: number; /* ═══════════════════════════════════════════════════════════════ TAB: SCHOLARSHIPS 101 ═══════════════════════════════════════════════════════════════ */ -export const Scholarships101Tab = ({ progress, onToggle, initialOpenId = null }: { +export const Scholarships101Tab = ({ progress, onToggle, activeId, onOpenContent }: { progress: ChecklistProgressMap onToggle: (itemId: string) => void - /** Open straight onto this item (Overview's "Start FAFSA prep"), to read: not marked started. */ - initialOpenId?: string | null + /** The article being read, owned by the module so the sidebar can leave it. */ + activeId: string | null + onOpenContent: (itemId: string | null) => void }) => { - const reader = useChecklistReader(progress, onToggle, initialOpenId) + const reader = useChecklistReader(progress, onToggle, activeId, onOpenContent) const [expanded, setExpanded] = useState>({}) if (reader.activeId) { return ( @@ -776,7 +785,8 @@ const TaskBox = ({ done }: { done: boolean }) => ( ) -const ScholarshipsTab = ({ api, aid, ownDates, gradeStartIdx, initialOpenId, onFindScholarships }: { +const ScholarshipsTab = ({ api, aid, ownDates, gradeStartIdx, initialOpenId, onFindScholarships, navSignal }: { + navSignal: number api: TrackerApi /** The student's schools, for the FAFSA and CSS Profile boxes on top. */ aid: AidCollegesState @@ -788,6 +798,12 @@ const ScholarshipsTab = ({ api, aid, ownDates, gradeStartIdx, initialOpenId, onF 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) @@ -1673,6 +1689,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 @@ -1688,7 +1706,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) @@ -1700,6 +1718,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. @@ -2122,13 +2143,24 @@ export default function FinancialAidModule({ open, onClose, year = 11, aside }: }, [open, tourSeen]) const isNarrow = useIsNarrow() - // Opens on Overview, as Application Tracking does. - const [tab, setTab] = useRoutedTab('Financial Aid', open, FA_TAB_IDS, 'overview') - // What to open straight onto when switching tab: a tracked scholarship in - // Aid Tracker (from the Scholarship Engine's strip), or an article in - // Scholarships 101 (from Overview). Any other tab change clears it. + // Opens on Overview, as Application Tracking does. 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, 'overview') + // Only an id the rendering tab owns: routedItem validates the tab but not + // the item, so a stale or hand-edited URL could otherwise put an Overview + // id in Scholarships 101's reader, where indexOf is -1, the header reads + // "0 of 6" and both prev and next vanish. Articles all live here since #89. + const article = tab === 'scholarships-101' && routedPage && CHECKLIST_ALL_IDS.includes(routedPage) ? routedPage : null + // A tracked scholarship to open straight onto when switching to Aid Tracker + // (from the Scholarship Engine's strip). Any other tab change clears it. const [openItem, setOpenItem] = useState(null) - const switchTab = useCallback((t: TabId) => { setOpenItem(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); setOpenItem(null); setTab(t) }, [setTab]) // Reopens on Overview 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, @@ -2136,7 +2168,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) ?? 'overview'); setOpenItem(null) } // a tab in the URL wins + if (open) { setTab(routedTab('Financial Aid', FA_TAB_IDS) ?? 'overview'); setPage(routedItem('Financial Aid', FA_TAB_IDS)); setOpenItem(null) } // a tab in the URL wins } const [progress, setProgress] = useState({}) const [progressError, setProgressError] = useState(null) @@ -2386,7 +2418,8 @@ export default function FinancialAidModule({ open, onClose, year = 11, aside }: }, } const openTracked = (id: string | null) => { setTab('scholarships'); setOpenItem(id) } - const read101 = (id: string) => { setTab('scholarships-101'); setOpenItem(id) } + // Routed, so the article it opens has the same exits as any other. + const read101 = (id: string) => { setTab('scholarships-101'); setPage(id) } const saveAidPrefsOrSay = async (p: AidPrefs) => { if (!(await saveAidPrefs(p))) toast.error('Could not save your preferences — try again') } @@ -2395,9 +2428,9 @@ export default function FinancialAidModule({ open, onClose, year = 11, aside }: const content = tab === 'overview' ? : - tab === 'scholarships-101' ? : - tab === 'scholarships' ? switchTab('scholarship-search')} /> : - void saveAidPrefsOrSay(p)} dismissals={dismissals} onOpenTracked={openTracked} year={year} /> + tab === 'scholarships-101' ? : + tab === 'scholarships' ? switchTab('scholarship-search')} /> : + void saveAidPrefsOrSay(p)} dismissals={dismissals} onOpenTracked={openTracked} year={year} /> return (
@@ -2417,7 +2450,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} + } }
@@ -2461,14 +2500,14 @@ export default function FinancialAidModule({ open, onClose, year = 11, aside }: {/* Full-width content */}
-
{content}
+
{content}
) : (
setShowTour(true)} />
-
{content}
+
{content}
)} diff --git a/web/src/components/ModuleOverviewTab.tsx b/web/src/components/ModuleOverviewTab.tsx index 22fa9b0..284d05d 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' @@ -38,6 +44,14 @@ interface Props { * passed down, so every panel shares the one set of handlers rather than * each module loading its own copy of the student's dates. */ aside?: ReactNode + /** Rendered above the title, inside the main column. Applications puts the + * 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 /** Back's label in the article reader, when this isn't the Overview tab. */ backLabel?: string } @@ -55,11 +69,12 @@ export default function ModuleOverviewTab({ subtitle, itemTypeIcon, aside, + activeContentId, + onOpenContent, backLabel, }: 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, @@ -75,9 +90,9 @@ export default function ModuleOverviewTab({ allIds={allIds} accentColor={accent} backLabel={backLabel} - onBack={() => setActiveContentId(null)} + onBack={() => onOpenContent(null)} onMarkComplete={onMarkComplete} - onNavigate={setActiveContentId} + onNavigate={onOpenContent} /> ) } @@ -134,7 +149,7 @@ export default function ModuleOverviewTab({