mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
PanelChrome, its collapse-preference restore and the phone shell read a panel's disclosure state back from the gev-panel-chrome store (_shownPanel), falling back to the markup's classes before the panel is first presented, instead of reading the classes v-panel-state draws. The share link and the phone shell share one rule for a panel the person keeps closed (prefersCollapsed). The rails, the accordion and the hover disclosure still read the classes, which the directive draws in the same task as their layout.
102 lines
3.6 KiB
JavaScript
102 lines
3.6 KiB
JavaScript
/** Own panel collapsed-state preferences and the one-time layout-reset notice. */
|
|
import { t } from '../i18n/index.js';
|
|
import { readPanelState } from './rail/panelState.js';
|
|
/** Versioned localStorage namespace prefix to invalidate stale panel layouts. */
|
|
const PANEL_LAYOUT_STORAGE_VERSION = 'v6';
|
|
/**
|
|
* Position keys are versioned separately from collapsed-state keys. The rails
|
|
* now lay panels out themselves and store no position; the version still names
|
|
* the layout-reset notice and the documented key.
|
|
*/
|
|
const PANEL_POSITION_STORAGE_VERSION = 'v8';
|
|
/** Floating panels' stored positions and hint flag: nothing reads them now. */
|
|
const RETIRED_PANEL_KEY_PREFIXES = [
|
|
`godsEyeView.${PANEL_POSITION_STORAGE_VERSION}.panelPos.`,
|
|
`godsEyeView.${PANEL_POSITION_STORAGE_VERSION}.panelFloatHintShown`,
|
|
];
|
|
export class PanelPositionControls {
|
|
constructor({ presentPanel, shownPanel = readPanelState, showToast }) {
|
|
this._presentPanel = presentPanel;
|
|
this._shownPanel = shownPanel;
|
|
this._showToast = showToast;
|
|
}
|
|
|
|
_maybeNotifyLayoutReset() {
|
|
this._dropRetiredPanelKeys();
|
|
try {
|
|
const marker = `godsEyeView.${PANEL_POSITION_STORAGE_VERSION}.layoutResetNotified`;
|
|
if (localStorage.getItem(marker)) return;
|
|
localStorage.setItem(marker, '1');
|
|
const hadOldPositions = Object.keys(localStorage).some((key) =>
|
|
key.startsWith('godsEyeView.v6.panelPos.'),
|
|
);
|
|
if (hadOldPositions) {
|
|
this._showToast(
|
|
t('Panel layout updated — positions reset to new defaults'),
|
|
);
|
|
}
|
|
} catch {
|
|
// storage unavailable
|
|
}
|
|
}
|
|
|
|
_dropRetiredPanelKeys() {
|
|
try {
|
|
for (const key of Object.keys(localStorage))
|
|
if (RETIRED_PANEL_KEY_PREFIXES.some((prefix) => key.startsWith(prefix)))
|
|
localStorage.removeItem(key);
|
|
} catch {
|
|
// storage unavailable
|
|
}
|
|
}
|
|
|
|
_panelCollapseStorageKey(panelId) {
|
|
return `godsEyeView.${PANEL_LAYOUT_STORAGE_VERSION}.panelCollapsed.${panelId}`;
|
|
}
|
|
|
|
_restorePanelCollapsedState(panelId, { allowStored = true } = {}) {
|
|
const panelEl = document.getElementById(panelId);
|
|
if (!panelEl) return;
|
|
let collapsed = this._shownPanel(panelEl).collapsed;
|
|
let stored = null;
|
|
if (allowStored) {
|
|
try {
|
|
stored = localStorage.getItem(this._panelCollapseStorageKey(panelId));
|
|
if (stored === '1') collapsed = true;
|
|
if (stored === '0') collapsed = false;
|
|
} catch {
|
|
// storage unavailable
|
|
}
|
|
}
|
|
// DISPLAY starts COLLAPSED for a first-time visitor, then respects the
|
|
// user's persisted choice like every other panel.
|
|
//
|
|
// It used to start expanded, to advertise the HUD / DETECT / 3D toggles.
|
|
// That reason expired when those became ON by default: the rail now opens
|
|
// to offer controls for things already happening, while competing with the
|
|
// first-run mission card for the one first impression there is. A stored
|
|
// choice still wins in both directions, so anyone who opens it keeps it.
|
|
if (panelId === 'pp-toggles' && stored === null) collapsed = true;
|
|
this._presentPanel(panelEl, { collapsed });
|
|
// Bodies that expand themselves on first appearance must not override a
|
|
// choice the user (or a share link) already made.
|
|
if (panelEl.dataset)
|
|
panelEl.dataset.collapsedPreference = !allowStored
|
|
? 'share'
|
|
: stored === null
|
|
? 'default'
|
|
: 'stored';
|
|
}
|
|
|
|
_savePanelCollapsedState(panelId, collapsed) {
|
|
try {
|
|
localStorage.setItem(
|
|
this._panelCollapseStorageKey(panelId),
|
|
collapsed ? '1' : '0',
|
|
);
|
|
} catch {
|
|
// storage unavailable
|
|
}
|
|
}
|
|
}
|