浏览代码

Fix: Display recent articles for visitors

Show the 20 most recent articles on the home page for users who are not logged in.
gpt-engineer-app[bot] 5 月之前
父节点
当前提交
1ff7648a46
共有 1 个文件被更改,包括 20 次插入17 次删除
  1. 20 17
      src/hooks/useRealArticles.tsx

+ 20 - 17
src/hooks/useRealArticles.tsx

@@ -116,10 +116,11 @@ export function useRealArticles() {
           .from('articles')
           .select(`
             *,
-            feeds!inner(name, category)
+            feeds(name, category)
           `)
+          .not('feeds', 'is', null)
           .order('published_at', { ascending: false })
-          .limit(50);
+          .limit(20);
 
         if (articlesError) {
           console.error('❌ Error fetching public articles:', articlesError);
@@ -129,21 +130,23 @@ export function useRealArticles() {
 
         console.log('📰 Public articles found:', articlesData?.length);
 
-        // Transform to NewsItem format
-        const transformedArticles: NewsItem[] = articlesData?.map(article => ({
-          id: article.id,
-          title: article.title,
-          description: article.description || '',
-          content: article.content || '',
-          source: article.feeds.name,
-          category: article.feeds.category as NewsItem['category'],
-          publishedAt: article.published_at,
-          readTime: article.read_time || 5,
-          isPinned: false,
-          isRead: false,
-          url: article.url || undefined,
-          imageUrl: article.image_url || undefined
-        })) || [];
+        // Transform to NewsItem format - filter out articles without feeds
+        const transformedArticles: NewsItem[] = articlesData
+          ?.filter(article => article.feeds) // Only keep articles with valid feeds
+          ?.map(article => ({
+            id: article.id,
+            title: article.title,
+            description: article.description || '',
+            content: article.content || '',
+            source: article.feeds.name,
+            category: article.feeds.category as NewsItem['category'],
+            publishedAt: article.published_at,
+            readTime: article.read_time || 5,
+            isPinned: false,
+            isRead: false,
+            url: article.url || undefined,
+            imageUrl: article.image_url || undefined
+          })) || [];
 
         setArticles(transformedArticles);
       }