chore: added remove category
cfcb9460
2 file(s) · +51 −4
| 256 | 256 | onFeedSelect(null); |
|
| 257 | 257 | }, [selectedFeedId, allFeeds, allPosts, onFeedSelect]); |
|
| 258 | 258 | ||
| 259 | + | // Delete category (uncategorize all feeds in the category) |
|
| 260 | + | const handleDeleteCategory = React.useCallback(() => { |
|
| 261 | + | const selectedFeed = allFeeds.find((f) => f.id === selectedFeedId); |
|
| 262 | + | if (!selectedFeed || !selectedFeed.category) return; |
|
| 263 | + | ||
| 264 | + | const categoryToDelete = selectedFeed.category; |
|
| 265 | + | ||
| 266 | + | // Find all feeds in this category |
|
| 267 | + | const feedsInCategory = allFeeds.filter( |
|
| 268 | + | (f) => f.category === categoryToDelete, |
|
| 269 | + | ); |
|
| 270 | + | ||
| 271 | + | // Set category to null for all feeds in this category |
|
| 272 | + | feedsInCategory.forEach((feed) => { |
|
| 273 | + | evoluInstance.update("rssFeed", { |
|
| 274 | + | id: feed.id as any, |
|
| 275 | + | category: null, |
|
| 276 | + | }); |
|
| 277 | + | }); |
|
| 278 | + | ||
| 279 | + | toast.success( |
|
| 280 | + | `Removed category "${categoryToDelete}" from ${feedsInCategory.length} feed${feedsInCategory.length !== 1 ? "s" : ""}`, |
|
| 281 | + | ); |
|
| 282 | + | ||
| 283 | + | // Navigate back to all feeds |
|
| 284 | + | onFeedSelect(null); |
|
| 285 | + | }, [selectedFeedId, allFeeds, onFeedSelect]); |
|
| 286 | + | ||
| 259 | 287 | const refreshFeeds = React.useCallback(async () => { |
|
| 260 | 288 | if (allFeeds.length === 0) { |
|
| 261 | 289 | toast.error("No feeds to refresh"); |
|
| 335 | 363 | // eslint-disable-next-line react-hooks/exhaustive-deps |
|
| 336 | 364 | }, []); // Only run once on mount |
|
| 337 | 365 | ||
| 338 | - | const selectedFeedTitle = selectedFeedId |
|
| 339 | - | ? allFeeds.find((f) => f.id === selectedFeedId)?.title || "Posts" |
|
| 340 | - | : "All Posts"; |
|
| 366 | + | const selectedFeed = selectedFeedId |
|
| 367 | + | ? allFeeds.find((f) => f.id === selectedFeedId) |
|
| 368 | + | : null; |
|
| 369 | + | const selectedFeedTitle = selectedFeed?.title || "All Posts"; |
|
| 370 | + | const selectedFeedCategory = selectedFeed?.category || null; |
|
| 341 | 371 | ||
| 342 | 372 | return ( |
|
| 343 | 373 | <> |
|
| 377 | 407 | onMarkAllAsRead={handleMarkAllAsRead} |
|
| 378 | 408 | onMarkAllAsUnread={handleMarkAllAsUnread} |
|
| 379 | 409 | onDeleteFeed={handleDeleteFeed} |
|
| 410 | + | onDeleteCategory={handleDeleteCategory} |
|
| 380 | 411 | selectedFeedId={selectedFeedId} |
|
| 412 | + | selectedFeedCategory={selectedFeedCategory} |
|
| 381 | 413 | className="border-0" |
|
| 382 | 414 | /> |
|
| 383 | 415 | </div> |
|
| 416 | 448 | onMarkAllAsRead={handleMarkAllAsRead} |
|
| 417 | 449 | onMarkAllAsUnread={handleMarkAllAsUnread} |
|
| 418 | 450 | onDeleteFeed={handleDeleteFeed} |
|
| 451 | + | onDeleteCategory={handleDeleteCategory} |
|
| 419 | 452 | selectedFeedId={selectedFeedId} |
|
| 453 | + | selectedFeedCategory={selectedFeedCategory} |
|
| 420 | 454 | className={`bg-sidebar text-sidebar-foreground hidden md:flex ${hidden ? "w-0 min-w-0 border-0 overflow-hidden" : "w-[320px] overflow-y-auto"}`} |
|
| 421 | 455 | /> |
|
| 422 | 456 | </> |
|
| 1 | - | import { MoreVertical, Check, X, Trash2 } from "lucide-react"; |
|
| 1 | + | import { MoreVertical, Check, X, Trash2, FolderX } from "lucide-react"; |
|
| 2 | 2 | import { Button } from "@/components/ui/button"; |
|
| 3 | 3 | import { |
|
| 4 | 4 | DropdownMenu, |
|
| 29 | 29 | onMarkAllAsRead: () => void; |
|
| 30 | 30 | onMarkAllAsUnread: () => void; |
|
| 31 | 31 | onDeleteFeed?: () => void; |
|
| 32 | + | onDeleteCategory?: () => void; |
|
| 32 | 33 | selectedFeedId?: string | null; |
|
| 34 | + | selectedFeedCategory?: string | null; |
|
| 33 | 35 | className?: string; |
|
| 34 | 36 | } |
|
| 35 | 37 | ||
| 44 | 46 | onMarkAllAsRead, |
|
| 45 | 47 | onMarkAllAsUnread, |
|
| 46 | 48 | onDeleteFeed, |
|
| 49 | + | onDeleteCategory, |
|
| 47 | 50 | selectedFeedId, |
|
| 51 | + | selectedFeedCategory, |
|
| 48 | 52 | className = "", |
|
| 49 | 53 | }: PostsListProps) { |
|
| 50 | 54 | return ( |
|
| 80 | 84 | > |
|
| 81 | 85 | <Trash2 className="h-4 w-4 mr-2" /> |
|
| 82 | 86 | Delete feed |
|
| 87 | + | </DropdownMenuItem> |
|
| 88 | + | )} |
|
| 89 | + | {selectedFeedCategory && onDeleteCategory && ( |
|
| 90 | + | <DropdownMenuItem |
|
| 91 | + | onClick={onDeleteCategory} |
|
| 92 | + | className="text-destructive focus:text-destructive" |
|
| 93 | + | > |
|
| 94 | + | <FolderX className="h-4 w-4 mr-2" /> |
|
| 95 | + | Delete category |
|
| 83 | 96 | </DropdownMenuItem> |
|
| 84 | 97 | )} |
|
| 85 | 98 | </DropdownMenuContent> |
|