Przeglądaj źródła

Fix article filtering logic

Ensured that the date filter resets correctly when switching between "All articles" and "Followed feeds only" modes. Modified `useRealArticles.tsx` to properly separate date filtering from mode filtering, guaranteeing that "All articles" displays all content when no date filter is active. Updated UI elements in `Index.tsx` and `CategoryFilter.tsx` for clearer filter indication.
Here are the files that were edited by the AI in that message:
-edited src/pages/Index.tsx
-edited src/hooks/useRealArticles.tsx
-edited src/components/CategoryFilter.tsx
gpt-engineer-app[bot] 3 miesięcy temu
rodzic
commit
546858be98

+ 11 - 2
src/components/CategoryFilter.tsx

@@ -155,8 +155,8 @@ const CategoryFilter = ({
               </div>
             )}
 
-            {/* Section 2: Filtres de date */}
-            {onDateFilterChange && (
+            {/* Section 2: Filtres de date - Only show for followed feeds */}
+            {onDateFilterChange && showFollowedOnly && (
               <div className="flex flex-col gap-2 min-w-fit">
                 <div className="flex items-center gap-2 mb-1">
                   <Calendar className="h-4 w-4 text-muted-foreground" />
@@ -193,6 +193,15 @@ const CategoryFilter = ({
               </div>
             )}
 
+            {/* Info message when in "All articles" mode */}
+            {!showFollowedOnly && user && (
+              <div className="flex flex-col gap-2 min-w-fit">
+                <div className="text-xs text-muted-foreground bg-muted/50 p-2 rounded-md">
+                  Mode "Tous les flux" : affiche tous les articles sans filtre de date
+                </div>
+              </div>
+            )}
+
             {/* Section 3: Compteur d'épinglés */}
             {user && (
               <div className="flex flex-col gap-2 min-w-fit">

+ 2 - 5
src/hooks/useRealArticles.tsx

@@ -164,7 +164,7 @@ export function useRealArticles(dateFilter?: 'today' | 'yesterday' | null, showF
           }
         }
 
-        // Fetch regular articles (with date filter if specified)
+        // Fetch regular articles (NO date filter for "All articles" mode)
         let regularQuery = supabase
           .from('articles')
           .select(`
@@ -173,10 +173,7 @@ export function useRealArticles(dateFilter?: 'today' | 'yesterday' | null, showF
             user_articles(is_read, is_pinned)
           `);
         
-        // Apply date filter to regular articles only
-        if (dateStart && dateEnd) {
-          regularQuery = regularQuery.gte('published_at', dateStart).lte('published_at', dateEnd);
-        }
+        // Don't apply date filter in "All articles" mode - show everything
         
         const { data: regularData, error: regularError } = await regularQuery
           .order('published_at', { ascending: false })

+ 11 - 2
src/pages/Index.tsx

@@ -23,6 +23,15 @@ const Index = () => {
   const [dateFilter, setDateFilter] = useState<'today' | 'yesterday' | null>(null);
   const [showFollowedOnly, setShowFollowedOnly] = useState(false);
   const [showReadArticles, setShowReadArticles] = useState(false);
+
+  // Reset date filter when switching to "All articles" mode
+  const handleShowFollowedOnlyChange = (value: boolean) => {
+    setShowFollowedOnly(value);
+    if (!value) {
+      // When switching to "All articles", reset date filter
+      setDateFilter(null);
+    }
+  };
   const {
     articles,
     loading,
@@ -134,7 +143,7 @@ const Index = () => {
                           dateFilter={dateFilter}
                           onDateFilterChange={setDateFilter}
                           showFollowedOnly={showFollowedOnly}
-                          onShowFollowedOnlyChange={setShowFollowedOnly}
+                          onShowFollowedOnlyChange={handleShowFollowedOnlyChange}
                           showReadArticles={showReadArticles}
                           onShowReadArticlesChange={setShowReadArticles}
               />
@@ -191,7 +200,7 @@ const Index = () => {
                           dateFilter={dateFilter}
                           onDateFilterChange={setDateFilter}
                           showFollowedOnly={showFollowedOnly}
-                          onShowFollowedOnlyChange={setShowFollowedOnly}
+                          onShowFollowedOnlyChange={handleShowFollowedOnlyChange}
                           showReadArticles={showReadArticles}
                           onShowReadArticlesChange={setShowReadArticles}
                         />