2023-02-24 11:32:28 -06:00
|
|
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
2023-03-28 02:31:50 -05:00
|
|
|
import { signOut } from "next-auth/react";
|
2023-11-29 08:41:24 -06:00
|
|
|
import { faPlus, faBars, faCaretDown } from "@fortawesome/free-solid-svg-icons";
|
2023-05-01 05:07:01 -05:00
|
|
|
import { useEffect, useState } from "react";
|
2023-05-08 09:35:39 -05:00
|
|
|
import ClickAwayHandler from "@/components/ClickAwayHandler";
|
|
|
|
import Sidebar from "@/components/Sidebar";
|
2023-05-01 05:07:01 -05:00
|
|
|
import { useRouter } from "next/router";
|
2023-11-16 02:22:16 -06:00
|
|
|
import SearchBar from "@/components/SearchBar";
|
2023-05-20 14:25:00 -05:00
|
|
|
import useAccountStore from "@/store/account";
|
2023-06-09 17:31:14 -05:00
|
|
|
import ProfilePhoto from "@/components/ProfilePhoto";
|
2023-10-23 09:45:48 -05:00
|
|
|
import useWindowDimensions from "@/hooks/useWindowDimensions";
|
2023-11-16 02:22:16 -06:00
|
|
|
import ToggleDarkMode from "./ToggleDarkMode";
|
2023-11-24 06:50:16 -06:00
|
|
|
import useLocalSettingsStore from "@/store/localSettings";
|
2023-12-01 16:44:34 -06:00
|
|
|
import NewLinkModal from "./ModalContent/NewLinkModal";
|
|
|
|
import NewCollectionModal from "./ModalContent/NewCollectionModal";
|
2023-11-29 14:17:51 -06:00
|
|
|
import Link from "next/link";
|
2023-12-03 22:52:32 -06:00
|
|
|
import UploadFileModal from "./ModalContent/UploadFileModal";
|
2023-02-24 11:32:28 -06:00
|
|
|
|
2023-06-09 17:31:14 -05:00
|
|
|
export default function Navbar() {
|
2023-11-24 06:50:16 -06:00
|
|
|
const { settings, updateSettings } = useLocalSettingsStore();
|
|
|
|
|
2023-05-20 14:25:00 -05:00
|
|
|
const { account } = useAccountStore();
|
2023-02-24 11:32:28 -06:00
|
|
|
|
2023-05-01 05:07:01 -05:00
|
|
|
const router = useRouter();
|
|
|
|
|
2023-10-16 12:10:52 -05:00
|
|
|
const [sidebar, setSidebar] = useState(false);
|
|
|
|
|
2023-10-23 09:45:48 -05:00
|
|
|
const { width } = useWindowDimensions();
|
|
|
|
|
2023-11-24 06:50:16 -06:00
|
|
|
const handleToggle = () => {
|
|
|
|
if (settings.theme === "dark") {
|
|
|
|
updateSettings({ theme: "light" });
|
|
|
|
} else {
|
|
|
|
updateSettings({ theme: "dark" });
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-10-23 09:45:48 -05:00
|
|
|
useEffect(() => {
|
|
|
|
setSidebar(false);
|
|
|
|
}, [width]);
|
2023-04-30 15:54:40 -05:00
|
|
|
|
2023-05-01 05:07:01 -05:00
|
|
|
useEffect(() => {
|
|
|
|
setSidebar(false);
|
|
|
|
}, [router]);
|
|
|
|
|
2023-04-30 15:54:40 -05:00
|
|
|
const toggleSidebar = () => {
|
|
|
|
setSidebar(!sidebar);
|
|
|
|
};
|
2023-02-24 11:32:28 -06:00
|
|
|
|
2023-12-01 11:01:56 -06:00
|
|
|
const [newLinkModal, setNewLinkModal] = useState(false);
|
|
|
|
const [newCollectionModal, setNewCollectionModal] = useState(false);
|
2023-12-03 22:52:32 -06:00
|
|
|
const [uploadFileModal, setUploadFileModal] = useState(false);
|
2023-11-28 23:46:31 -06:00
|
|
|
|
2023-02-08 18:32:20 -06:00
|
|
|
return (
|
2023-11-30 05:13:42 -06:00
|
|
|
<div className="flex justify-between gap-2 items-center px-4 py-2 border-solid border-b-neutral-content border-b">
|
2023-04-30 15:54:40 -05:00
|
|
|
<div
|
|
|
|
onClick={toggleSidebar}
|
2023-11-27 15:38:38 -06:00
|
|
|
className="text-neutral btn btn-square btn-sm btn-ghost lg:hidden"
|
2023-04-30 15:54:40 -05:00
|
|
|
>
|
2023-05-31 13:33:01 -05:00
|
|
|
<FontAwesomeIcon icon={faBars} className="w-5 h-5" />
|
2023-04-30 15:54:40 -05:00
|
|
|
</div>
|
2023-11-16 02:22:16 -06:00
|
|
|
<SearchBar />
|
2023-03-28 02:31:50 -05:00
|
|
|
<div className="flex items-center gap-2">
|
2023-11-27 15:38:38 -06:00
|
|
|
<ToggleDarkMode className="sm:inline-grid hidden" />
|
|
|
|
|
2023-11-29 08:41:24 -06:00
|
|
|
<div className="dropdown dropdown-end">
|
|
|
|
<div className="tooltip tooltip-bottom" data-tip="Create New...">
|
|
|
|
<div
|
|
|
|
tabIndex={0}
|
|
|
|
role="button"
|
2023-12-07 11:29:45 -06:00
|
|
|
className="flex items-center group btn btn-accent dark:border-violet-400 text-white btn-sm px-2"
|
2023-11-29 08:41:24 -06:00
|
|
|
>
|
|
|
|
<FontAwesomeIcon icon={faPlus} className="w-5 h-5" />
|
2023-12-01 11:01:56 -06:00
|
|
|
<FontAwesomeIcon
|
|
|
|
icon={faCaretDown}
|
|
|
|
className="w-2 h-2 sm:w-3 sm:h-3"
|
|
|
|
/>
|
2023-11-29 08:41:24 -06:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-12-02 03:42:51 -06:00
|
|
|
<ul className="dropdown-content z-[1] menu shadow bg-base-200 border border-neutral-content rounded-box w-40 mt-1">
|
2023-11-29 08:41:24 -06:00
|
|
|
<li>
|
|
|
|
<div
|
2023-11-30 03:36:40 -06:00
|
|
|
onClick={() => {
|
|
|
|
(document?.activeElement as HTMLElement)?.blur();
|
2023-12-01 11:01:56 -06:00
|
|
|
setNewLinkModal(true);
|
2023-11-30 03:36:40 -06:00
|
|
|
}}
|
2023-11-29 08:41:24 -06:00
|
|
|
tabIndex={0}
|
|
|
|
role="button"
|
|
|
|
>
|
|
|
|
New Link
|
|
|
|
</div>
|
|
|
|
</li>
|
2023-12-06 15:13:11 -06:00
|
|
|
{/* <li>
|
2023-12-03 22:52:32 -06:00
|
|
|
<div
|
|
|
|
onClick={() => {
|
|
|
|
(document?.activeElement as HTMLElement)?.blur();
|
|
|
|
setUploadFileModal(true);
|
|
|
|
}}
|
|
|
|
tabIndex={0}
|
|
|
|
role="button"
|
|
|
|
>
|
|
|
|
Upload File
|
|
|
|
</div>
|
2023-12-06 15:13:11 -06:00
|
|
|
</li> */}
|
2023-11-29 08:41:24 -06:00
|
|
|
<li>
|
|
|
|
<div
|
2023-11-30 03:36:40 -06:00
|
|
|
onClick={() => {
|
|
|
|
(document?.activeElement as HTMLElement)?.blur();
|
2023-12-01 11:01:56 -06:00
|
|
|
setNewCollectionModal(true);
|
2023-11-30 03:36:40 -06:00
|
|
|
}}
|
2023-11-29 08:41:24 -06:00
|
|
|
tabIndex={0}
|
|
|
|
role="button"
|
|
|
|
>
|
|
|
|
New Collection
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
2023-11-16 02:22:16 -06:00
|
|
|
|
2023-11-29 14:17:51 -06:00
|
|
|
<div className="dropdown dropdown-end">
|
|
|
|
<div tabIndex={0} role="button" className="btn btn-circle btn-ghost">
|
2023-06-07 14:34:50 -05:00
|
|
|
<ProfilePhoto
|
2023-10-27 23:45:14 -05:00
|
|
|
src={account.image ? account.image : undefined}
|
2023-10-16 12:10:52 -05:00
|
|
|
priority={true}
|
2023-06-07 14:34:50 -05:00
|
|
|
/>
|
2023-03-28 02:31:50 -05:00
|
|
|
</div>
|
2023-12-02 03:42:51 -06:00
|
|
|
<ul className="dropdown-content z-[1] menu shadow bg-base-200 border border-neutral-content rounded-box w-40 mt-1">
|
2023-11-29 14:17:51 -06:00
|
|
|
<li>
|
2023-11-30 03:36:40 -06:00
|
|
|
<Link
|
|
|
|
href="/settings/account"
|
|
|
|
onClick={() => (document?.activeElement as HTMLElement)?.blur()}
|
|
|
|
tabIndex={0}
|
|
|
|
role="button"
|
|
|
|
>
|
2023-11-29 14:17:51 -06:00
|
|
|
Settings
|
|
|
|
</Link>
|
|
|
|
</li>
|
|
|
|
<li>
|
2023-11-30 03:36:40 -06:00
|
|
|
<div
|
|
|
|
onClick={() => {
|
|
|
|
(document?.activeElement as HTMLElement)?.blur();
|
|
|
|
handleToggle();
|
|
|
|
}}
|
|
|
|
tabIndex={0}
|
|
|
|
role="button"
|
|
|
|
>
|
2023-11-29 14:17:51 -06:00
|
|
|
Switch to {settings.theme === "light" ? "Dark" : "Light"}
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
<li>
|
2023-11-30 03:36:40 -06:00
|
|
|
<div
|
|
|
|
onClick={() => {
|
|
|
|
(document?.activeElement as HTMLElement)?.blur();
|
|
|
|
signOut();
|
|
|
|
}}
|
|
|
|
tabIndex={0}
|
|
|
|
role="button"
|
|
|
|
>
|
2023-11-29 14:17:51 -06:00
|
|
|
Logout
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
</ul>
|
2023-03-28 02:31:50 -05:00
|
|
|
</div>
|
2023-02-08 18:32:20 -06:00
|
|
|
</div>
|
2023-11-29 14:17:51 -06:00
|
|
|
{sidebar ? (
|
|
|
|
<div className="fixed top-0 bottom-0 right-0 left-0 bg-black bg-opacity-10 backdrop-blur-sm flex items-center fade-in z-30">
|
|
|
|
<ClickAwayHandler className="h-full" onClickOutside={toggleSidebar}>
|
|
|
|
<div className="slide-right h-full shadow-lg">
|
|
|
|
<Sidebar />
|
|
|
|
</div>
|
|
|
|
</ClickAwayHandler>
|
|
|
|
</div>
|
|
|
|
) : null}
|
2023-12-01 16:42:45 -06:00
|
|
|
{newLinkModal ? (
|
|
|
|
<NewLinkModal onClose={() => setNewLinkModal(false)} />
|
|
|
|
) : undefined}
|
|
|
|
{newCollectionModal ? (
|
|
|
|
<NewCollectionModal onClose={() => setNewCollectionModal(false)} />
|
|
|
|
) : undefined}
|
2023-12-03 22:52:32 -06:00
|
|
|
{uploadFileModal ? (
|
|
|
|
<UploadFileModal onClose={() => setUploadFileModal(false)} />
|
|
|
|
) : undefined}
|
2023-02-08 18:32:20 -06:00
|
|
|
</div>
|
|
|
|
);
|
2023-02-08 17:58:55 -06:00
|
|
|
}
|