Files
sure/app/javascript/controllers/auto_open_controller.js
LPW 8c9764f1ad Unify provider and account card UI and move setup actions to menus (#755)
* feat: add auto-open functionality for collapsible sections and streamline unlinked account handling

- Introduce `auto-open` Stimulus controller to auto-expand <details> elements based on URL params.
- Update all settings sections and panels to support the new `auto_open_param` for seamless navigation.
- Improve unlinked account logic for Coinbase, SimpleFIN, and SnapTrade, ensuring consistent and optimized handling.
- Refactor sync warnings and badges for better readability and user experience.
- Extend localization for additional menu items, warnings, and setup prompts.

* fix: improve error handling and safe HTML usage in Coinbase and settings components

- Log warning for unhandled exceptions in Coinbase unlinked account count fallback.
- Escape `auto_open_param` in settings section for safe HTML injection.
- Clean up URL params in `auto-open` controller after auto-expansion.

---------

Co-authored-by: luckyPipewrench <luckypipewrench@proton.me>
2026-01-24 01:11:56 +01:00

30 lines
1022 B
JavaScript

import { Controller } from "@hotwired/stimulus";
// Connects to data-controller="auto-open"
// Auto-opens a <details> element based on URL param
// Use data-auto-open-param-value="paramName" to open when ?paramName=1 is in URL
export default class extends Controller {
static values = { param: String };
connect() {
if (!this.hasParamValue || !this.paramValue) return;
const params = new URLSearchParams(window.location.search);
if (params.get(this.paramValue) === "1") {
this.element.open = true;
// Clean up the URL param after opening
params.delete(this.paramValue);
const newUrl = params.toString()
? `${window.location.pathname}?${params.toString()}${window.location.hash}`
: `${window.location.pathname}${window.location.hash}`;
window.history.replaceState({}, "", newUrl);
// Scroll into view after opening
requestAnimationFrame(() => {
this.element.scrollIntoView({ behavior: "smooth", block: "start" });
});
}
}
}