feat: added unread category 3d46baa8
Steve · 2025-11-05 14:39 2 file(s) · +38 −13
src/components/app-sidebar.tsx +28 −13
65 65
	// Get posts based on selected feed
66 66
	const allPosts = useQuery(allPostsQuery);
67 67
	const feedPostsQuery = useQuery(postsByFeedQuery(selectedFeedId || ""));
68 -
	const feedPosts = selectedFeedId ? feedPostsQuery : allPosts;
68 +
69 +
	// Check if a post is read
70 +
	const isPostRead = React.useCallback(
71 +
		(postId: string) => {
72 +
			return allReadStatuses.some((status) => status.postId === postId);
73 +
		},
74 +
		[allReadStatuses],
75 +
	);
76 +
77 +
	// Determine which posts to show based on selection
78 +
	const feedPosts = React.useMemo(() => {
79 +
		if (selectedFeedId === "unread") {
80 +
			// Show only unread posts from all feeds
81 +
			return allPosts.filter((post) => !isPostRead(post.id));
82 +
		} else if (selectedFeedId) {
83 +
			// Show posts from specific feed
84 +
			return feedPostsQuery;
85 +
		} else {
86 +
			// Show all posts
87 +
			return allPosts;
88 +
		}
89 +
	}, [selectedFeedId, allPosts, feedPostsQuery, isPostRead]);
69 90
70 91
	// Filter and sort posts by search query and date
71 92
	const filteredPosts = React.useMemo(() => {
84 105
			return b.publishedDate.localeCompare(a.publishedDate);
85 106
		});
86 107
	}, [feedPosts, searchQuery]);
87 -
88 -
	// Check if a post is read
89 -
	const isPostRead = React.useCallback(
90 -
		(postId: string) => {
91 -
			return allReadStatuses.some((status) => status.postId === postId);
92 -
		},
93 -
		[allReadStatuses],
94 -
	);
95 108
96 109
	// Handle feed selection - on mobile, navigate to posts view
97 110
	const handleFeedSelect = React.useCallback(
351 364
		// eslint-disable-next-line react-hooks/exhaustive-deps
352 365
	}, []); // Only run once on mount
353 366
354 -
	const selectedFeed = selectedFeedId
355 -
		? allFeeds.find((f) => f.id === selectedFeedId)
356 -
		: null;
357 -
	const selectedFeedTitle = selectedFeed?.title || "All Posts";
367 +
	const selectedFeed =
368 +
		selectedFeedId && selectedFeedId !== "unread"
369 +
			? allFeeds.find((f) => f.id === selectedFeedId)
370 +
			: null;
371 +
	const selectedFeedTitle =
372 +
		selectedFeedId === "unread" ? "Unread" : selectedFeed?.title || "All Posts";
358 373
	const selectedFeedCategory = selectedFeed?.category || null;
359 374
360 375
	return (
src/components/nav-feeds.tsx +10 −0
69 69
					</SidebarMenuButton>
70 70
				</SidebarMenuItem>
71 71
72 +
				{/* Unread option */}
73 +
				<SidebarMenuItem>
74 +
					<SidebarMenuButton
75 +
						onClick={() => onFeedSelect("unread")}
76 +
						isActive={selectedFeedId === "unread"}
77 +
					>
78 +
						Unread
79 +
					</SidebarMenuButton>
80 +
				</SidebarMenuItem>
81 +
72 82
				{/* Categories with feeds */}
73 83
				{categories.map((category) => (
74 84
					<Collapsible