From 3b908ac453df885f5dc7decd134bb603fcb0444e Mon Sep 17 00:00:00 2001 From: Thomas Hallock Date: Sat, 8 Nov 2025 14:51:55 -0600 Subject: [PATCH] fix(worksheets): add borrowNotation and borrowingHints to DisplayRules interfaces MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add missing subtraction-specific scaffold fields to DisplayRules and ResolvedDisplayOptions interfaces, and include them in resolveDisplayForProblem. This fixes TypeScript errors and ensures these fields are properly resolved for each problem in smart difficulty mode. Part of subtraction scaffolding integration that was lost during git stash. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../worksheets/addition/displayRules.ts | 88 ++++++++++--------- 1 file changed, 48 insertions(+), 40 deletions(-) diff --git a/apps/web/src/app/create/worksheets/addition/displayRules.ts b/apps/web/src/app/create/worksheets/addition/displayRules.ts index 5f58e334..4cce28b6 100644 --- a/apps/web/src/app/create/worksheets/addition/displayRules.ts +++ b/apps/web/src/app/create/worksheets/addition/displayRules.ts @@ -1,32 +1,36 @@ // Display rules for conditional per-problem scaffolding -import type { ProblemMeta, SubtractionProblemMeta } from './problemAnalysis' +import type { ProblemMeta, SubtractionProblemMeta } from "./problemAnalysis"; -export type AnyProblemMeta = ProblemMeta | SubtractionProblemMeta +export type AnyProblemMeta = ProblemMeta | SubtractionProblemMeta; export type RuleMode = - | 'always' // Always show this display option - | 'never' // Never show this display option - | 'whenRegrouping' // Show when problem requires any regrouping - | 'whenMultipleRegroups' // Show when 2+ place values regroup - | 'when3PlusDigits' // Show when maxDigits >= 3 + | "always" // Always show this display option + | "never" // Never show this display option + | "whenRegrouping" // Show when problem requires any regrouping + | "whenMultipleRegroups" // Show when 2+ place values regroup + | "when3PlusDigits"; // Show when maxDigits >= 3 export interface DisplayRules { - carryBoxes: RuleMode - answerBoxes: RuleMode - placeValueColors: RuleMode - tenFrames: RuleMode - problemNumbers: RuleMode - cellBorders: RuleMode + carryBoxes: RuleMode; + answerBoxes: RuleMode; + placeValueColors: RuleMode; + tenFrames: RuleMode; + problemNumbers: RuleMode; + cellBorders: RuleMode; + borrowNotation: RuleMode; // Subtraction: scratch boxes showing borrowed 10s + borrowingHints: RuleMode; // Subtraction: arrows and visual hints } export interface ResolvedDisplayOptions { - showCarryBoxes: boolean - showAnswerBoxes: boolean - showPlaceValueColors: boolean - showTenFrames: boolean - showProblemNumbers: boolean - showCellBorder: boolean + showCarryBoxes: boolean; + showAnswerBoxes: boolean; + showPlaceValueColors: boolean; + showTenFrames: boolean; + showProblemNumbers: boolean; + showCellBorder: boolean; + showBorrowNotation: boolean; // Subtraction: scratch work boxes in minuend + showBorrowingHints: boolean; // Subtraction: hints with arrows } /** @@ -35,24 +39,26 @@ export interface ResolvedDisplayOptions { */ export function evaluateRule(mode: RuleMode, problem: AnyProblemMeta): boolean { switch (mode) { - case 'always': - return true + case "always": + return true; - case 'never': - return false + case "never": + return false; - case 'whenRegrouping': + case "whenRegrouping": // Works for both: requiresRegrouping (addition) or requiresBorrowing (subtraction) - return 'requiresRegrouping' in problem + return "requiresRegrouping" in problem ? problem.requiresRegrouping - : problem.requiresBorrowing + : problem.requiresBorrowing; - case 'whenMultipleRegroups': + case "whenMultipleRegroups": // Works for both: regroupCount (addition) or borrowCount (subtraction) - return 'regroupCount' in problem ? problem.regroupCount >= 2 : problem.borrowCount >= 2 + return "regroupCount" in problem + ? problem.regroupCount >= 2 + : problem.borrowCount >= 2; - case 'when3PlusDigits': - return problem.maxDigits >= 3 + case "when3PlusDigits": + return problem.maxDigits >= 3; } } @@ -62,10 +68,10 @@ export function evaluateRule(mode: RuleMode, problem: AnyProblemMeta): boolean { */ export function resolveDisplayForProblem( rules: DisplayRules, - problem: AnyProblemMeta + problem: AnyProblemMeta, ): ResolvedDisplayOptions { - console.log('[resolveDisplayForProblem] Input rules:', rules) - console.log('[resolveDisplayForProblem] Problem meta:', problem) + console.log("[resolveDisplayForProblem] Input rules:", rules); + console.log("[resolveDisplayForProblem] Problem meta:", problem); const resolved = { showCarryBoxes: evaluateRule(rules.carryBoxes, problem), @@ -74,15 +80,17 @@ export function resolveDisplayForProblem( showTenFrames: evaluateRule(rules.tenFrames, problem), showProblemNumbers: evaluateRule(rules.problemNumbers, problem), showCellBorder: evaluateRule(rules.cellBorders, problem), - } + showBorrowNotation: evaluateRule(rules.borrowNotation, problem), + showBorrowingHints: evaluateRule(rules.borrowingHints, problem), + }; - console.log('[resolveDisplayForProblem] Resolved display options:', resolved) + console.log("[resolveDisplayForProblem] Resolved display options:", resolved); console.log( - '[resolveDisplayForProblem] Ten-frames rule:', + "[resolveDisplayForProblem] Ten-frames rule:", rules.tenFrames, - '-> showTenFrames:', - resolved.showTenFrames - ) + "-> showTenFrames:", + resolved.showTenFrames, + ); - return resolved + return resolved; }