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-02-18 21:32:02 -06:00
|
|
|
import useCollectionSlice from "@/store/collection";
|
|
|
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
|
|
import { faFolder, faUserCircle } from "@fortawesome/free-regular-svg-icons";
|
|
|
|
import {
|
|
|
|
faDatabase,
|
|
|
|
faPlus,
|
|
|
|
faChevronDown,
|
|
|
|
} from "@fortawesome/free-solid-svg-icons";
|
2023-02-08 17:58:55 -06:00
|
|
|
|
|
|
|
export default function Sidebar() {
|
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);
|
|
|
|
|
|
|
|
const { collections, addCollection } = useCollectionSlice();
|
2023-02-13 15:22:47 -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-02-18 21:32:02 -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">
|
|
|
|
<div className="flex gap-3 items-center mb-5 cursor-pointer w-fit text-gray-600">
|
|
|
|
<FontAwesomeIcon icon={faUserCircle} className="h-8" />
|
|
|
|
<div className="flex items-center gap-1">
|
|
|
|
<p>{user?.name}</p>
|
|
|
|
<FontAwesomeIcon icon={faChevronDown} className="h-3" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="hover:bg-sky-100 hover:shadow-sm duration-100 text-sky-900 rounded my-1 p-3 cursor-pointer flex items-center gap-2">
|
|
|
|
<FontAwesomeIcon icon={faDatabase} className="w-4" />
|
|
|
|
<p>All Collections</p>
|
|
|
|
</div>
|
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">
|
|
|
|
<p>Collections</p>
|
|
|
|
{collectionInput ? (
|
|
|
|
<ClickAwayHandler
|
|
|
|
onClickOutside={toggleCollectionInput}
|
|
|
|
className="w-fit"
|
|
|
|
>
|
2023-02-13 15:22:47 -06:00
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
placeholder="Enter Collection Name"
|
2023-02-18 21:32:02 -06:00
|
|
|
className="w-44 rounded p-1"
|
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}
|
|
|
|
className="select-none cursor-pointer rounded p-2 w-3"
|
|
|
|
/>
|
2023-02-13 15:22:47 -06:00
|
|
|
)}
|
|
|
|
</div>
|
2023-02-18 21:32:02 -06:00
|
|
|
<div>
|
|
|
|
{collections.map((e, i) => {
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className="hover:bg-sky-100 hover:shadow-sm duration-100 text-sky-900 rounded my-1 p-3 cursor-pointer flex items-center gap-2"
|
|
|
|
key={i}
|
|
|
|
>
|
|
|
|
<FontAwesomeIcon icon={faFolder} className="w-4" />
|
|
|
|
<p>{e.name}</p>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</div>
|
2023-02-08 17:58:55 -06:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|