Allow changing default toc view, and disabling view selector#393
Allow changing default toc view, and disabling view selector#393matsest wants to merge 6 commits intobasecamp:mainfrom
Conversation
There was a problem hiding this comment.
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_viewandallow_view_selectortobooks, 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 rungh pr ready --undo.
Click "Ready for review" or rungh pr readyto reengage.
Comments suppressed due to low confidence (1)
app/javascript/controllers/toc_view_controller.js:22
#restoreViewPrefhas mismatched braces/parentheses: theforEachcallback isn’t closed properly, leaving the file with a JavaScript syntax error that will prevent the Stimulus controller from loading. Fix the block so theforEachcall 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.
|
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>
There was a problem hiding this comment.
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") andbooks.allow_view_selector(defaulttrue) 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>
There was a problem hiding this comment.
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") andbooks.allow_view_selector(defaulttrue) 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 rungh pr ready --undo.
Click "Ready for review" or rungh pr readyto reengage.
Comments suppressed due to low confidence (1)
app/javascript/controllers/toc_view_controller.js:22
#restoreViewPrefhas mismatched braces/parentheses in theforEachcallback, 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.
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
gridas 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
default_view(default: "grid") andallow_view_selector(default: true) columns to booksallow_view_selector?settingScreenshots
Screenshots - expand to show
Book settings:

Reader view with

allow_view_selector:falseanddefault_view:gridReader view with

allow_view_selector:falseanddefault_view:listReader view with default settings (

allow_view_selector:trueanddefault_view:grid)