fix: reset stale price analysis selection
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import React, { useState, useMemo } from 'react';
|
||||
import React, { useState, useMemo, useEffect } from 'react';
|
||||
import { ResponsiveContainer, BarChart, Bar, XAxis, YAxis, Tooltip, CartesianGrid, Cell } from 'recharts';
|
||||
import { TrendingUp, Download, Sparkles, Inbox } from 'lucide-react';
|
||||
import { useApp } from '../../context/AppContext';
|
||||
@@ -10,6 +10,10 @@ export const PriceAnalysis = () => {
|
||||
const { items, itemCount, uniqueItems } = useMemo(() => itemStats(tenders), [tenders]);
|
||||
const [selectedKey, setSelectedKey] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (selectedKey && !items.some((item) => `${item.ad}||${item.birim}` === selectedKey)) setSelectedKey(null);
|
||||
}, [items, selectedKey]);
|
||||
|
||||
const selected = useMemo(() => {
|
||||
if (!items.length) return null;
|
||||
const found = items.find((i) => `${i.ad}||${i.birim}` === selectedKey);
|
||||
|
||||
Reference in New Issue
Block a user