Update Industries.tsx
This commit is contained in:
@@ -10,8 +10,19 @@ import { PieChartIcon } from '../../icons';
|
|||||||
interface IndustryWithData extends Industry {
|
interface IndustryWithData extends Industry {
|
||||||
keywordsCount: number;
|
keywordsCount: number;
|
||||||
topKeywords: SeedKeyword[];
|
topKeywords: SeedKeyword[];
|
||||||
|
totalVolume: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Format volume with k for thousands and m for millions
|
||||||
|
const formatVolume = (volume: number): string => {
|
||||||
|
if (volume >= 1000000) {
|
||||||
|
return `${(volume / 1000000).toFixed(1)}m`;
|
||||||
|
} else if (volume >= 1000) {
|
||||||
|
return `${(volume / 1000).toFixed(1)}k`;
|
||||||
|
}
|
||||||
|
return volume.toString();
|
||||||
|
};
|
||||||
|
|
||||||
export default function Industries() {
|
export default function Industries() {
|
||||||
const toast = useToast();
|
const toast = useToast();
|
||||||
const [industries, setIndustries] = useState<IndustryWithData[]>([]);
|
const [industries, setIndustries] = useState<IndustryWithData[]>([]);
|
||||||
@@ -51,10 +62,17 @@ export default function Industries() {
|
|||||||
.sort((a, b) => (b.volume || 0) - (a.volume || 0))
|
.sort((a, b) => (b.volume || 0) - (a.volume || 0))
|
||||||
.slice(0, 5);
|
.slice(0, 5);
|
||||||
|
|
||||||
|
// Calculate total volume of all keywords
|
||||||
|
const totalVolume = industryKeywords.reduce(
|
||||||
|
(sum, kw) => sum + (kw.volume || 0),
|
||||||
|
0
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...industry,
|
...industry,
|
||||||
keywordsCount: industryKeywords.length,
|
keywordsCount: industryKeywords.length,
|
||||||
topKeywords,
|
topKeywords,
|
||||||
|
totalVolume,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -102,9 +120,9 @@ export default function Industries() {
|
|||||||
<h3 className="text-base font-bold text-gray-900 dark:text-white leading-tight">
|
<h3 className="text-base font-bold text-gray-900 dark:text-white leading-tight">
|
||||||
{industry.name}
|
{industry.name}
|
||||||
</h3>
|
</h3>
|
||||||
{industry.is_active !== false && (
|
{industry.totalVolume > 0 && (
|
||||||
<Badge variant="light" color="success" size="xs">
|
<Badge variant="solid" color="dark" size="sm">
|
||||||
Active
|
{formatVolume(industry.totalVolume)}
|
||||||
</Badge>
|
</Badge>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user