2023-02-08 17:58:55 -06:00
|
|
|
import { useSession } from "next-auth/react";
|
2023-02-13 15:22:47 -06:00
|
|
|
import ClickAwayHandler from "@/components/ClickAwayHandler";
|
|
|
|
import { useState } from "react";
|
2023-03-22 18:11:54 -05:00
|
|
|
import useCollectionStore from "@/store/collections";
|
|
|
|
import { signOut } from "next-auth/react";
|
2023-02-18 21:32:02 -06:00
|
|
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
|
|
import {
|
|
|
|
faPlus,
|
|
|
|
faChevronDown,
|
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-03-22 18:11:54 -05:00
|
|
|
faCircleUser,
|
|
|
|
faSliders,
|
|
|
|
faArrowRightFromBracket,
|
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-03-22 18:11:54 -05:00
|
|
|
import Dropdown from "@/components/Dropdown";
|
2023-02-08 17:58:55 -06:00
|
|
|
|
2023-02-24 11:32:28 -06:00
|
|
|
export default function () {
|
2023-02-18 21:32:02 -06:00
|
|
|
const { data: session } = useSession();
|
2023-02-08 17:58:55 -06:00
|
|
|
|
2023-02-18 21:32:02 -06:00
|
|
|
const [collectionInput, setCollectionInput] = useState(false);
|
2023-03-22 18:11:54 -05:00
|
|
|
const [profileDropdown, setProfileDropdown] = useState(false);
|
2023-02-18 21:32:02 -06:00
|
|
|
|
2023-03-22 18:11:54 -05:00
|
|
|
const { collections, addCollection } = useCollectionStore();
|
2023-02-13 15:22:47 -06:00
|
|
|
|
2023-03-22 18:11:54 -05:00
|
|
|
const { tags } = useTagStore();
|
2023-02-24 11:32:28 -06:00
|
|
|
|
2023-02-08 17:58:55 -06:00
|
|
|
const user = session?.user;
|
|
|
|
|
2023-02-18 21:32:02 -06:00
|
|
|
const toggleCollectionInput = () => {
|
|
|
|
setCollectionInput(!collectionInput);
|
2023-02-13 15:22:47 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
const submitCollection = async (
|
|
|
|
event: React.KeyboardEvent<HTMLInputElement>
|
|
|
|
) => {
|
|
|
|
const collectionName: string = (event.target as HTMLInputElement).value;
|
|
|
|
|
|
|
|
if (event.key === "Enter" && collectionName) {
|
2023-02-18 21:32:02 -06:00
|
|
|
addCollection(collectionName);
|
|
|
|
(event.target as HTMLInputElement).value = "";
|
2023-02-13 15:22:47 -06:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-02-08 17:58:55 -06:00
|
|
|
return (
|
2023-03-25 09:17:34 -05:00
|
|
|
<div className="fixed bg-gray-100 top-0 bottom-0 left-0 w-80 p-2 overflow-y-auto hide-scrollbar border-solid border-r-sky-100 border z-10">
|
2023-03-22 22:06:15 -05:00
|
|
|
<div className="relative w-fit">
|
2023-03-22 18:11:54 -05:00
|
|
|
<div
|
2023-03-25 09:17:34 -05:00
|
|
|
className="flex gap-2 items-center mb-5 p-2 w-fit text-gray-600 cursor-pointer hover:outline outline-sky-100 outline-1 hover:bg-gray-50 rounded-md duration-100"
|
2023-03-22 18:11:54 -05:00
|
|
|
onClick={() => setProfileDropdown(!profileDropdown)}
|
2023-03-23 10:25:17 -05:00
|
|
|
id="profile-dropdown"
|
2023-03-22 18:11:54 -05:00
|
|
|
>
|
2023-03-23 10:25:17 -05:00
|
|
|
<FontAwesomeIcon
|
|
|
|
icon={faCircleUser}
|
|
|
|
className="h-5 pointer-events-none"
|
|
|
|
/>
|
|
|
|
<div className="flex items-center gap-1 pointer-events-none">
|
2023-03-22 22:06:15 -05:00
|
|
|
<p className="font-bold">{user?.name}</p>
|
|
|
|
<FontAwesomeIcon icon={faChevronDown} className="h-3" />
|
|
|
|
</div>
|
2023-02-18 21:32:02 -06:00
|
|
|
</div>
|
2023-03-22 18:11:54 -05:00
|
|
|
{profileDropdown ? (
|
|
|
|
<Dropdown
|
|
|
|
items={[
|
|
|
|
{
|
|
|
|
name: "Settings",
|
|
|
|
icon: <FontAwesomeIcon icon={faSliders} />,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Logout",
|
|
|
|
icon: <FontAwesomeIcon icon={faArrowRightFromBracket} />,
|
|
|
|
onClick: () => {
|
|
|
|
signOut();
|
|
|
|
setProfileDropdown(!profileDropdown);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]}
|
2023-03-23 10:25:17 -05:00
|
|
|
onClickOutside={(e: Event) => {
|
|
|
|
const target = e.target as HTMLInputElement;
|
|
|
|
if (target.id !== "profile-dropdown") setProfileDropdown(false);
|
|
|
|
}}
|
2023-03-25 09:17:34 -05:00
|
|
|
className="absolute top-10 left-0"
|
2023-03-22 18:11:54 -05:00
|
|
|
/>
|
|
|
|
) : null}
|
2023-02-18 21:32:02 -06:00
|
|
|
</div>
|
|
|
|
|
2023-03-05 15:03:20 -06:00
|
|
|
<Link href="links">
|
2023-03-25 09:17:34 -05:00
|
|
|
<div className="hover:bg-gray-50 hover:outline outline-sky-100 outline-1 duration-100 text-sky-900 rounded-md my-1 p-2 cursor-pointer flex items-center gap-2">
|
2023-03-05 15:03:20 -06:00
|
|
|
<FontAwesomeIcon icon={faBookmark} className="w-4 text-sky-300" />
|
|
|
|
<p>All Links</p>
|
|
|
|
</div>
|
|
|
|
</Link>
|
2023-02-24 22:22:33 -06:00
|
|
|
|
2023-03-05 15:03:20 -06:00
|
|
|
<Link href="/collections">
|
2023-03-25 09:17:34 -05:00
|
|
|
<div className="hover:bg-gray-50 hover:outline outline-sky-100 outline-1 duration-100 text-sky-900 rounded-md my-1 p-2 cursor-pointer flex items-center gap-2">
|
2023-03-05 15:03:20 -06:00
|
|
|
<FontAwesomeIcon icon={faBox} className="w-4 text-sky-300" />
|
|
|
|
<p>All Collections</p>
|
|
|
|
</div>
|
|
|
|
</Link>
|
2023-02-13 15:22:47 -06:00
|
|
|
|
2023-02-18 21:32:02 -06:00
|
|
|
<div className="text-gray-500 flex items-center justify-between mt-5">
|
2023-03-25 09:17:34 -05:00
|
|
|
<p className="text-sm p-2">Collections</p>
|
2023-02-18 21:32:02 -06:00
|
|
|
{collectionInput ? (
|
|
|
|
<ClickAwayHandler
|
|
|
|
onClickOutside={toggleCollectionInput}
|
|
|
|
className="w-fit"
|
|
|
|
>
|
2023-02-13 15:22:47 -06:00
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
placeholder="Enter Collection Name"
|
2023-03-25 09:17:34 -05:00
|
|
|
className="w-44 rounded-md p-1 border-sky-500 border-solid border text-sm outline-none"
|
2023-02-13 15:22:47 -06:00
|
|
|
onKeyDown={submitCollection}
|
|
|
|
autoFocus
|
|
|
|
/>
|
|
|
|
</ClickAwayHandler>
|
|
|
|
) : (
|
2023-02-18 21:32:02 -06:00
|
|
|
<FontAwesomeIcon
|
|
|
|
icon={faPlus}
|
|
|
|
onClick={toggleCollectionInput}
|
2023-03-25 09:17:34 -05:00
|
|
|
title="Add Collection"
|
|
|
|
className="select-none text-gray-500 rounded-md cursor-pointer hover:bg-white hover:outline outline-sky-100 outline-1 duration-100 p-1 w-3"
|
2023-02-18 21:32:02 -06:00
|
|
|
/>
|
2023-02-13 15:22:47 -06:00
|
|
|
)}
|
|
|
|
</div>
|
2023-02-18 21:32:02 -06:00
|
|
|
<div>
|
|
|
|
{collections.map((e, i) => {
|
2023-03-05 15:03:20 -06:00
|
|
|
return (
|
|
|
|
<SidebarItem
|
|
|
|
key={i}
|
|
|
|
text={e.name}
|
2023-03-22 22:06:15 -05:00
|
|
|
icon={<FontAwesomeIcon icon={faFolder} />}
|
2023-03-05 15:03:20 -06:00
|
|
|
path={`/collections/${e.id}`}
|
|
|
|
/>
|
|
|
|
);
|
2023-02-24 11:32:28 -06:00
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
<div className="text-gray-500 flex items-center justify-between 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>
|
|
|
|
{tags.map((e, i) => {
|
2023-03-05 15:03:20 -06:00
|
|
|
return (
|
|
|
|
<SidebarItem
|
|
|
|
key={i}
|
|
|
|
text={e.name}
|
2023-03-22 22:06:15 -05:00
|
|
|
icon={<FontAwesomeIcon icon={faHashtag} />}
|
2023-03-05 15:03:20 -06:00
|
|
|
path={`/tags/${e.id}`}
|
|
|
|
/>
|
|
|
|
);
|
2023-02-18 21:32:02 -06:00
|
|
|
})}
|
|
|
|
</div>
|
2023-02-08 17:58:55 -06:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|