docs: cut the comments that were not earning their place
I wrote 731 comment lines on this branch against 4,530 lines of code — 14%, where the rest of the repo runs at 1.8%. CLAUDE.md asks for code that reads like its surroundings, and this did not. Removed by genre rather than by taste: - restating the code, e.g. "JS getUTCDay() numbering: Sunday = 0" above the map that literally shows it, and a docblock on startOfWeek explaining that it returns the start of the week; - narrating history — "this used to rebuild the whole map", "left the bar recording forever" — which the commit message and git blame already carry; - saying the same thing in several places: the "cannot record is not a denied microphone" reason appeared three times in one file, and the "aborting stops a per-minute metered call" reason across three files. Each now lives once, where the behaviour it explains lives; - defending decisions nobody would question, like why toLatinDigits is its own module; - over-explaining defensive branches, three separate comments to distinguish null from missing-kind from unrecognised-kind. What stays is what the code cannot say: the patient-right convention in toFdi, whose failure mode is a valid code for the wrong tooth; the "this"-vs-"next" week anchoring; StrictMode re-arming mountedRef; Safari accepting no mimeType hint; and the invariants whose violation already cost a bug — the body parser's middleware ordering and the dispatch panel's auto-fill rules. Comments only. The diff contains no non-comment line. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -338,17 +338,12 @@ function NotesField({
|
||||
/**
|
||||
* "Add detail", split into two segments with the microphone at the logical end.
|
||||
*
|
||||
* Built like the detail chip's trash affordance in this same file — an
|
||||
* `inline-flex items-stretch overflow-hidden rounded` wrapper holding two raw `<button>`s
|
||||
* divided by `border-s` — rather than two shared `Button`s, which each hardcode their own
|
||||
* rounding and would fight a segmented control.
|
||||
* Built like the detail chip's trash affordance in this same file — a wrapper holding two
|
||||
* raw `<button>`s divided by `border-s` — rather than two shared `Button`s, which hardcode
|
||||
* their own rounding and would fight a segmented control. `border-s` puts the microphone
|
||||
* visually right in en/nl and left in fa, on the same side as the chip's trash in both.
|
||||
*
|
||||
* `border-s` puts the microphone at the *logical* end: visually right in en/nl, visually
|
||||
* left in fa, on the same side as the chip's trash in both directions.
|
||||
*
|
||||
* The two halves share a wrapper and nothing else. Add keeps its exact existing
|
||||
* behaviour; the microphone is an independent action that creates nothing until the
|
||||
* clinician confirms.
|
||||
* Add keeps its exact existing behaviour; the microphone is an independent action.
|
||||
*/
|
||||
function AddDetailWithVoice({
|
||||
addLabel,
|
||||
|
||||
@@ -2000,8 +2000,7 @@ export function TreatmentWorkspace({
|
||||
|
||||
const nextDetails = [...detailsRef.current, detail];
|
||||
setDetails(nextDetails);
|
||||
// persistDraft reads detailsRef, and setDetails has not rendered yet. The codebase
|
||||
// already writes this ref imperatively after a save for the same reason.
|
||||
// persistDraft reads detailsRef, and setDetails has not rendered yet.
|
||||
detailsRef.current = nextDetails;
|
||||
setActiveDetailId(detail.clientId);
|
||||
setEntryStep('treatment');
|
||||
@@ -2045,19 +2044,16 @@ export function TreatmentWorkspace({
|
||||
const updatedLabCases = [...labCaseDrafts, draft];
|
||||
setLabCaseDrafts(updatedLabCases);
|
||||
|
||||
// Every other path that creates a lab draft persists it immediately, and the
|
||||
// autosave effect only watches `details`. Left in state alone, the destination
|
||||
// lab, the due date and the whole prosthesis map vanish on the next reload —
|
||||
// silently, because the detail itself does survive.
|
||||
// Autosave only watches `details`, so a lab draft left in state alone loses the
|
||||
// lab, the due date and the prosthesis map on reload — silently, because the
|
||||
// detail itself survives.
|
||||
void (async () => {
|
||||
try {
|
||||
const saved = await persistDraft({ force: true });
|
||||
// persistDraft returns a *preview* treatment rather than saving when the
|
||||
// details are not persistable — one blank detail, the kind the workspace opens
|
||||
// with, is enough. A preview's detail id falls back to the client id, so
|
||||
// posting lab cases against it would send the server an id it has never seen
|
||||
// and fail the whole save. Check what came back, not the precondition, so this
|
||||
// holds for every early return persistDraft has.
|
||||
// persistDraft returns a *preview* when the details are not persistable — one
|
||||
// blank detail is enough — and a preview's detail id falls back to the client
|
||||
// id. Check what came back, not the precondition, so this holds for every early
|
||||
// return persistDraft has.
|
||||
const savedDetail = saved.details.find((d) => d.clientId === detail.clientId);
|
||||
if (!savedDetail?.id || savedDetail.id === detail.clientId) return;
|
||||
await persistLabCases(saved, updatedLabCases);
|
||||
|
||||
@@ -16,9 +16,9 @@ function formatElapsed(ms: number): string {
|
||||
/**
|
||||
* Live recording / processing strip.
|
||||
*
|
||||
* Sits between the header row and the chip strip rather than inside the segmented
|
||||
* control: the header is `sm:justify-between`, so growing the button mid-recording would
|
||||
* shove the row on every start and every stop.
|
||||
* Sits between the header row and the chip strip rather than inside the segmented control:
|
||||
* the header is `sm:justify-between`, so growing the button mid-recording would shift the
|
||||
* whole row.
|
||||
*/
|
||||
export function VoiceRecordingBar({ voice }: { voice: VoiceCaptureState }) {
|
||||
const t = useTranslations('treatment');
|
||||
|
||||
@@ -38,9 +38,8 @@ interface VoiceReviewSheetProps {
|
||||
/**
|
||||
* Confirmation step between the model's output and the form.
|
||||
*
|
||||
* Modal on desktop, bottom sheet on mobile via ResponsiveDialog — deliberately an overlay
|
||||
* and not a route, because navigating would unmount TreatmentWorkspace and destroy the
|
||||
* in-progress draft.
|
||||
* Modal on desktop, bottom sheet on mobile — an overlay and not a route, because navigating
|
||||
* would unmount TreatmentWorkspace and destroy the in-progress draft.
|
||||
*/
|
||||
export function VoiceReviewSheet({
|
||||
result,
|
||||
@@ -78,10 +77,9 @@ export function VoiceReviewSheet({
|
||||
// The teeth row starts unticked whenever the recording produced no teeth of its own,
|
||||
// and a picked tooth that is not ticked applies nothing.
|
||||
teeth: true,
|
||||
// The picked tooth has no prosthesis type, which makes the map unshippable. Leaving
|
||||
// the row ticked would apply a map that `assertCompleteToothProsthesisMap` rejects
|
||||
// at dispatch — the exact failure the never-auto-tick-incomplete rule exists to
|
||||
// prevent. Only ever unticks: re-ticking is the clinician's call.
|
||||
// A picked tooth has no prosthesis type, so the map is no longer shippable — leaving the
|
||||
// row ticked would apply a map dispatch rejects. Only ever unticks; re-ticking is the
|
||||
// clinician's call.
|
||||
prosthesis:
|
||||
prev.prosthesis &&
|
||||
withChosenTeeth(result, nextChosen).prosthesis?.complete !== false,
|
||||
@@ -290,9 +288,8 @@ function Row({
|
||||
}
|
||||
|
||||
/**
|
||||
* A bare `YYYY-MM-DD` is a *civil* date, but `new Date('2025-10-17')` parses it as UTC
|
||||
* midnight — which renders as the 16th for any viewer west of Greenwich. Build the date
|
||||
* from its parts so it means the same day everywhere.
|
||||
* `new Date('2025-10-17')` parses a civil date as UTC midnight, which renders as the 16th
|
||||
* west of Greenwich. Build it from its parts so it means the same day everywhere.
|
||||
*/
|
||||
function civilDateToLocalDate(iso: string): Date {
|
||||
const [year, month, day] = iso.split('-').map(Number);
|
||||
|
||||
Reference in New Issue
Block a user