feat: wire frontend state and data flow for multi-chart support

- Add activeChartId/charts state to page.tsx with chart fetching on mount
- ChartSelector integrated in sidebar between header and file upload
- CandleChart and SvgOverlay fetch data scoped by activeChartId
- FileUpload returns chart info, auto-selects new chart after upload
- Annotation create/delete flows include chart_id
- Export scoped by activeChartId
- Toolbox receives activeChartId prop
This commit is contained in:
Marko Djordjevic 2026-02-13 00:17:09 +01:00
parent a3c7137b01
commit b9771fe89f
6 changed files with 126 additions and 37 deletions

View file

@ -42,6 +42,7 @@ interface CandleChartProps {
selectedColor: string;
selectedLabelId?: number | null;
onLabelSelect?: (id: number) => void;
activeChartId?: number | null;
}
export interface CandleChartHandle {
@ -49,7 +50,7 @@ export interface CandleChartHandle {
}
const CandleChart = forwardRef<CandleChartHandle, CandleChartProps>(
({ activeTool, onAnnotationChange, selectedColor, selectedLabelId, onLabelSelect }, ref) => {
({ activeTool, onAnnotationChange, selectedColor, selectedLabelId, onLabelSelect, activeChartId }, ref) => {
const chartContainerRef = useRef<HTMLDivElement>(null);
const chartRef = useRef<IChartApi | null>(null);
const seriesRef = useRef<ISeriesApi<'Candlestick'> | null>(null);
@ -68,7 +69,8 @@ const CandleChart = forwardRef<CandleChartHandle, CandleChartProps>(
// Fetch candles from API
const fetchCandles = async () => {
try {
const response = await fetch('/api/candles');
const url = activeChartId ? `/api/candles?chartId=${activeChartId}` : '/api/candles';
const response = await fetch(url);
const data = await response.json();
setCandles(data);
setIsEmpty(data.length === 0);
@ -82,7 +84,8 @@ const CandleChart = forwardRef<CandleChartHandle, CandleChartProps>(
// Fetch annotations from API
const fetchAnnotations = async () => {
try {
const response = await fetch('/api/annotations');
const url = activeChartId ? `/api/annotations?chartId=${activeChartId}` : '/api/annotations';
const response = await fetch(url);
const data = await response.json();
setAnnotations(data);
return data;
@ -308,6 +311,7 @@ const CandleChart = forwardRef<CandleChartHandle, CandleChartProps>(
body: JSON.stringify({
timestamp: nearestCandle.time,
label_type: activeTool,
chart_id: activeChartId,
}),
});
@ -410,6 +414,7 @@ const CandleChart = forwardRef<CandleChartHandle, CandleChartProps>(
activeTool={activeTool}
onAnnotationChange={onAnnotationChange}
selectedColor={selectedColor}
activeChartId={activeChartId}
/>
</div>
);