Sync saved settings to ReaderApp without page refresh#3151
Sync saved settings to ReaderApp without page refresh#3151YishaiGlasner wants to merge 3 commits intomasterfrom
Conversation
…refresh.
After saving account settings, dispatch a custom DOM event to update ReaderApp state and Sefaria globals (translation language preference, reading history, experiments, calendars). For interface language changes,
redirect via /interface/{lang} instead.
…atbot token. Replace in-event experiments update with page reload since toggling experiments requires a fresh chatbot_user_token from the server.
There was a problem hiding this comment.
Pull request overview
This PR enables real-time syncing of saved account settings to the React-based ReaderApp (running in headerMode) without requiring a page refresh. It follows the existing sefaria:bootstrap-url custom DOM event pattern to communicate between the jQuery-based account settings page and the React component tree.
Changes:
- Dispatches a
sefaria:settings-updatedcustom DOM event after saving account settings, with special handling for interface language (redirect) and experiments (reload) - Adds a handler in
ReaderAppthat updates translation language preference state, reading history flag, and calendar data in response to the new event - Introduces
Sefaria.updateCalendars()utility to re-fetch calendar data when the textual custom (Ashkenazi/Sephardi) preference changes
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| templates/account_settings.html | Dispatches sefaria:settings-updated event after successful save; adds early returns for language redirect and experiments reload |
| static/js/ReaderApp.jsx | Adds event listener/handler for sefaria:settings-updated to update React state and global Sefaria state |
| static/js/sefaria/sefaria.js | Adds updateCalendars() method to fetch fresh calendar data from the API |
| reader/views.py | Passes request.diaspora to account settings template context for calendar API calls |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
🧪 CI InsightsHere's what we observed from your CI run for d8790d1. ✅ Passed Jobs With Interesting Signals
|
…t will redirect to the right domain.
stevekaplan123
left a comment
There was a problem hiding this comment.
I'm confused why we need a custom event. Why can't this function be called when the user clicks save?
because it's reactive. you can't change ReaderApp state from django template. |
Summary
When saving account settings, the changes were persisted to the database and cookies but ReaderApp (mounted as a header overlay with
headerMode: True) retained stale state until a page refresh. This PR syncs saved settings to the React app in real-time using a custom DOM event, following the existingsefaria:bootstrap-urlpattern.Changes
Event dispatch from account settings (account_settings.html)
sefaria:settings-updatedcustom event with the new settings as payloadtextual_customsince it's the only setting that triggers an expensive operation (calendars API re-fetch); all other settings are always included as their updates are cheapchatbot_user_tokenis generated server-side and requires fresh propsEvent handler in ReaderApp (ReaderApp.jsx)
sefaria:settings-updatedevent and updates:translationLanguagePreference→setState(passed as prop to Header → InterfaceLanguageMenu)readingHistory→Sefaria.is_history_enabled(checked bysaveUserHistoryandUserHistoryPanel)textualCustom→ callsSefaria.updateCalendars()to re-fetch calendar data with the new Ashkenazi/Sephardi preferenceNew
updateCalendarsutility (sefaria.js)Sefaria.updateCalendars(custom, diaspora)near the existingcalendarReffunctionSefaria._ApiPromiseto fetch/api/calendarsand updateSefaria.calendarsDiaspora context (views.py)
request.diasporato the account settings template context so the calendars API call can use the correct diaspora valueNote
I'm open to the claim that we shouldn't do all of this, but only refresh page after any click on save, or any click on save that changed setting (except email frequency).