Skip to content

Allow changing default toc view, and disabling view selector#393

Open
matsest wants to merge 6 commits intobasecamp:mainfrom
matsest:feat/custom-toc-view-setting
Open

Allow changing default toc view, and disabling view selector#393
matsest wants to merge 6 commits intobasecamp:mainfrom
matsest:feat/custom-toc-view-setting

Conversation

@matsest
Copy link

@matsest matsest commented Mar 18, 2026

This pull request introduces configurable view settings for books, allowing admins to set a default view (list or grid) and control whether users can switch between views.

The existing behavior with having a view selector with grid as default is preserved.

Motivation

Give authors a way of showing their publications in their preferred way, either as with a default or enforced (no view selector).

Changes

  • Migration adds default_view (default: "grid") and allow_view_selector (default: true) columns to books
  • Updates book form with radio buttons for default view selection and toggle for view selector visibility
  • Conditionally renders view selector UI based on allow_view_selector? setting
  • CSS classes force the selected view when selector is disabled
  • JavaScript uses book's default view instead of hardcoded "grid"
  • Adds tests for updated model and controller

Screenshots

Screenshots - expand to show

Book settings:
image

Reader view with allow_view_selector:false and default_view: grid
image

Reader view with allow_view_selector:false and default_view: list
image

Reader view with default settings (allow_view_selector:true and default_view: grid)
image

Copilot AI review requested due to automatic review settings March 18, 2026 18:47
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds per-book configuration for the table-of-contents (ToC) view, allowing admins to choose a default ToC view (list/grid) and optionally disable the view selector so readers can’t change it.

Changes:

  • Add default_view and allow_view_selector to books, plus model enum support and strong params.
  • Update book settings form and show page to respect the new view settings.
  • Update the ToC Stimulus controller to use the book’s configured default view; add model/controller tests.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
db/migrate/20260317235838_add_view_settings_to_books.rb Adds new books columns for default/enforced ToC view behavior.
db/schema.rb Reflects new columns and updated schema dump.
app/models/book.rb Introduces default_view enum for list/grid.
app/controllers/books_controller.rb Permits default_view and allow_view_selector in book_params.
app/views/books/_form.html.erb Adds UI controls for selecting default view and enabling/disabling the selector.
app/views/books/show.html.erb Conditionally renders the view selector; applies forced view class when selector is disabled.
app/javascript/controllers/toc_view_controller.js Uses book-provided default view (instead of hardcoded "grid").
app/assets/stylesheets/toc.css Adds forced-view CSS classes when selector is disabled.
test/models/book_test.rb Adds coverage for new default values and enum predicate.
test/controllers/books_controller_test.rb Adds coverage for persisting settings and conditional selector rendering.

[!TIP]
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

Comments suppressed due to low confidence (1)

app/javascript/controllers/toc_view_controller.js:22

  • #restoreViewPref has mismatched braces/parentheses: the forEach callback isn’t closed properly, leaving the file with a JavaScript syntax error that will prevent the Stimulus controller from loading. Fix the block so the forEach call and method body close correctly.
    const viewType = readCookie(id) || this.defaultValue
    this.switchTargets.forEach(switchTarget => {
      switchTarget.checked = switchTarget.dataset.tocViewTypeValue === viewType
    }
  )}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@matsest
Copy link
Author

matsest commented Mar 18, 2026

I don't know if you're open to PRs at this point (couldn't find any contribution guidelines), or if you're not looking for new "features" to Writebook, so feel free to discard it or change it up any way you like. This was mostly a personal preference from my side.

Disclaimer: Kimi K2.5 wrote all of this in a few prompts 🤖

Review suggestion by Copilot

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 18, 2026 18:55
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds per-book configuration for the table-of-contents (TOC) view, allowing an editor/admin to set a default TOC view (list/grid) and optionally disable the view selector so readers cannot switch.

Changes:

  • Add books.default_view (default "grid") and books.allow_view_selector (default true) via migration/schema and expose them through strong params.
  • Update the book form to configure these settings and update the TOC UI to conditionally render the selector and/or force a view via CSS classes.
  • Update the Stimulus controller to use the book’s configured default view (instead of hardcoded "grid") and add controller/model tests.

Tip

If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
db/migrate/20260317235838_add_view_settings_to_books.rb Adds DB columns for default/enforced TOC view behavior.
db/schema.rb Reflects new columns and updated schema dump.
app/models/book.rb Introduces default_view enum with a grid default.
app/controllers/books_controller.rb Permits the new fields on create/update.
app/views/books/_form.html.erb Adds UI controls for default view + selector toggle.
app/views/books/show.html.erb Conditionally renders selector and applies forced-view CSS classes + passes default to JS.
app/javascript/controllers/toc_view_controller.js Uses the per-book default view when no cookie preference exists.
app/assets/stylesheets/toc.css Adds forced list/grid styling when selector is disabled.
test/models/book_test.rb Tests defaults for default_view and allow_view_selector.
test/controllers/books_controller_test.rb Tests persistence of settings and selector visibility/forced class behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Review suggestion by copilot

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 18, 2026 19:03
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds per-book configuration for TOC display, letting admins choose a default TOC view (list/grid) and optionally disable the view selector so the chosen view is enforced.

Changes:

  • Adds books.default_view (default "grid") and books.allow_view_selector (default true) plus model/controller support.
  • Updates book form + book show view to configure and conditionally render the TOC view selector, including forced-view CSS.
  • Updates the TOC Stimulus controller to use the book’s default view and adds/updates tests.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
db/migrate/20260317235838_add_view_settings_to_books.rb Adds DB columns for default/enforced TOC view behavior.
db/schema.rb Reflects new columns and schema dump updates.
app/models/book.rb Introduces default_view enum with default value.
app/controllers/books_controller.rb Permits new view-setting params on create/update.
app/views/books/_form.html.erb Adds admin UI to set default view and toggle selector visibility.
app/views/books/show.html.erb Conditionally renders selector; applies forced-view class + passes default to JS.
app/javascript/controllers/toc_view_controller.js Uses per-book default view (but currently has a syntax issue).
app/assets/stylesheets/toc.css Adds forced list/grid styling when selector is disabled.
test/models/book_test.rb Adds model default tests for new fields.
test/controllers/books_controller_test.rb Adds controller/show behavior tests for selector visibility and forced class.

[!TIP]
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

Comments suppressed due to low confidence (1)

app/javascript/controllers/toc_view_controller.js:22

  • #restoreViewPref has mismatched braces/parentheses in the forEach callback, which makes this controller invalid JavaScript and will prevent the TOC view preference logic from running. Please fix the closing }) / method braces so the file parses correctly.
  #restoreViewPref(id) {
    const viewType = readCookie(id) || this.defaultValue
    this.switchTargets.forEach(switchTarget => {
      switchTarget.checked = switchTarget.dataset.tocViewTypeValue === viewType
    }
  )}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

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.

2 participants