2023-02-24 11:32:28 -06:00
|
|
|
import { useRouter } from "next/router";
|
2023-03-22 18:11:54 -05:00
|
|
|
import useCollectionStore from "@/store/collections";
|
2023-03-05 15:03:20 -06:00
|
|
|
import { Collection, Tag } from "@prisma/client";
|
2023-02-24 11:32:28 -06:00
|
|
|
import ClickAwayHandler from "./ClickAwayHandler";
|
|
|
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
2023-03-05 15:03:20 -06:00
|
|
|
import {
|
|
|
|
faPlus,
|
|
|
|
faFolder,
|
|
|
|
faBox,
|
2023-03-10 13:25:33 -06:00
|
|
|
faHashtag,
|
2023-03-05 15:03:20 -06:00
|
|
|
faBookmark,
|
|
|
|
faMagnifyingGlass,
|
|
|
|
IconDefinition,
|
|
|
|
} from "@fortawesome/free-solid-svg-icons";
|
|
|
|
import { useEffect, useState } from "react";
|
2023-02-24 11:32:28 -06:00
|
|
|
import AddLinkModal from "./AddLinkModal";
|
2023-03-22 18:11:54 -05:00
|
|
|
import useTagStore from "@/store/tags";
|
2023-02-24 11:32:28 -06:00
|
|
|
|
|
|
|
export default function () {
|
|
|
|
const router = useRouter();
|
2023-03-05 15:03:20 -06:00
|
|
|
const [pageName, setPageName] = useState<string | null>("");
|
|
|
|
const [pageIcon, setPageIcon] = useState<IconDefinition | null>(null);
|
2023-02-24 11:32:28 -06:00
|
|
|
|
2023-03-22 18:11:54 -05:00
|
|
|
const { collections } = useCollectionStore();
|
|
|
|
const { tags } = useTagStore();
|
2023-02-24 11:32:28 -06:00
|
|
|
|
2023-03-05 15:03:20 -06:00
|
|
|
useEffect(() => {
|
|
|
|
if (router.route === "/collections/[id]") {
|
|
|
|
const collectionId = router.query.id;
|
|
|
|
|
|
|
|
const activeCollection: Collection | undefined = collections.find(
|
|
|
|
(e) => e.id.toString() == collectionId
|
|
|
|
);
|
|
|
|
|
|
|
|
if (activeCollection) {
|
|
|
|
setPageName(activeCollection?.name);
|
|
|
|
}
|
|
|
|
|
|
|
|
setPageIcon(faFolder);
|
|
|
|
} else if (router.route === "/tags/[id]") {
|
|
|
|
const tagId = router.query.id;
|
|
|
|
|
|
|
|
const activeTag: Tag | undefined = tags.find(
|
|
|
|
(e) => e.id.toString() == tagId
|
|
|
|
);
|
|
|
|
|
|
|
|
if (activeTag) {
|
|
|
|
setPageName(activeTag?.name);
|
|
|
|
}
|
|
|
|
|
2023-03-10 13:25:33 -06:00
|
|
|
setPageIcon(faHashtag);
|
2023-03-05 15:03:20 -06:00
|
|
|
} else if (router.route === "/collections") {
|
|
|
|
setPageName("All Collections");
|
|
|
|
setPageIcon(faBox);
|
|
|
|
} else if (router.route === "/links") {
|
|
|
|
setPageName("All Links");
|
|
|
|
setPageIcon(faBookmark);
|
|
|
|
}
|
|
|
|
}, [router, collections, tags]);
|
2023-02-24 11:32:28 -06:00
|
|
|
|
2023-03-08 15:31:24 -06:00
|
|
|
const [linkModal, setLinkModal] = useState(false);
|
2023-02-24 11:32:28 -06:00
|
|
|
|
2023-03-08 15:31:24 -06:00
|
|
|
const toggleLinkModal = () => {
|
|
|
|
setLinkModal(!linkModal);
|
2023-02-24 11:32:28 -06:00
|
|
|
};
|
2023-02-08 18:32:20 -06:00
|
|
|
|
|
|
|
return (
|
2023-02-24 11:32:28 -06:00
|
|
|
<div className="flex justify-between items-center p-5 border-solid border-b-sky-100 border border-l-white">
|
2023-03-05 15:03:20 -06:00
|
|
|
<div className="text-sky-900 rounded my-1 flex items-center gap-2 font-bold">
|
|
|
|
{pageIcon ? (
|
|
|
|
<FontAwesomeIcon icon={pageIcon} className="w-4 text-sky-300" />
|
|
|
|
) : null}
|
|
|
|
<p>{pageName}</p>
|
|
|
|
</div>
|
2023-02-24 11:32:28 -06:00
|
|
|
<div className="flex items-center gap-3">
|
|
|
|
<FontAwesomeIcon
|
|
|
|
icon={faPlus}
|
2023-03-08 15:31:24 -06:00
|
|
|
onClick={toggleLinkModal}
|
2023-02-24 11:32:28 -06:00
|
|
|
className="select-none cursor-pointer w-5 h-5 text-white bg-sky-500 p-2 rounded hover:bg-sky-400 duration-100"
|
|
|
|
/>
|
|
|
|
<FontAwesomeIcon
|
|
|
|
icon={faMagnifyingGlass}
|
|
|
|
className="select-none cursor-pointer w-5 h-5 text-white bg-sky-500 p-2 rounded hover:bg-sky-400 duration-100"
|
|
|
|
/>
|
|
|
|
|
2023-03-08 15:31:24 -06:00
|
|
|
{linkModal ? (
|
2023-03-10 23:10:10 -06:00
|
|
|
<div className="fixed top-0 bottom-0 right-0 left-0 bg-gray-500 bg-opacity-10 flex items-center fade-in z-10">
|
2023-02-24 11:32:28 -06:00
|
|
|
<ClickAwayHandler
|
2023-03-08 15:31:24 -06:00
|
|
|
onClickOutside={toggleLinkModal}
|
2023-02-24 11:32:28 -06:00
|
|
|
className="w-fit mx-auto"
|
|
|
|
>
|
2023-03-08 15:31:24 -06:00
|
|
|
<AddLinkModal toggleLinkModal={toggleLinkModal} />
|
2023-02-24 11:32:28 -06:00
|
|
|
</ClickAwayHandler>
|
|
|
|
</div>
|
|
|
|
) : null}
|
2023-02-08 18:32:20 -06:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
2023-02-08 17:58:55 -06:00
|
|
|
}
|