Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 26 additions & 13 deletions web/src/components/ApplicationTrackingModule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<TabId>('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<TabId>('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
Expand All @@ -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)
Expand Down Expand Up @@ -254,10 +267,10 @@ export default function ApplicationTrackingModule({ open, onClose, onEditIncome,

const content =
tab === 'overview' ? <OverviewTab year={year} aside={aside} listLoaded={appsLoaded} strip={<YourListStrip apps={apps} profile={effectiveProfile} origin={origin} onOpenSchool={openInStatus} onDiscover={() => switchTab('discover')} onSeeAll={() => openInStatus(ALL_SCHOOLS)} />} /> :
tab === 'application-101' ? <ModuleOverviewTab progress={progress} onToggle={handleToggle} onMarkComplete={handleMarkComplete} checklist={APPLICATIONS_CHECKLIST} contentMap={APPLICATIONS_CONTENT_MAP} allIds={APPLICATIONS_ALL_IDS} totalItems={APPLICATIONS_TOTAL_ITEMS} accent={MC} title="Application 101" subtitle={"Click an item title to read it. Click the circle to cycle status: empty → in-progress → done."} itemTypeIcon={itemTypeIcon} backLabel="Back to Application 101" /> :
tab === 'application-101' ? <ModuleOverviewTab progress={progress} onToggle={handleToggle} onMarkComplete={handleMarkComplete} checklist={APPLICATIONS_CHECKLIST} contentMap={APPLICATIONS_CONTENT_MAP} allIds={APPLICATIONS_ALL_IDS} totalItems={APPLICATIONS_TOTAL_ITEMS} accent={MC} title="Application 101" subtitle={"Click an item title to read it. Click the circle to cycle status: empty → in-progress → done."} itemTypeIcon={itemTypeIcon} backLabel="Back to Application 101" activeContentId={article} onOpenContent={setPage} /> :
tab === 'aid-compare' && FEATURES.aidCompare ? <AidCompare collegeIds={apps.map((a) => a.collegeId)} accent={MC} /> :
tab === 'discover' ? <CollegeDiscoverTab open={open} apps={apps} listLoaded={appsLoaded} onAdd={handleAddFromDiscover} onRemove={handleRemoveApp} /> :
<ApplicationStatusTab onFindColleges={() => switchTab('discover')} apps={apps} onUpdate={handleUpdateApp} onRemove={handleRemoveApp} onSetShared={handleSetSharedTask} onSetSharedDue={handleSetSharedDue} gradeStartIdx={profile?.grade_start_idx} openId={school} onOpen={setSchool} colleges={collegeRows} />
<ApplicationStatusTab onFindColleges={() => 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 (
Expand All @@ -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={<ModuleTabNav active={tab} onTab={switchTab} progress={progress} totalItems={APPLICATIONS_TOTAL_ITEMS} accent={MC} title="Applications" subtitle="Building Your List" tabs={TABS} onTour={() => setShowTour(true)} />}
tour={showTour && (
<ApplicationsModuleTour
Expand Down
33 changes: 29 additions & 4 deletions web/src/components/EssaysModule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import EssaysModuleTour, { type EssaysTabId } from './EssaysModuleTour'
import ModuleTabNav from './ModuleTabNav'
import ModuleOverviewTab from './ModuleOverviewTab'
import ModuleShell from './ModuleShell'
import { useRoutedTab } from '../lib/hashRoute'
import { routedItem, routedTab, useRoutedTab } from '../lib/hashRoute'

const DRAFTS_LOAD_FAILED_MESSAGE =
"Couldn't load your saved work — check your connection and reopen. Editing is paused so nothing already saved gets overwritten."
Expand Down Expand Up @@ -390,7 +390,29 @@ 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<TabId>('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<TabId>('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<EssayDraft>(MODULE_NAME, DRAFTS_KEY, open)
Expand All @@ -410,17 +432,20 @@ export default function EssaysModule({ open, onClose, aside, year }: Props) {

const content =
tab === 'overview'
? <ModuleOverviewTab progress={progress} onToggle={handleToggle} onMarkComplete={handleMarkComplete} checklist={ESSAYS_CHECKLIST} contentMap={ESSAYS_CONTENT_MAP} allIds={ESSAYS_ALL_IDS} totalItems={ESSAYS_TOTAL_ITEMS} accent={MC} title="Essay Strategy" subtitle="Click an item title to read it. Click the circle to cycle status." itemTypeIcon={itemTypeIcon} aside={aside} />
? <ModuleOverviewTab progress={progress} onToggle={handleToggle} onMarkComplete={handleMarkComplete} checklist={ESSAYS_CHECKLIST} contentMap={ESSAYS_CONTENT_MAP} allIds={ESSAYS_ALL_IDS} totalItems={ESSAYS_TOTAL_ITEMS} accent={MC} title="Essay Strategy" subtitle="Click an item title to read it. Click the circle to cycle status." itemTypeIcon={itemTypeIcon} activeContentId={article} onOpenContent={setPage} aside={aside} />
: <DraftsTab drafts={drafts} draftsRef={draftsRef} onSave={handleSaveDrafts} />

return (
<ModuleShell
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={<ModuleTabNav active={tab} onTab={setTab} progress={progress} totalItems={ESSAYS_TOTAL_ITEMS} accent={MC} title="Essays" subtitle="Drafting Season" tabs={TABS} onTour={() => setShowTour(true)} />}
tour={showTour && (
<EssaysModuleTour
Expand Down
13 changes: 10 additions & 3 deletions web/src/components/FinancialAidModule.test.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -78,7 +79,12 @@ describe('AidForms', () => {
describe('Scholarships 101', () => {
it('starts with the six scholarship steps and opens each one', async () => {
const onToggle = vi.fn()
render(<Scholarships101Tab progress={{ 'sr-1': 'completed' }} onToggle={onToggle} />)
// The open article belongs to the module now, so stand in for it.
const Harness = () => {
const [activeId, setActiveId] = useState<string | null>(null)
return <Scholarships101Tab progress={{ 'sr-1': 'completed' }} onToggle={onToggle} activeId={activeId} onOpenContent={setActiveId} />
}
render(<Harness />)
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')
Expand All @@ -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(<Scholarships101Tab progress={{}} onToggle={onToggle} />)
const { unmount } = render(<Scholarships101Tab progress={{}} onToggle={onToggle} activeId={null} onOpenContent={vi.fn()} />)
for (const section of ['Scholarships', 'Understanding Aid Types', 'FAFSA Preparation', 'Net Price Calculators']) {
expect(screen.getByRole('button', { name: new RegExp(`^${section}`) })).toBeInTheDocument()
}
unmount()
render(<Scholarships101Tab progress={{}} onToggle={onToggle} initialOpenId="fp-1" />)
// Opened straight onto by the module (Overview's "Start FAFSA prep").
render(<Scholarships101Tab progress={{}} onToggle={onToggle} activeId="fp-1" onOpenContent={vi.fn()} />)
expect(screen.getByText('What is FAFSA and why every student should file', { exact: false })).toBeInTheDocument()
expect(onToggle).not.toHaveBeenCalled()
})
Expand Down
Loading
Loading