2023-04-23 08:26:39 -05:00
// Copyright (C) 2022-present Daniel31x13 <daniel31x13@gmail.com>
// This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3.
// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
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" ;
import { useSession } from "next-auth/react" ;
2023-03-05 15:03:20 -06:00
import {
faPlus ,
2023-03-28 02:31:50 -05:00
faCircleUser ,
faSliders ,
faArrowRightFromBracket ,
faChevronDown ,
2023-04-30 15:54:40 -05:00
faBars ,
2023-03-05 15:03:20 -06:00
} from "@fortawesome/free-solid-svg-icons" ;
2023-05-01 05:07:01 -05:00
import { useEffect , useState } from "react" ;
2023-03-28 02:31:50 -05:00
import Dropdown from "@/components/Dropdown" ;
2023-05-08 09:35:39 -05:00
import Modal from "@/components/Modal" ;
import AddLink from "@/components/Modal/AddLink" ;
import ClickAwayHandler from "@/components/ClickAwayHandler" ;
import Sidebar from "@/components/Sidebar" ;
2023-05-01 05:07:01 -05:00
import { useRouter } from "next/router" ;
2023-05-08 09:35:39 -05:00
import Search from "@/components/Search" ;
2023-05-16 12:08:28 -05:00
import UserSettings from "./Modal/UserSettings" ;
2023-02-24 11:32:28 -06:00
export default function ( ) {
2023-03-28 02:31:50 -05:00
const { data : session } = useSession ( ) ;
2023-02-24 11:32:28 -06:00
2023-03-28 02:31:50 -05:00
const [ profileDropdown , setProfileDropdown ] = useState ( false ) ;
2023-02-24 11:32:28 -06:00
2023-03-28 02:31:50 -05:00
const user = session ? . user ;
2023-02-24 11:32:28 -06:00
2023-03-08 15:31:24 -06:00
const [ linkModal , setLinkModal ] = useState ( false ) ;
2023-05-16 12:08:28 -05:00
const [ settingsModal , setSettingsModal ] = useState ( false ) ;
2023-04-30 15:54:40 -05:00
const [ sidebar , setSidebar ] = useState ( false ) ;
2023-05-01 05:07:01 -05:00
const router = useRouter ( ) ;
2023-04-30 15:54:40 -05:00
window . addEventListener ( "resize" , ( ) = > setSidebar ( false ) ) ;
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-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
2023-05-16 12:08:28 -05:00
const toggleSettingsModal = ( ) = > {
setSettingsModal ( ! settingsModal ) ;
} ;
2023-02-08 18:32:20 -06:00
return (
2023-03-28 02:31:50 -05:00
< div className = "flex justify-between gap-2 items-center px-5 py-2 border-solid border-b-sky-100 border-b" >
2023-04-30 15:54:40 -05:00
< div
onClick = { toggleSidebar }
className = "inline-flex lg:hidden gap-1 items-center select-none cursor-pointer p-1 text-sky-500 rounded-md hover:outline-sky-500 outline duration-100 bg-white outline-sky-100 outline-1"
>
< FontAwesomeIcon icon = { faBars } className = "w-5 h-5" / >
< / div >
2023-05-08 09:35:39 -05:00
< Search / >
2023-03-28 02:31:50 -05:00
< div className = "flex items-center gap-2" >
< div
2023-03-08 15:31:24 -06:00
onClick = { toggleLinkModal }
2023-03-25 09:17:34 -05:00
title = "New Link"
2023-03-28 02:31:50 -05:00
className = "inline-flex gap-1 items-center select-none cursor-pointer p-1 text-sky-500 rounded-md hover:outline-sky-500 outline duration-100 bg-white outline-sky-100 outline-1"
>
2023-05-01 15:00:23 -05:00
< FontAwesomeIcon icon = { faPlus } className = "w-6 h-6" / >
2023-03-28 02:31:50 -05:00
< / div >
2023-02-24 11:32:28 -06:00
2023-03-28 02:31:50 -05:00
< div className = "relative" >
< div
className = "flex gap-2 items-center p-1 w-fit bg-white text-gray-600 cursor-pointer border border-sky-100 hover:border-sky-500 rounded-md duration-100"
onClick = { ( ) = > setProfileDropdown ( ! profileDropdown ) }
id = "profile-dropdown"
>
< FontAwesomeIcon
icon = { faCircleUser }
2023-05-01 15:00:23 -05:00
className = "h-6 w-6 pointer-events-none"
2023-03-28 02:31:50 -05:00
/ >
< div className = "flex items-center gap-1 pointer-events-none" >
2023-04-30 15:54:40 -05:00
< p className = "font-bold leading-3 hidden sm:block" >
{ user ? . name }
< / p >
2023-03-28 02:31:50 -05:00
< FontAwesomeIcon icon = { faChevronDown } className = "h-3 w-3" / >
< / div >
< / div >
{ profileDropdown ? (
< Dropdown
items = { [
{
name : "Settings" ,
icon : < FontAwesomeIcon icon = { faSliders } / > ,
2023-05-16 12:08:28 -05:00
onClick : ( ) = > {
toggleSettingsModal ( ) ;
setProfileDropdown ( ! profileDropdown ) ;
} ,
2023-03-28 02:31:50 -05:00
} ,
{
name : "Logout" ,
icon : < FontAwesomeIcon icon = { faArrowRightFromBracket } / > ,
onClick : ( ) = > {
signOut ( ) ;
setProfileDropdown ( ! profileDropdown ) ;
} ,
} ,
] }
onClickOutside = { ( e : Event ) = > {
const target = e . target as HTMLInputElement ;
if ( target . id !== "profile-dropdown" ) setProfileDropdown ( false ) ;
} }
2023-05-01 15:00:23 -05:00
className = "absolute top-9 right-0 z-20 w-36"
2023-03-28 02:31:50 -05:00
/ >
) : null }
2023-04-30 15:54:40 -05:00
2023-05-16 12:08:28 -05:00
{ linkModal ? (
< Modal toggleModal = { toggleLinkModal } >
< AddLink toggleLinkModal = { toggleLinkModal } / >
< / Modal >
) : null }
{ settingsModal ? (
< Modal toggleModal = { toggleSettingsModal } >
< UserSettings toggleSettingsModal = { toggleSettingsModal } / >
< / Modal >
) : null }
2023-04-30 15:54:40 -05:00
{ sidebar ? (
< div className = "fixed top-0 bottom-0 right-0 left-0 bg-gray-500 bg-opacity-10 flex items-center fade-in z-30" >
< ClickAwayHandler onClickOutside = { toggleSidebar } >
2023-05-01 05:07:01 -05:00
< div className = "slide-right shadow-lg" >
2023-04-30 15:54:40 -05:00
< Sidebar / >
< / div >
< / ClickAwayHandler >
< / div >
) : null }
2023-03-28 02:31:50 -05:00
< / div >
2023-02-08 18:32:20 -06:00
< / div >
< / div >
) ;
2023-02-08 17:58:55 -06:00
}