Skip to content

refactor(web): split member.tsx into hooks and components - #78

Open
naasanov wants to merge 1 commit into
mainfrom
nick/member-refactor
Open

refactor(web): split member.tsx into hooks and components#78
naasanov wants to merge 1 commit into
mainfrom
nick/member-refactor

Conversation

@naasanov

Copy link
Copy Markdown
Collaborator

Prep work for the chat transcript export (#73). Pure refactor — no behavior changes, so the transcript PR stacked on top stays reviewable.

member.tsx had reached 1235 lines holding the chat, the composer, patient controls, referrals and checklists. This splits it along the boundaries main already established with ChecklistWidget / useChecklists / CollapsibleSection: hooks own the Firestore subscriptions, components own their own UI and handlers.

New file Contents
hooks/useChat.ts message state, live listener, pagination, sender profiles, read receipts, send
hooks/usePatientProfile.ts patient doc subscription, current user profile, social worker list
components/ChatPanel.tsx chat column
components/MessageBubble.tsx one message + chunk grouping
components/ChatComposer.tsx textarea, image picker, send
components/PatientControls.tsx assignment / status / verify-deny
utils/format_datetime.ts shared message-timestamp + person-name formatters

member.tsx ends as a 156-line layout shell.

Deliberately not done here

The live-listener bug is carried across unchanged. The onSnapshot handler replaces the whole message list with only the newest page, discarding older pages loaded by loadOlderMessages. It's filed as #77 with a comment pointing at it from the new code. Fixing it inside a 1000-line move would have made this diff impossible to review — and #77 needs human confirmation of the repro first.

The ad-hoc date formatters in _index.tsx and calendar.tsx were left alone. They looked like duplicates of formatMessageDateTime but aren't: one renders date-only with a year, another a full weekday with no time, the third date+time with no year. Unifying them would have changed what renders in three places.

Verification

npm run typecheck, npm run lint, npm run build all clean.

Behavior preservation was checked mechanically as well as by hand: every one of the 129 string literals in the original member.tsx still appears somewhere in the new file set.

member.tsx had grown to 1235 lines holding the chat, the composer, patient
controls, referrals and checklists. Split it along the boundaries main already
established with ChecklistWidget/useChecklists/CollapsibleSection: hooks own the
Firestore subscriptions, components own their own UI and handlers.

  useChat.ts            message state, live listener, pagination, read receipts
  usePatientProfile.ts  patient doc subscription, current user, social workers
  ChatPanel.tsx         chat column
  MessageBubble.tsx     one message + chunk grouping
  ChatComposer.tsx      textarea, image picker, send
  PatientControls.tsx   assignment / status / verify-deny
  format_datetime.ts    shared message timestamp + person name formatters

member.tsx is now a 156-line layout shell.

Strictly behavior-preserving: no bug fixes and no cleanups. In particular the
live-listener bug that discards older paginated pages moves across unchanged,
with a comment pointing at #77 — fixing it here would have made this diff
unreviewable.

The ad-hoc date formatters in _index.tsx and calendar.tsx were left alone
rather than folded into format_datetime.ts; their output differs (year vs no
year, time vs no time), so unifying them would change what renders.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant