feat: persist navigation state#354
Conversation
|
@TheBullRing I'm not sure what issue you're trying to fix with this. As far as I can see this only happens if you change the card configuration. How often do you change this? |
|
My integration uses the my-skylight-calendar project (https://github.com/mohesles/my-skylight-calendar), which is based on the week-planner-card component. When a user navigates away from the current week (e.g., advancing to the next week using the navigation arrows), the navigation state is lost if a calendar toggle is pressed. After the re-render, the view unexpectedly resets to the current week instead of maintaining the previously selected date. Resolution Introduced in PR
On load, the card checks for an existing saved offset associated with its card_id and restores it.
With the persistence mechanism in place, navigation state is preserved across card re-renders, resolving the usability issue and ensuring users can reliably plan future dates without repeated navigation. |
Feature: Persist Navigation State
Problem
The week-planner-card previously lost its navigation state (current date view) whenever the component was re-rendered or the configuration changed (e.g., adding/toggling calendars). This caused the view to reset to "today", frustrating users who were navigating through future/past dates.
Solution
Implemented a persistence mechanism using a static class property WeekPlannerCard.persistence to store the navigation offset for each card instance.
Key Changes
_card_id Configuration: Added a new optional configuration parameter card_id. If provided, the card uses this ID to key its state in the persistent storage.
State Persistence: The _navigationOffset (which determines the viewed date range) is saved to WeekPlannerCard.persistence[card_id] whenever navigation occurs (next/prev/today).
State Restoration: When setConfig is called (e.g., on dashboard refresh or config update), the card checks for an existing state for the given card_id and restores the _navigationOffset.
Events: Dispatches a new week-planner-date-changed event whenever the navigation changes, containing the startDate, navigationOffset, and card_id.
Configuration Example
Verification
verified that adding card_id preserves the view when toggling other config options.
verified that without card_id, behavior remains unchanged (no persistence).