## Add User Preferences Support to iD Editor

### Summary
This PR implements server-side rendering of user preferences for the iD editor, 
making them accessible in the client-side JavaScript context.

### Technical Changes

**Server-side (`app/views/site/id.html.erb`):**
- Added user preference collection logic that fetches all preferences for the 
current user
- Converts preferences from ActiveRecord objects to a hash structure (`{key 
=> value}`)
- Serializes preferences as JSON and includes them in the data attributes 
passed to the iD container

**Client-side (`app/assets/javascripts/id.js`):**
- Added preference parsing logic that extracts user preferences from the 
container's dataset
- Parses JSON-encoded preferences and makes them available globally via 
`window.OSM.userPreferences`
- Provides fallback to empty object for unauthenticated users or users without 
preferences

### Implementation Details
- Follows existing pattern used for other iD editor data (token, locale, 
asset_map)
- User preferences are fetched via 
`current_user.preferences.each_with_object({})` for efficient hash construction
- Data flow: Database → Ruby hash → JSON string → HTML data attribute → 
JavaScript object
- Preferences are only included when `current_user` exists (authenticated users)
- Client-side code gracefully handles missing or malformed preference data

### Use Case
This enables the iD editor to access user-specific preferences (such as display 
settings, editor configurations, etc.) that were previously only available 
through separate API calls, improving performance and reducing client-server 
round trips during editor initialization.

### Testing
- Verified with authenticated users having preferences
- Verified with authenticated users having no preferences  
- Verified with unauthenticated users
- Confirmed preferences are accessible via `window.OSM.userPreferences` in 
browser console
You can view, comment on, or merge this pull request online at:

  https://github.com/openstreetmap/openstreetmap-website/pull/6199

-- Commit Summary --

  * Add user preferences support to iD editor via server-side rendering

-- File Changes --

    M app/assets/javascripts/id.js (9)
    M app/views/site/id.html.erb (10)

-- Patch Links --

https://github.com/openstreetmap/openstreetmap-website/pull/6199.patch
https://github.com/openstreetmap/openstreetmap-website/pull/6199.diff

-- 
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/6199
You are receiving this because you are subscribed to this thread.

Message ID: <openstreetmap/openstreetmap-website/pull/6...@github.com>
_______________________________________________
rails-dev mailing list
rails-dev@openstreetmap.org
https://lists.openstreetmap.org/listinfo/rails-dev

Reply via email to