Skip to content

修正函數式思考題庫程式碼片段未用 code block 顯示的問題#19

Merged
Retsomm merged 3 commits into
mainfrom
dev
Jul 18, 2026
Merged

修正函數式思考題庫程式碼片段未用 code block 顯示的問題#19
Retsomm merged 3 commits into
mainfrom
dev

Conversation

@Retsomm

@Retsomm Retsomm commented Jul 18, 2026

Copy link
Copy Markdown
Owner

部分 fp-* 題目把程式碼直接寫進 prompt/選項文字,只能當純文字擠成一行;
改為統一搬進既有的 code 欄位(QuestionOption 新增選填 code 欄位),
交給 CodeBlock 元件做語法上色渲染。

Summary by CodeRabbit

  • New Features
    • Answer options can now display associated code examples in mobile and web question views.
    • Code examples support readable, non-scrolling layouts within answer options.
  • Content Updates
    • Improved question formatting by separating prompts, explanations, and code examples.
    • Added and refined code examples across functional programming lessons.
  • Documentation
    • Updated question-format guidance for concept questions and option-level code examples.

部分 fp-* 題目把程式碼直接寫進 prompt/選項文字,只能當純文字擠成一行;
改為統一搬進既有的 code 欄位(QuestionOption 新增選填 code 欄位),
交給 CodeBlock 元件做語法上色渲染。

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 18, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
easy-learn Ready Ready Preview, Comment Jul 18, 2026 1:23pm

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@Retsomm, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 35 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 4273b76c-260b-44ce-b01a-bcf2760c7190

📥 Commits

Reviewing files that changed from the base of the PR and between 7a77b51 and 3165a31.

📒 Files selected for processing (27)
  • apps/mobile/components/CodeBlock.tsx
  • apps/web/src/components/QuestionCard.tsx
  • apps/web/src/index.css
  • packages/core/src/data/questions/fp-1-welcome.json
  • packages/core/src/data/questions/fp-10-first-class-functions-1.json
  • packages/core/src/data/questions/fp-14-nested-data.json
  • packages/core/src/data/questions/fp-15-timeline-diagrams.json
  • packages/core/src/data/questions/fp-17-coordinating-timelines.json
  • packages/core/src/data/questions/fp-18-reactive-onion.json
  • packages/core/src/data/questions/fp-19-road-ahead.json
  • packages/core/src/data/questions/fp-2-overview.json
  • packages/core/src/data/questions/fp-4-extract-calculations.json
  • packages/core/src/data/questions/fp-5-improve-actions.json
  • packages/core/src/data/questions/jsa-1-this-scope.json
  • packages/core/src/data/questions/jsa-2-closures.json
  • packages/core/src/data/questions/jsa-3-async-basics.json
  • packages/core/src/data/questions/jsa-5-classes.json
  • packages/core/src/data/questions/jsa-6-collections-json.json
  • packages/core/src/data/questions/jsb-6-loops.json
  • packages/core/src/data/questions/jsb-7-numbers-dates.json
  • packages/core/src/data/questions/react-1-jsx.json
  • packages/core/src/data/questions/react-11-refs.json
  • packages/core/src/data/questions/react-2-props.json
  • packages/core/src/data/questions/react-4-hooks.json
  • packages/core/src/data/questions/react-5-lists-conditional.json
  • packages/core/src/data/questions/react-7-pure-components.json
  • packages/core/src/data/questions/react-8-sharing-state.json
📝 Walkthrough

Walkthrough

Question data now supports structured code examples for questions and options. Web and mobile question cards and review screens render these examples conditionally, with mobile support for non-scrolling option code blocks.

Changes

Question code data and rendering

