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-10 23:10:10 -06:00
|
|
|
<div className="fixed bg-gray-100 top-0 bottom-0 left-0 w-80 p-5 overflow-y-auto hide-scrollbar border-solid border-r-sky-100 border z-10">
|
2023-03-22 18:11:54 -05:00
|
|
|
<div className="flex gap-3 items-center mb-5 p-3 w-fit text-gray-600 relative">
|
|
|
|
<FontAwesomeIcon icon={faCircleUser} className="h-8" />
|
|
|
|
<div
|
|
|
|
className="flex items-center gap-1 cursor-pointer"
|
|
|
|
onClick={() => setProfileDropdown(!profileDropdown)}
|
|
|
|
>
|
2023-02-18 21:32:02 -06:00
|
|
|
<p>{user?.name}</p>
|
|
|
|
<FontAwesomeIcon icon={faChevronDown} className="h-3" />
|
|
|
|
</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);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
onClickOutside={() => setProfileDropdown(!profileDropdown)}
|
|
|
|
className="absolute top-14 left-0"
|
|
|
|
/>
|
|
|
|
) : null}
|
2023-02-18 21:32:02 -06:00
|
|
|
</div>
|
|
|
|
|
2023-03-05 15:03:20 -06:00
|
|
|
<Link href="links">
|
2023-03-10 23:10:10 -06:00
|
|
|
<div className="hover:bg-gray-50 hover:outline outline-sky-100 outline-1 duration-100 text-sky-900 rounded my-1 p-3 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-10 23:10:10 -06:00
|
|
|
<div className="hover:bg-gray-50 hover:outline outline-sky-100 outline-1 duration-100 text-sky-900 rounded my-1 p-3 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-02-24 11:32:28 -06:00
|
|
|
<p className="text-sm p-3">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-02-24 11:32:28 -06:00
|
|
|
className="w-44 rounded p-2 border-sky-100 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-02-24 11:32:28 -06:00
|
|
|
className="select-none cursor-pointer p-2 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}
|
|
|
|
icon={faFolder}
|
|
|
|
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">
|
|
|
|
<p className="text-sm p-3">Tags</p>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
{tags.map((e, i) => {
|
2023-03-05 15:03:20 -06:00
|
|
|
return (
|
|
|
|
<SidebarItem
|
|
|
|
key={i}
|
|
|
|
text={e.name}
|
2023-03-10 13:25:33 -06:00
|
|
|
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>
|
|
|
|
);
|
|
|
|
}
|