2023-04-23 08:26:39 -05:00
// Copyright (C) 2022-present Daniel31x13 <daniel31x13@gmail.com>
// This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3.
// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
2023-03-22 18:11:54 -05:00
import useCollectionStore from "@/store/collections" ;
2023-02-18 21:32:02 -06:00
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" ;
import {
2023-02-24 11:32:28 -06:00
faFolder ,
2023-03-05 15:03:20 -06:00
faBox ,
2023-03-10 13:25:33 -06:00
faHashtag ,
2023-02-24 22:22:33 -06:00
faBookmark ,
2023-05-14 10:41:08 -05:00
faChartSimple ,
2023-02-18 21:32:02 -06:00
} from "@fortawesome/free-solid-svg-icons" ;
2023-02-24 11:32:28 -06:00
import SidebarItem from "./SidebarItem" ;
2023-03-22 18:11:54 -05:00
import useTagStore from "@/store/tags" ;
2023-03-05 15:03:20 -06:00
import Link from "next/link" ;
2023-05-01 05:07:01 -05:00
import { useRouter } from "next/router" ;
import { useEffect , useState } from "react" ;
2023-02-08 17:58:55 -06:00
2023-05-15 13:29:51 -05:00
export default function ( { className } : { className? : string } ) {
2023-04-24 16:30:40 -05:00
const { collections } = useCollectionStore ( ) ;
2023-03-22 18:11:54 -05:00
const { tags } = useTagStore ( ) ;
2023-02-24 11:32:28 -06:00
2023-05-01 05:07:01 -05:00
const router = useRouter ( ) ;
const [ active , setActive ] = useState ( "" ) ;
useEffect ( ( ) = > {
setActive ( router . asPath ) ;
} , [ router ] ) ;
2023-02-08 17:58:55 -06:00
return (
2023-05-15 13:29:51 -05:00
< div
className = { ` bg-gray-100 h-screen w-64 xl:w-80 p-2 overflow-y-auto border-solid border-r-sky-100 border z-20 ${ className } ` }
>
2023-03-28 02:31:50 -05:00
< p className = "p-2 text-sky-500 font-bold text-xl mb-5 leading-4" >
Linkwarden
< / p >
2023-02-18 21:32:02 -06:00
2023-05-14 10:41:08 -05:00
< Link href = "/dashboard" >
< div
className = { ` ${
active === "/dashboard"
? "bg-sky-500"
: "hover:bg-gray-50 hover:outline bg-gray-100"
} outline - sky - 100 outline - 1 duration - 100 rounded - md my - 1 p - 2 cursor - pointer flex items - center gap - 2 ` }
>
< FontAwesomeIcon
icon = { faChartSimple }
className = { ` w-4 ${
active === "/dashboard" ? "text-white" : "text-sky-300"
} ` }
/ >
< p
className = { ` ${
active === "/dashboard" ? "text-white" : "text-sky-900"
} ` }
>
Dashboard
< / p >
< / div >
< / Link >
2023-03-28 02:31:50 -05:00
< Link href = "/links" >
2023-05-01 05:07:01 -05:00
< div
className = { ` ${
active === "/links"
? "bg-sky-500"
: "hover:bg-gray-50 hover:outline bg-gray-100"
} outline - sky - 100 outline - 1 duration - 100 rounded - md my - 1 p - 2 cursor - pointer flex items - center gap - 2 ` }
>
< FontAwesomeIcon
icon = { faBookmark }
className = { ` w-4 ${
active === "/links" ? "text-white" : "text-sky-300"
} ` }
/ >
< p
className = { ` ${ active === "/links" ? "text-white" : "text-sky-900" } ` }
>
All Links
< / p >
2023-03-05 15:03:20 -06:00
< / div >
< / Link >
2023-02-24 22:22:33 -06:00
2023-03-05 15:03:20 -06:00
< Link href = "/collections" >
2023-05-01 05:07:01 -05:00
< div
className = { ` ${
active === "/collections"
? "bg-sky-500"
: "hover:bg-gray-50 hover:outline bg-gray-100"
} outline - sky - 100 outline - 1 duration - 100 rounded - md my - 1 p - 2 cursor - pointer flex items - center gap - 2 ` }
>
< FontAwesomeIcon
icon = { faBox }
className = { ` w-4 ${
active === "/collections" ? "text-white" : "text-sky-300"
} ` }
/ >
< p
className = { ` ${
active === "/collections" ? "text-white" : "text-sky-900"
} ` }
>
All Collections
< / p >
2023-03-05 15:03:20 -06:00
< / div >
< / Link >
2023-02-13 15:22:47 -06:00
2023-04-24 16:30:40 -05:00
< div className = "text-gray-500 mt-5" >
2023-03-25 09:17:34 -05:00
< p className = "text-sm p-2" > Collections < / p >
2023-02-13 15:22:47 -06:00
< / div >
2023-02-18 21:32:02 -06:00
< div >
2023-05-25 13:44:08 -05:00
{ collections
. sort ( ( a , b ) = > a . name . localeCompare ( b . name ) )
. map ( ( e , i ) = > {
return (
< SidebarItem
key = { i }
text = { e . name }
icon = { < FontAwesomeIcon icon = { faFolder } / > }
path = { ` /collections/ ${ e . id } ` }
className = "capitalize"
/ >
) ;
} ) }
2023-02-24 11:32:28 -06:00
< / div >
2023-04-24 16:30:40 -05:00
< div className = "text-gray-500 mt-5" >
2023-03-25 09:17:34 -05:00
< p className = "text-sm p-2" > Tags < / p >
2023-02-24 11:32:28 -06:00
< / div >
< div >
2023-05-25 21:21:35 -05:00
{ tags
. sort ( ( a , b ) = > a . name . localeCompare ( b . name ) )
. map ( ( e , i ) = > {
return (
< SidebarItem
key = { i }
text = { e . name }
icon = { < FontAwesomeIcon icon = { faHashtag } / > }
path = { ` /tags/ ${ e . id } ` }
/ >
) ;
} ) }
2023-02-18 21:32:02 -06:00
< / div >
2023-02-08 17:58:55 -06:00
< / div >
) ;
}