feat(hub): click archive trade row to switch chart
When the K-line panel is open, clicking a trade row switches selection and chart markers without re-fetching candles for the same symbol. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -945,6 +945,50 @@
|
||||
);
|
||||
}
|
||||
|
||||
function isTradeRowInteractiveTarget(el) {
|
||||
return !!(
|
||||
el &&
|
||||
el.closest &&
|
||||
el.closest("button, select, input, textarea, a, label, .archive-actions-cell")
|
||||
);
|
||||
}
|
||||
|
||||
async function switchToTrade(tr) {
|
||||
if (!tr) return;
|
||||
const exKey = String(tr.exchange_key || "").toLowerCase();
|
||||
const sym = tr.symbol || "";
|
||||
if (!exKey || !sym) {
|
||||
setStatus("该笔交易缺少交易所或合约,无法切换");
|
||||
return;
|
||||
}
|
||||
const key = tradeRowKey(tr);
|
||||
const prevEx = selected && selected.exchange_key;
|
||||
const prevSym = selected && selected.symbol;
|
||||
if (key === selectedTradeKey && prevEx === exKey && prevSym === sym) return;
|
||||
|
||||
selected = { exchange_key: exKey, symbol: sym };
|
||||
selectedTradeKey = key;
|
||||
renderTrades();
|
||||
|
||||
const needSymbolReload = prevEx !== exKey || prevSym !== sym;
|
||||
if (needSymbolReload) {
|
||||
await loadSymbolTradesForChart(exKey, sym);
|
||||
}
|
||||
if (!isChartOpen()) return;
|
||||
|
||||
if (needSymbolReload) {
|
||||
await loadChart();
|
||||
return;
|
||||
}
|
||||
applyChartMarkers();
|
||||
const anchor = pickAnchorTrade();
|
||||
if (anchor && lastCandles.length) {
|
||||
focusInitialTradeView(lastCandles, anchor, timeframe);
|
||||
}
|
||||
updateChartTitle();
|
||||
setStatus("已切换至 " + sym + " · " + exchangeLabel(exKey));
|
||||
}
|
||||
|
||||
async function openTradeChart(tr) {
|
||||
if (!tr) return;
|
||||
const exKey = String(tr.exchange_key || "").toLowerCase();
|
||||
@@ -953,12 +997,8 @@
|
||||
setStatus("该笔交易缺少交易所或合约,无法加载图表");
|
||||
return;
|
||||
}
|
||||
selected = { exchange_key: exKey, symbol: sym };
|
||||
selectedTradeKey = tradeRowKey(tr);
|
||||
renderTrades();
|
||||
setChartOpen(true);
|
||||
await loadSymbolTradesForChart(exKey, sym);
|
||||
await loadChart();
|
||||
await switchToTrade(tr);
|
||||
}
|
||||
|
||||
function renderTrades() {
|
||||
@@ -1080,14 +1120,31 @@
|
||||
}
|
||||
});
|
||||
});
|
||||
elTrades.querySelectorAll(".archive-trade-row").forEach(function (row) {
|
||||
row.addEventListener("click", function (ev) {
|
||||
if (!isChartOpen()) return;
|
||||
if (isTradeRowInteractiveTarget(ev.target)) return;
|
||||
const tr = findTradeByKey(row.getAttribute("data-key"));
|
||||
if (tr) void switchToTrade(tr);
|
||||
});
|
||||
});
|
||||
elTrades.querySelectorAll(".archive-tag-select").forEach(function (sel) {
|
||||
applyTagSelectStyle(sel);
|
||||
sel.addEventListener("mousedown", function (ev) {
|
||||
ev.stopPropagation();
|
||||
});
|
||||
sel.addEventListener("change", function () {
|
||||
applyTagSelectStyle(sel);
|
||||
saveOverlay(sel.getAttribute("data-id"), sel.getAttribute("data-ex"), sel.value, null);
|
||||
});
|
||||
});
|
||||
elTrades.querySelectorAll(".archive-note-input").forEach(function (inp) {
|
||||
inp.addEventListener("mousedown", function (ev) {
|
||||
ev.stopPropagation();
|
||||
});
|
||||
inp.addEventListener("click", function (ev) {
|
||||
ev.stopPropagation();
|
||||
});
|
||||
inp.addEventListener("change", function () {
|
||||
const row = inp.closest(".archive-trade-row");
|
||||
const tagSel = row && row.querySelector(".archive-tag-select");
|
||||
|
||||
Reference in New Issue
Block a user