Layer / File(s) Summary
Question data contract and content migration
packages/core/src/types.ts, docs/question-format.md, packages/core/src/data/questions/*.json
QuestionOption accepts optional code, documentation defines structured code fields, and quiz examples are moved from prose or option text into dedicated code fields.
Web and mobile code rendering
apps/mobile/components/CodeBlock.tsx, apps/mobile/components/QuestionCard.tsx, apps/mobile/screens/QuestionReview.tsx, apps/web/src/components/QuestionCard.tsx, apps/web/src/components/QuestionReview.tsx, apps/web/src/index.css
Question and option code blocks render conditionally across web and mobile; mobile CodeBlock supports disabling horizontal scrolling, and option-specific styling is added.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant QuestionData
  participant QuestionReview
  participant CodeBlock
  QuestionData->>QuestionReview: Provide question.code and option.code
  QuestionReview->>CodeBlock: Render present question and option code
  CodeBlock-->>QuestionReview: Display highlighted code
Loading

Possibly related PRs

  • Retsomm/EasyLearn#11: Introduces the mobile CodeBlock implementation extended by this PR with non-scrolling rendering.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 標題清楚指出修正題庫程式碼片段未以 code block 顯示的主問題,與此次變更一致。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dev

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/web/src/components/QuestionCard.tsx (1)

59-67: 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Fix invalid HTML DOM nesting.

React will throw a validateDOMNesting warning because <button> elements cannot contain block-level elements like <pre> (which is rendered by the CodeBlock component). This produces invalid HTML and can cause hydration mismatches or accessibility issues.

Refactor the container into a semantic <div> with role="button" and add keyboard event handlers to retain full accessibility.

🔧 Proposed fix
-            <button
-              key={opt.id}
-              className={cls}
-              disabled={answered}
-              onClick={() => onSelect(opt.id)}
-            >
-              {opt.code && <CodeBlock code={opt.code} />}
-              {opt.text}
-            </button>
+            <div
+              key={opt.id}
+              className={cls}
+              role="button"
+              tabIndex={answered ? -1 : 0}
+              aria-disabled={answered}
+              onClick={() => {
+                if (!answered) onSelect(opt.id)
+              }}
+              onKeyDown={(e) => {
+                if (!answered && (e.key === 'Enter' || e.key === ' ')) {
+                  e.preventDefault()
+                  onSelect(opt.id)
+                }
+              }}
+            >
+              {opt.code && <CodeBlock code={opt.code} />}
+              <span>{opt.text}</span>
+            </div>

(Note: Verify that your CSS in index.css safely targets .option-btn without strictly requiring a button tag. For disabled styling, you might need to swap :disabled for [aria-disabled="true"].)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/web/src/components/QuestionCard.tsx` around lines 59 - 67, Replace the
native button container in the option rendering with a semantic div using
role="button", preserving the existing className, key, selection callback, and
answered state via aria-disabled. Add keyboard handlers to trigger onSelect for
Enter and Space while preventing default Space behavior, and update
disabled-state CSS selectors from :disabled to [aria-disabled="true"] if
required by .option-btn styling.
🧹 Nitpick comments (1)
apps/mobile/components/CodeBlock.tsx (1)

45-49: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider wrapping the text in a <View> for consistent box-model behavior.

Applying container styles (like borders and margins) directly to a <Text> node works in React Native, but can occasionally cause padding or layout clipping quirks on Android. Wrapping it in a <View> matches the layout structure of the ScrollView branch and ensures maximum consistency.

💡 Proposed refactor

Make sure to import View from react-native if it isn't already imported:

-  if (!scroll) {
-    return <Text style={[styles.wrap, styles.code]}>{highlight(code)}</Text>;
-  }
+  if (!scroll) {
+    return (
+      <View style={styles.wrap}>
+        <Text style={styles.code}>{highlight(code)}</Text>
+      </View>
+    );
+  }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/mobile/components/CodeBlock.tsx` around lines 45 - 49, Wrap the
non-scroll `highlight(code)` output in a `View` within `CodeBlock`, applying the
existing container styles to the `View` and keeping the code text styles on the
text content so its layout matches the `ScrollView` branch. Add the `View`
import from react-native if needed.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/core/src/data/questions/fp-14-nested-data.json`:
- Around line 100-101: Correct the nested-update example around badNestedUpdate
so its stated failure mode matches runtime behavior: with an empty keys array,
update receives an undefined object and throws a TypeError while accessing
object[key], rather than causing infinite recursion or stack overflow. Update
the associated prompt, explanation, and answer rationale consistently, unless
you modify the example so it genuinely recurses indefinitely.

---

Outside diff comments:
In `@apps/web/src/components/QuestionCard.tsx`:
- Around line 59-67: Replace the native button container in the option rendering
with a semantic div using role="button", preserving the existing className, key,
selection callback, and answered state via aria-disabled. Add keyboard handlers
to trigger onSelect for Enter and Space while preventing default Space behavior,
and update disabled-state CSS selectors from :disabled to [aria-disabled="true"]
if required by .option-btn styling.

---

Nitpick comments:
In `@apps/mobile/components/CodeBlock.tsx`:
- Around line 45-49: Wrap the non-scroll `highlight(code)` output in a `View`
within `CodeBlock`, applying the existing container styles to the `View` and
keeping the code text styles on the text content so its layout matches the
`ScrollView` branch. Add the `View` import from react-native if needed.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 3e27beaf-3d0e-42b6-974f-33a7d0367226

📥 Commits

Reviewing files that changed from the base of the PR and between 67ce545 and 7a77b51.

📒 Files selected for processing (18)
  • apps/mobile/components/CodeBlock.tsx
  • apps/mobile/components/QuestionCard.tsx
  • apps/mobile/screens/QuestionReview.tsx
  • apps/web/src/components/QuestionCard.tsx
  • apps/web/src/components/QuestionReview.tsx
  • apps/web/src/index.css
  • docs/question-format.md
  • packages/core/src/data/questions/fp-1-welcome.json
  • packages/core/src/data/questions/fp-10-first-class-functions-1.json
  • packages/core/src/data/questions/fp-13-chaining.json
  • packages/core/src/data/questions/fp-14-nested-data.json
  • packages/core/src/data/questions/fp-15-timeline-diagrams.json
  • packages/core/src/data/questions/fp-3-actions-calculations-data.json
  • packages/core/src/data/questions/fp-4-extract-calculations.json
  • packages/core/src/data/questions/fp-5-improve-actions.json
  • packages/core/src/data/questions/fp-6-copy-on-write.json
  • packages/core/src/data/questions/fp-7-defensive-copying.json
  • packages/core/src/types.ts

Comment thread packages/core/src/data/questions/fp-14-nested-data.json Outdated
答題後 disabled 的 <button> 會被移出 tab 順序,改用 aria-disabled 的 div
保留鍵盤/螢幕報讀器可及性;CodeBlock 非捲動分支補上 View 容器維持排版
一致;fp-14-q5 修正成實際會拋出 TypeError 而非無限遞迴塞爆堆疊。

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
修正 fp/jsa/jsb/react 題庫中「答案需要記得某章節內容才能理解」的設計問題:
把「第一章的坑」「react-4 學過的時序」「react-8 教過」這類跨關卡引用,
改成把該觀念直接在題目或解析裡講清楚,不假設使用者記得或已完成其他關卡。

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@Retsomm
Retsomm merged commit ca4edab into main Jul 18, 2026
3 checks passed
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