Skip to content

Commit

Permalink
🚀 feat: refactor sidebar components and implement theme toggle functi…
Browse files Browse the repository at this point in the history
…onality
  • Loading branch information
vaayne committed Dec 26, 2024
1 parent d731c21 commit 55de5a0
Show file tree
Hide file tree
Showing 9 changed files with 361 additions and 172 deletions.
104 changes: 104 additions & 0 deletions web/src/components/bookmark-sidebar-content.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import {
Collapsible,
CollapsibleContent,
CollapsibleTrigger,
} from "@/components/ui/collapsible";
import {
SidebarGroup,
SidebarMenu,
SidebarMenuButton,
SidebarMenuItem,
SidebarMenuSub,
SidebarMenuSubButton,
SidebarMenuSubItem,
} from "@/components/ui/sidebar";
import { ROUTES } from "@/lib/router";
import {
BookImage,
BookOpen,
Bookmark,
ChevronRight,
Newspaper,
} 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: [],
// }
];

export function BookmarkSidebarContent() {
return (
<SidebarGroup>
<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>
);
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
import type * as React from "react";

import { NavContent } from "@/components/sidebar-content";
import { NavUser } from "@/components/sidebar-nav-user";
import {
Sidebar,
SidebarContent,
SidebarFooter,
SidebarGroup,
SidebarHeader,
SidebarMenu,
SidebarMenuButton,
SidebarMenuItem,
SidebarRail,
} from "@/components/ui/sidebar";
import { ROUTES } from "@/lib/router";
import { Bookmark } from "lucide-react";
import { Bookmark, Settings2 } from "lucide-react";
import { Link } from "react-router-dom";
import { BookmarkSidebarContent } from "./bookmark-sidebar-content";
import ThemeToggle from "./theme-toggle";

export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
export function BookmarkSidebar({
...props
}: React.ComponentProps<typeof Sidebar>) {
return (
<Sidebar collapsible="icon" {...props}>
<SidebarHeader>
Expand All @@ -34,7 +39,22 @@ export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
</SidebarMenuItem>
</SidebarMenu>
</SidebarHeader>
<NavContent />
<SidebarContent>
<BookmarkSidebarContent />
<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>
<SidebarFooter>
<NavUser />
</SidebarFooter>
Expand Down
104 changes: 104 additions & 0 deletions web/src/components/bookmarks-sidebar-content.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import {
Collapsible,
CollapsibleContent,
CollapsibleTrigger,
} from "@/components/ui/collapsible";
import {
SidebarGroup,
SidebarMenu,
SidebarMenuButton,
SidebarMenuItem,
SidebarMenuSub,
SidebarMenuSubButton,
SidebarMenuSubItem,
} from "@/components/ui/sidebar";
import { ROUTES } from "@/lib/router";
import {
BookImage,
BookOpen,
Bookmark,
ChevronRight,
Newspaper,
} 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: [],
// }
];

export function BookmarksSidebarContent() {
return (
<SidebarGroup>
<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>
);
}
64 changes: 64 additions & 0 deletions web/src/components/bookmarks-sidebar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import type * as React from "react";

import { NavUser } from "@/components/sidebar-nav-user";
import {
Sidebar,
SidebarContent,
SidebarFooter,
SidebarGroup,
SidebarHeader,
SidebarMenu,
SidebarMenuButton,
SidebarMenuItem,
SidebarRail,
} from "@/components/ui/sidebar";
import { ROUTES } from "@/lib/router";
import { Bookmark, Settings2 } from "lucide-react";
import { Link } from "react-router-dom";
import { BookmarksSidebarContent } from "./bookmarks-sidebar-content";
import ThemeToggle from "./theme-toggle";

export function BookmarksSidebar({
...props
}: React.ComponentProps<typeof Sidebar>) {
return (
<Sidebar collapsible="icon" {...props}>
<SidebarHeader>
<SidebarMenu>
<SidebarMenuItem>
<SidebarMenuButton size="lg" asChild>
<Link to={ROUTES.HOME}>
<div className="flex aspect-square size-8 items-center justify-center rounded-lg bg-sidebar-primary text-sidebar-primary-foreground">
<Bookmark className="size-4" />
</div>
<div className="flex flex-col gap-0.5 leading-none">
<span className="font-semibold">Vibrain</span>
</div>
</Link>
</SidebarMenuButton>
</SidebarMenuItem>
</SidebarMenu>
</SidebarHeader>
<SidebarContent>
<BookmarksSidebarContent />
<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>
<SidebarFooter>
<NavUser />
</SidebarFooter>
<SidebarRail />
</Sidebar>
);
}
5 changes: 1 addition & 4 deletions web/src/components/content-reader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,7 @@ export const ArticleReader: React.FC<ArticleReaderProps> = ({ bookmark }) => {
};

return (
<div className="container mx-auto px-4 py-8 max-w-screen-lg">
{/* <Card className="p-4 shadow-lg"> */}
{/* <h1 className="text-3xl font-bold mb-4">{title}</h1> */}

<div className="container mx-auto px-4 py-8 ">
<ArticleHeader
title={bookmark.title ?? "Title"}
url={bookmark.url}
Expand Down
Loading

0 comments on commit 55de5a0

Please sign in to comment.