Skip to content

Commit

Permalink
🚀 feat: refactor sidebar and bookmarks components, remove unused Them…
Browse files Browse the repository at this point in the history
…eToggle and nav-main
  • Loading branch information
vaayne committed Dec 26, 2024
1 parent a6ab2a2 commit 9e2f0d3
Show file tree
Hide file tree
Showing 7 changed files with 202 additions and 191 deletions.
37 changes: 0 additions & 37 deletions web/src/components/ThemeToggle.tsx

This file was deleted.

13 changes: 3 additions & 10 deletions web/src/components/bookmarks-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
CardTitle,
} from "@/components/ui/card";
import type { Bookmark } from "@/lib/apis/bookmarks";
import { ExternalLink, Highlighter } from "lucide-react";
import { ROUTES } from "@/lib/router";
import { Highlighter } from "lucide-react";
import { Link } from "react-router-dom";

interface BookmarkListProps {
Expand All @@ -22,7 +23,7 @@ export default function BookmarkList({ bookmarks }: BookmarkListProps) {
key={bookmark.id}
className="overflow-hidden transition-transform transform hover:-translate-y-1 mx-2"
>
<Link to={`/bookmarks/${bookmark.id}`} className="block">
<Link to={`${ROUTES.BOOKMARKS}/${bookmark.id}`} className="block">
{bookmark.metadata?.image && (
<img
src={bookmark.metadata.image}
Expand All @@ -38,14 +39,6 @@ export default function BookmarkList({ bookmarks }: BookmarkListProps) {
<Highlighter className="h-4 w-4 text-yellow-500" />
) : null}
</span>
<a
href={bookmark.url}
target="_blank"
rel="noopener noreferrer"
onClick={(e) => e.stopPropagation()}
>
<ExternalLink className="h-4 w-4 text-blue-500" />
</a>
</CardTitle>
<CardDescription className="truncate">
{bookmark.url}
Expand Down
107 changes: 0 additions & 107 deletions web/src/components/nav-main.tsx

This file was deleted.

159 changes: 159 additions & 0 deletions web/src/components/sidebar-content.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import { useTheme } from "@/components/theme-provider";
import {
Collapsible,
CollapsibleContent,
CollapsibleTrigger,
} from "@/components/ui/collapsible";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import {
SidebarContent,
SidebarGroup,
SidebarMenu,
SidebarMenuButton,
SidebarMenuItem,
SidebarMenuSub,
SidebarMenuSubButton,
SidebarMenuSubItem,
} from "@/components/ui/sidebar";
import { ROUTES } from "@/lib/router";
import {
BookImage,
BookOpen,
Bookmark,
ChevronRight,
Moon,
Newspaper,
Settings2,
Sun,
} from "lucide-react";
import { Link } from "react-router-dom";

const items = [
{
title: "Bookmarks",
url: "#bookmark",
icon: Bookmark,
isActive: true,
items: [
{
title: "Articles",
icon: Newspaper,
url: `${ROUTES.BOOKMARKS}?type=bookmark&category=article`,
},
{
title: "EPUBs",
icon: BookOpen,
url: `${ROUTES.BOOKMARKS}?type=bookmark&category=epub`,
},
{
title: "PDFs",
icon: BookImage,
url: `${ROUTES.BOOKMARKS}?type=bookmark&category=pdf`,
},
// {
// title: "Videos",
// url: `${ROUTES.BOOKMARKS}?type=bookmark&category=video`,
// },
// {
// title: "Podcasts",
// url: `${ROUTES.BOOKMARKS}?type=bookmark&category=podcast`,
// },
],
},
// {
// title: "Subscriptions",
// url: `${ROUTES.BOOKMARKS}?type=feed`,
// icon: Rss,
// items: [],
// }
];

function ThemeToggle() {
const { setTheme } = useTheme();
return (
<SidebarMenuItem key="theme-toggle">
<DropdownMenu>
<DropdownMenuTrigger asChild>
<SidebarMenuButton>
<Sun className="h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0" />
<Moon className="absolute h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100" />
<span>Theme</span>
</SidebarMenuButton>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem onClick={() => setTheme("light")}>
Light
</DropdownMenuItem>
<DropdownMenuItem onClick={() => setTheme("dark")}>
Dark
</DropdownMenuItem>
<DropdownMenuItem onClick={() => setTheme("system")}>
System
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</SidebarMenuItem>
);
}

export function NavContent() {
return (
<SidebarContent>
<SidebarGroup>
{/* <SidebarGroupLabel>Platform</SidebarGroupLabel> */}
<SidebarMenu>
{items.map((item) => (
<Collapsible
key={item.title}
asChild
defaultOpen={item.isActive}
className="group/collapsible"
>
<SidebarMenuItem>
<CollapsibleTrigger asChild>
<SidebarMenuButton tooltip={item.title}>
{item.icon && <item.icon />}
<span>{item.title}</span>
<ChevronRight className="ml-auto transition-transform duration-200 group-data-[state=open]/collapsible:rotate-90" />
</SidebarMenuButton>
</CollapsibleTrigger>
<CollapsibleContent>
<SidebarMenuSub>
{item.items?.map((subItem) => (
<SidebarMenuSubItem key={subItem.title}>
<SidebarMenuSubButton asChild>
<Link to={subItem.url}>
{subItem.icon && <subItem.icon />}
<span>{subItem.title}</span>
</Link>
</SidebarMenuSubButton>
</SidebarMenuSubItem>
))}
</SidebarMenuSub>
</CollapsibleContent>
</SidebarMenuItem>
</Collapsible>
))}
</SidebarMenu>
</SidebarGroup>
<SidebarGroup className="mt-auto">
<SidebarMenu>
<SidebarMenuItem key="preferences">
<SidebarMenuButton asChild>
<Link to={ROUTES.SETTINGS}>
<Settings2 />
<span>Preferences</span>
</Link>
</SidebarMenuButton>
</SidebarMenuItem>
<ThemeToggle />
</SidebarMenu>
</SidebarGroup>
</SidebarContent>
);
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { BookmarkIcon } from "lucide-react";
import type * as React from "react";

import { NavMain } from "@/components/nav-main";
import { NavUser } from "@/components/nav-user";
import { NavContent } from "@/components/sidebar-content";
import { NavUser } from "@/components/sidebar-nav-user";
import {
Sidebar,
SidebarContent,
SidebarFooter,
SidebarHeader,
SidebarMenu,
Expand All @@ -14,6 +12,8 @@ import {
SidebarRail,
} from "@/components/ui/sidebar";
import { ROUTES } from "@/lib/router";
import { Bookmark } from "lucide-react";
import { Link } from "react-router-dom";

export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
return (
Expand All @@ -22,21 +22,19 @@ export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
<SidebarMenu>
<SidebarMenuItem>
<SidebarMenuButton size="lg" asChild>
<a href={ROUTES.BOOKMARKS} className="flex items-center gap-2">
<Link to={ROUTES.HOME}>
<div className="flex aspect-square size-8 items-center justify-center rounded-lg bg-sidebar-primary text-sidebar-primary-foreground">
<BookmarkIcon className="size-4" />
<Bookmark className="size-4" />
</div>
<div className="flex flex-col gap-0.5 leading-none">
<span className="font-semibold">Vibrain</span>
</div>
</a>
</Link>
</SidebarMenuButton>
</SidebarMenuItem>
</SidebarMenu>
</SidebarHeader>
<SidebarContent>
<NavMain />
</SidebarContent>
<NavContent />
<SidebarFooter>
<NavUser />
</SidebarFooter>
Expand Down
Loading

0 comments on commit 9e2f0d3

Please sign in to comment.