global: snapshot

This commit is contained in:
nym21
2026-01-19 16:54:08 +01:00
parent 371ff86287
commit fba0550dda
2 changed files with 16 additions and 29 deletions

View File

@@ -469,7 +469,16 @@ function createIndexSelector(option, state) {
);
});
// Create UI that syncs with state.index
/** @type {ChartableIndexName} */
const defaultIndex = "date";
const { field } = createChoiceField({
defaultValue: defaultIndex,
signal: state.index,
choices,
id: "index",
signals,
});
const fieldset = window.document.createElement("fieldset");
fieldset.id = "interval";
@@ -477,33 +486,9 @@ function createIndexSelector(option, state) {
screenshotSpan.innerText = "interval:";
fieldset.append(screenshotSpan);
const select = window.document.createElement("select");
select.id = "index";
fieldset.append(select);
fieldset.append(field);
fieldset.dataset.size = "sm";
// Populate and update options when choices change
signals.createEffect(choices, (choices) => {
const currentValue = state.index();
select.innerHTML = "";
choices.forEach((choice) => {
const option = window.document.createElement("option");
option.value = choice;
option.textContent = choice;
option.selected = choice === currentValue;
select.append(option);
});
});
// Sync select value with state
signals.createEffect(state.index, (value) => {
select.value = value;
});
select.addEventListener("change", () => {
state.index.set(/** @type {ChartableIndexName} */ (select.value));
});
// Convert short name to internal name
const index = signals.createMemo(() =>
serdeChartableIndex.deserialize(state.index()),