MCPcopy Create free account
hub / github.com/chartbrew/chartbrew / fetchChartData

Function fetchChartData

client/src/containers/Ai/AiModal.jsx:106–134  ·  view source on GitHub ↗
(chartId, projectId)

Source from the content-addressed store, hash-verified

104
105 // Function to fetch chart data when a chart is created
106 const fetchChartData = async (chartId, projectId) => {
107 try {
108 const result = await dispatch(getChart({
109 project_id: projectId,
110 chart_id: chartId
111 }));
112
113 if (result?.payload) {
114 setCreatedCharts(prevCharts => {
115 // Check if chart already exists
116 const existingIndex = prevCharts.findIndex(c => c.id === result.payload.id);
117 if (existingIndex >= 0) {
118 // Update existing chart
119 const updatedCharts = [...prevCharts];
120 updatedCharts[existingIndex] = result.payload;
121 return updatedCharts;
122 } else {
123 // Add new chart
124 return [...prevCharts, result.payload];
125 }
126 });
127 return result.payload;
128 }
129 } catch (error) {
130 console.error("Failed to fetch chart data:", error);
131 toast.error("Failed to load chart data");
132 }
133 return null;
134 };
135
136 // Auto-scroll to bottom when messages change
137 useEffect(() => {

Callers 1

fetchNewChartsFunction · 0.85

Calls 2

getChartFunction · 0.90
dispatchFunction · 0.50

Tested by

no test coverage detected