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-03-22 18:11:54 -05:00
import useCollectionStore from "@/store/collections" ;
2023-04-25 07:39:46 -05:00
import {
faAdd ,
faBox ,
faEllipsis ,
faPlus ,
2023-05-14 10:41:08 -05:00
faSort ,
2023-04-25 07:39:46 -05:00
} from "@fortawesome/free-solid-svg-icons" ;
2023-03-28 02:31:50 -05:00
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" ;
2023-02-24 11:32:28 -06:00
import CollectionCard from "@/components/CollectionCard" ;
2023-03-28 02:31:50 -05:00
import Dropdown from "@/components/Dropdown" ;
2023-05-14 10:41:08 -05:00
import { ChangeEvent , useState } from "react" ;
2023-04-23 08:26:39 -05:00
import Modal from "@/components/Modal" ;
import AddCollection from "@/components/Modal/AddCollection" ;
2023-05-14 10:41:08 -05:00
import MainLayout from "@/layouts/MainLayout" ;
import ClickAwayHandler from "@/components/ClickAwayHandler" ;
2023-05-15 14:18:33 -05:00
import { faCircle , faCircleCheck } from "@fortawesome/free-regular-svg-icons" ;
import RadioButton from "@/components/RadioButton" ;
2023-02-24 11:32:28 -06:00
export default function ( ) {
2023-03-22 18:11:54 -05:00
const { collections } = useCollectionStore ( ) ;
2023-04-23 08:26:39 -05:00
const [ expandDropdown , setExpandDropdown ] = useState ( false ) ;
2023-05-14 10:41:08 -05:00
const [ sortDropdown , setSortDropdown ] = useState ( false ) ;
2023-04-23 08:26:39 -05:00
2023-05-14 10:41:08 -05:00
const [ collectionModal , setCollectionModal ] = useState ( false ) ;
2023-04-23 08:26:39 -05:00
2023-04-25 07:39:46 -05:00
const toggleCollectionModal = ( ) = > {
2023-05-14 10:41:08 -05:00
setCollectionModal ( ! collectionModal ) ;
} ;
2023-05-15 14:18:33 -05:00
const [ sortBy , setSortBy ] = useState ( "Name" ) ;
2023-05-14 10:41:08 -05:00
const handleSortChange = ( event : ChangeEvent < HTMLInputElement > ) = > {
setSortBy ( event . target . value ) ;
2023-04-23 08:26:39 -05:00
} ;
2023-02-24 11:32:28 -06:00
return (
// ml-80
2023-05-14 10:41:08 -05:00
< MainLayout >
2023-04-30 15:54:40 -05:00
< div className = "p-5" >
2023-05-14 10:41:08 -05:00
< div className = "flex gap-3 items-center justify-between mb-5" >
< div className = "flex gap-3 items-center" >
< div className = "flex gap-2 items-center" >
< FontAwesomeIcon icon = { faBox } className = "w-5 h-5 text-sky-300" / >
< p className = "text-lg text-sky-900" > All Collections < / p >
< / div >
< div className = "relative" >
< div
onClick = { ( ) = > setExpandDropdown ( ! expandDropdown ) }
id = "edit-dropdown"
className = "inline-flex rounded-md cursor-pointer hover:bg-white hover:border-sky-500 border-sky-100 border duration-100 p-1"
>
< FontAwesomeIcon
icon = { faEllipsis }
id = "edit-dropdown"
className = "w-5 h-5 text-gray-500"
/ >
< / div >
{ expandDropdown ? (
< Dropdown
items = { [
{
name : "New" ,
icon : < FontAwesomeIcon icon = { faAdd } / > ,
onClick : ( ) = > {
toggleCollectionModal ( ) ;
setExpandDropdown ( false ) ;
} ,
} ,
] }
onClickOutside = { ( e : Event ) = > {
const target = e . target as HTMLInputElement ;
if ( target . id !== "edit-dropdown" ) setExpandDropdown ( false ) ;
} }
className = "absolute top-8 left-0 w-36"
/ >
) : null }
< / div >
2023-03-28 02:31:50 -05:00
< / div >
2023-05-14 10:41:08 -05:00
2023-04-30 15:54:40 -05:00
< div className = "relative" >
< div
2023-05-14 10:41:08 -05:00
onClick = { ( ) = > setSortDropdown ( ! sortDropdown ) }
id = "sort-dropdown"
2023-04-30 15:54:40 -05:00
className = "inline-flex rounded-md cursor-pointer hover:bg-white hover:border-sky-500 border-sky-100 border duration-100 p-1"
>
< FontAwesomeIcon
2023-05-14 10:41:08 -05:00
icon = { faSort }
id = "sort-dropdown"
2023-05-01 15:00:23 -05:00
className = "w-5 h-5 text-gray-500"
2023-04-30 15:54:40 -05:00
/ >
< / div >
2023-05-14 10:41:08 -05:00
{ sortDropdown ? (
< ClickAwayHandler
2023-04-30 15:54:40 -05:00
onClickOutside = { ( e : Event ) = > {
const target = e . target as HTMLInputElement ;
2023-05-14 10:41:08 -05:00
if ( target . id !== "sort-dropdown" ) setSortDropdown ( false ) ;
2023-04-30 15:54:40 -05:00
} }
2023-05-14 10:41:08 -05:00
className = "absolute top-8 right-0 shadow-md bg-gray-50 rounded-md p-2 z-10 border border-sky-100 w-36"
>
2023-05-15 14:18:33 -05:00
< p className = "mb-2 text-sky-900 text-center font-semibold" >
Sort by
< / p >
2023-05-14 10:41:08 -05:00
< div className = "flex flex-col gap-2" >
2023-05-15 14:18:33 -05:00
< RadioButton
label = "Name"
state = { sortBy === "Name" }
onClick = { handleSortChange }
/ >
< RadioButton
label = "Description"
state = { sortBy === "Description" }
onClick = { handleSortChange }
/ >
< RadioButton
label = "Date"
state = { sortBy === "Date" }
onClick = { handleSortChange }
/ >
2023-05-14 10:41:08 -05:00
< / div >
< / ClickAwayHandler >
2023-04-30 15:54:40 -05:00
) : null }
< / div >
2023-03-28 02:31:50 -05:00
< / div >
2023-05-14 10:41:08 -05:00
2023-04-30 15:54:40 -05:00
< div className = "flex flex-wrap gap-5" >
{ collections . map ( ( e , i ) = > {
return < CollectionCard key = { i } collection = { e } / > ;
} ) }
2023-04-23 08:26:39 -05:00
2023-04-30 15:54:40 -05:00
< div
className = "p-5 bg-gray-100 h-40 w-60 rounded-md border-sky-100 border-solid border flex flex-col gap-4 justify-center items-center cursor-pointer hover:bg-gray-50 duration-100"
onClick = { toggleCollectionModal }
>
< p className = "text-sky-900" > New Collection < / p >
< FontAwesomeIcon icon = { faPlus } className = "w-8 h-8 text-sky-500" / >
< / div >
2023-04-25 07:39:46 -05:00
< / div >
2023-03-28 02:31:50 -05:00
< / div >
2023-05-14 10:41:08 -05:00
{ collectionModal ? (
< Modal toggleModal = { toggleCollectionModal } >
< AddCollection toggleCollectionModal = { toggleCollectionModal } / >
< / Modal >
) : null }
< / MainLayout >
2023-02-24 11:32:28 -06:00
) ;
}