Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When unselected sessions closed, store tha state in LocalStorage and restore it later #329

Merged
merged 2 commits into from
Apr 1, 2025

Conversation

kinoppyd
Copy link
Member

Features

When a user closes an unselected sessions, they expect it to stay closed after reloading the page.
Store the state in LocalStorage and restore it when the component is connected.

@kinoppyd kinoppyd requested a review from Copilot March 29, 2025 14:29
Copy link

@Copilot 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 implements state persistence for unselected sessions by storing their closed state in LocalStorage and restoring it when the component is connected.

  • Modified the session view template to include a data attribute for session key identification.
  • Updated the Stimulus controller to manage LocalStorage interactions and added logic to restore UI state based on stored values.

Reviewed Changes

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

File Description
app/views/components/_session.html.erb Added data attribute for session key to support persistence in LocalStorage.
app/javascript/controllers/sessions_controller.js Extended controller values and toggle logic to store and restore session open/closed state using LocalStorage.
Comments suppressed due to low confidence (2)

app/views/components/_session.html.erb:3

  • Ensure that 'row.turbo_frames_id' produces a unique identifier for each session component; otherwise, LocalStorage keys might conflict, causing unintended behavior in state restoration.
<div data-controller="sessions" data-sessions-is-open-value="<%= !scheduled %>" data-sessions-key-value="<%= row.turbo_frames_id %>" class="bg-gray-100 rounded-lg p-3 shadow-md border">

app/javascript/controllers/sessions_controller.js:29

  • [nitpick] The variable name 'override' is unclear; consider renaming it to something more descriptive like 'shouldStoreState' to better convey its intent.
let override = true;

@kinoppyd kinoppyd merged commit 7b2f916 into 2025 Apr 1, 2025
2 checks passed
@kinoppyd kinoppyd deleted the features/remember_the_state_of_open_close branch April 1, 2025 07:10
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