Prechádzať zdrojové kódy

Add feed data type counters

Implement counters for each feed data type.
gpt-engineer-app[bot] 5 mesiacov pred
rodič
commit
af24ad8c5d
2 zmenil súbory, kde vykonal 13 pridanie a 2 odobranie
  1. 12 1
      src/components/CategoryFilter.tsx
  2. 1 1
      src/pages/Index.tsx

+ 12 - 1
src/components/CategoryFilter.tsx

@@ -19,6 +19,7 @@ interface CategoryFilterProps {
   onCategoryChange: (categoryId: string | null) => void;
   newsCount: number;
   pinnedCount?: number;
+  articles: any[]; // Add articles to calculate counts per category
 }
 
 const iconMap = {
@@ -33,10 +34,16 @@ const CategoryFilter = ({
   selectedCategory, 
   onCategoryChange,
   newsCount,
-  pinnedCount = 0
+  pinnedCount = 0,
+  articles
 }: CategoryFilterProps) => {
   const { user } = useAuth();
 
+  // Calculate count for each category
+  const getCategoryCount = (categoryType: string) => {
+    return articles.filter(article => article.category === categoryType).length;
+  };
+
   return (
     <div className="bg-card border rounded-lg p-6 space-y-4">
       <div className="flex items-center gap-2">
@@ -59,6 +66,7 @@ const CategoryFilter = ({
         {categories.map((category) => {
           const IconComponent = iconMap[category.icon as keyof typeof iconMap];
           const isSelected = selectedCategory === category.id;
+          const categoryCount = getCategoryCount(category.type);
           
           return (
             <Button
@@ -69,6 +77,9 @@ const CategoryFilter = ({
             >
               <IconComponent className="h-4 w-4" />
               <span>{category.name}</span>
+              <Badge variant="secondary" className="ml-auto">
+                {categoryCount}
+              </Badge>
             </Button>
           );
         })}

+ 1 - 1
src/pages/Index.tsx

@@ -125,7 +125,7 @@ const Index = () => {
         <div className="grid grid-cols-1 lg:grid-cols-4 gap-6">
           {/* Sidebar */}
           <div className={`lg:col-span-1 space-y-6 ${!showFilters && 'hidden lg:block'}`}>
-            <CategoryFilter categories={categories} selectedCategory={selectedCategory} onCategoryChange={setSelectedCategory} newsCount={articles.length} pinnedCount={pinnedCount} />
+            <CategoryFilter categories={categories} selectedCategory={selectedCategory} onCategoryChange={setSelectedCategory} newsCount={articles.length} pinnedCount={pinnedCount} articles={articles} />
             
             <div className="bg-card border rounded-lg p-4 space-y-3">
               <h3 className="font-semibold text-sm">Statistiques</h3>