import { useStore } from "@nanostores/react"; import { clsx } from "clsx"; import { Bookmark, Highlighter, MessageSquareText } from "lucide-react"; import { useState } from "react"; import { useSearchParams } from "react-router-dom"; import FeedItems from "../../components/feed/FeedItems"; import { Button, Tabs } from "../../components/ui"; import LayoutToggle from "../../components/ui/LayoutToggle"; import { $user } from "../../store/auth"; import { $feedLayout } from "../../store/feedLayout"; interface FeedProps { initialType?: string; motivation?: string; showTabs?: boolean; emptyMessage?: string; } export default function Feed({ initialType = "all", motivation, showTabs = true, emptyMessage = "No items found.", }: FeedProps) { const [searchParams, setSearchParams] = useSearchParams(); const tag = searchParams.get("tag") || undefined; const user = useStore($user); const layout = useStore($feedLayout); const [activeTab, setActiveTab] = useState(initialType); const [activeFilter, setActiveFilter] = useState( motivation, ); const handleTabChange = (id: string) => { if (id === activeTab) return; setActiveTab(id); setSearchParams((prev) => { const newParams = new URLSearchParams(prev); newParams.delete("tag"); return newParams; }); window.scrollTo({ top: 0, behavior: "smooth" }); }; const handleFilterChange = (id: string) => { const next = id === "all" ? undefined : id; if (next === activeFilter) return; setActiveFilter(next); setSearchParams((prev) => { const newParams = new URLSearchParams(prev); newParams.delete("tag"); return newParams; }); window.scrollTo({ top: 0, behavior: "smooth" }); }; const tabs = [ { id: "all", label: "Recent" }, { id: "popular", label: "Popular" }, { id: "shelved", label: "Shelved" }, { id: "margin", label: "Margin" }, { id: "semble", label: "Semble" }, ]; const filters = [ { id: "all", label: "All", icon: null }, { id: "commenting", label: "Annotations", icon: MessageSquareText }, { id: "highlighting", label: "Highlights", icon: Highlighter }, { id: "bookmarking", label: "Bookmarks", icon: Bookmark }, ]; return (
{!user && (

Welcome to Margin

Annotate, highlight, and bookmark anything on the web.

)} {showTabs && (
{!tag && ( )} {tag && (

Items with tag: #{tag}

)}
{filters.map((f) => { const isActive = f.id === "all" ? !activeFilter : activeFilter === f.id; return ( ); })}
)}
); }