From 64a1f352cf5276e152a213c33c2b196ffb9d29a6 Mon Sep 17 00:00:00 2001 From: daniel31x13 Date: Wed, 29 Nov 2023 15:17:51 -0500 Subject: [PATCH] recreated SortDropdown components --- components/CollectionCard.tsx | 4 +- components/Navbar.tsx | 86 ++++++--------- components/SortDropdown.tsx | 171 +++++++++++++++++++++--------- components/ToggleDarkMode.tsx | 63 ++++++----- pages/collections/[id].tsx | 27 +---- pages/collections/index.tsx | 22 +--- pages/links/index.tsx | 23 +--- pages/links/pinned.tsx | 24 +---- pages/public/collections/[id].tsx | 26 +---- pages/search.tsx | 21 +--- pages/tags/[id].tsx | 22 +--- 11 files changed, 198 insertions(+), 291 deletions(-) diff --git a/components/CollectionCard.tsx b/components/CollectionCard.tsx index a141313..fcea927 100644 --- a/components/CollectionCard.tsx +++ b/components/CollectionCard.tsx @@ -59,7 +59,7 @@ export default function CollectionCard({ collection, className }: Props) { return (
-
+
-
    +
      {permissions === true ? (
-
    +
    • setNewLinkModalIsOpen(true)} @@ -99,64 +97,42 @@ export default function Navbar() {
-
-
setProfileDropdown(!profileDropdown)} - id="profile-dropdown" - > +
+
- {profileDropdown ? ( - { - setProfileDropdown(!profileDropdown); - handleToggle(); - }, - }, - { - name: "Logout", - onClick: () => { - signOut(); - setProfileDropdown(!profileDropdown); - }, - }, - ]} - onClickOutside={(e: Event) => { - const target = e.target as HTMLInputElement; - if (target.id !== "profile-dropdown") setProfileDropdown(false); - }} - className="absolute top-11 right-0 z-20 w-36" - /> - ) : null} - - {sidebar ? ( -
- -
- -
-
-
- ) : null} +
    +
  • + + Settings + +
  • +
  • +
    + Switch to {settings.theme === "light" ? "Dark" : "Light"} +
    +
  • +
  • +
    signOut()} tabIndex={0} role="button"> + Logout +
    +
  • +
+ {sidebar ? ( +
+ +
+ +
+
+
+ ) : null} >; - - toggleSortDropdown: Function; }; -export default function SortDropdown({ - sortBy, - toggleSortDropdown, - setSort, -}: Props) { +export default function SortDropdown({ sortBy, setSort }: Props) { return ( - { - const target = e.target as HTMLInputElement; - if (target.id !== "sort-dropdown") toggleSortDropdown(); - }} - className="absolute top-8 right-0 border border-neutral-content shadow-md bg-base-200 rounded-md p-2 z-20 w-52" - > -

Sort by

-
- setSort(Sort.DateNewestFirst)} - /> - - setSort(Sort.DateOldestFirst)} - /> - - setSort(Sort.NameAZ)} - /> - - setSort(Sort.NameZA)} - /> - - setSort(Sort.DescriptionAZ)} - /> - - setSort(Sort.DescriptionZA)} +
+
+
- +
    +
  • + +
  • +
  • + +
  • +
  • + +
  • +
  • + +
  • +
  • + +
  • +
  • + +
  • +
+
); } diff --git a/components/ToggleDarkMode.tsx b/components/ToggleDarkMode.tsx index 58fd950..595ae2a 100644 --- a/components/ToggleDarkMode.tsx +++ b/components/ToggleDarkMode.tsx @@ -6,7 +6,7 @@ type Props = { }; export default function ToggleDarkMode({ className }: Props) { - const { updateSettings } = useLocalSettingsStore(); + const { settings, updateSettings } = useLocalSettingsStore(); const [theme, setTheme] = useState(localStorage.getItem("theme")); @@ -23,36 +23,41 @@ export default function ToggleDarkMode({ className }: Props) { }, [theme]); return ( - + {/* sun icon */} + + + + + + {/* moon icon */} + + + + +
); } diff --git a/pages/collections/[id].tsx b/pages/collections/[id].tsx index 1ba3da1..3daf937 100644 --- a/pages/collections/[id].tsx +++ b/pages/collections/[id].tsx @@ -3,11 +3,7 @@ import LinkCard from "@/components/LinkCard"; import useCollectionStore from "@/store/collections"; import useLinkStore from "@/store/links"; import { CollectionIncludingMembersAndLinkCount, Sort } from "@/types/global"; -import { - faEllipsis, - faFolder, - faSort, -} from "@fortawesome/free-solid-svg-icons"; +import { faEllipsis, faFolder } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { useRouter } from "next/router"; import { useEffect, useState } from "react"; @@ -31,7 +27,6 @@ export default function Index() { const { collections } = useCollectionStore(); const [expandDropdown, setExpandDropdown] = useState(false); - const [sortDropdown, setSortDropdown] = useState(false); const [sortBy, setSortBy] = useState(Sort.DateNewestFirst); const [activeCollection, setActiveCollection] = @@ -124,25 +119,7 @@ export default function Index() {

{activeCollection?.description}

-
setSortDropdown(!sortDropdown)} - id="sort-dropdown" - className="btn btn-ghost btn-square btn-sm" - > - -
- - {sortDropdown ? ( - setSortDropdown(!sortDropdown)} - /> - ) : null} +
(Sort.DateNewestFirst); const [sortedCollections, setSortedCollections] = useState(collections); @@ -91,25 +89,7 @@ export default function Collections() {
-
setSortDropdown(!sortDropdown)} - id="sort-dropdown" - className="btn btn-ghost btn-square btn-sm" - > - -
- - {sortDropdown ? ( - setSortDropdown(!sortDropdown)} - /> - ) : null} +
diff --git a/pages/links/index.tsx b/pages/links/index.tsx index 8d5157b..6364e40 100644 --- a/pages/links/index.tsx +++ b/pages/links/index.tsx @@ -5,14 +5,13 @@ import useLinks from "@/hooks/useLinks"; import MainLayout from "@/layouts/MainLayout"; import useLinkStore from "@/store/links"; import { Sort } from "@/types/global"; -import { faLink, faSort } from "@fortawesome/free-solid-svg-icons"; +import { faLink } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { useState } from "react"; export default function Links() { const { links } = useLinkStore(); - const [sortDropdown, setSortDropdown] = useState(false); const [sortBy, setSortBy] = useState(Sort.DateNewestFirst); useLinks({ sort: sortBy }); @@ -34,25 +33,7 @@ export default function Links() {
-
setSortDropdown(!sortDropdown)} - id="sort-dropdown" - className="btn btn-ghost btn-square btn-sm" - > - -
- - {sortDropdown ? ( - setSortDropdown(!sortDropdown)} - /> - ) : null} +
{links[0] ? ( diff --git a/pages/links/pinned.tsx b/pages/links/pinned.tsx index 35e82dd..ac52af2 100644 --- a/pages/links/pinned.tsx +++ b/pages/links/pinned.tsx @@ -1,18 +1,16 @@ import LinkCard from "@/components/LinkCard"; -import NoLinksFound from "@/components/NoLinksFound"; import SortDropdown from "@/components/SortDropdown"; import useLinks from "@/hooks/useLinks"; import MainLayout from "@/layouts/MainLayout"; import useLinkStore from "@/store/links"; import { Sort } from "@/types/global"; -import { faSort, faThumbTack } from "@fortawesome/free-solid-svg-icons"; +import { faThumbTack } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { useState } from "react"; export default function PinnedLinks() { const { links } = useLinkStore(); - const [sortDropdown, setSortDropdown] = useState(false); const [sortBy, setSortBy] = useState(Sort.DateNewestFirst); useLinks({ sort: sortBy, pinnedOnly: true }); @@ -34,25 +32,7 @@ export default function PinnedLinks() {
-
setSortDropdown(!sortDropdown)} - id="sort-dropdown" - className="btn btn-ghost btn-square btn-sm" - > - -
- - {sortDropdown ? ( - setSortDropdown(!sortDropdown)} - /> - ) : null} +
{links.some((e) => e.pinnedBy && e.pinnedBy[0]) ? ( diff --git a/pages/public/collections/[id].tsx b/pages/public/collections/[id].tsx index 8d4c065..a9ddc1e 100644 --- a/pages/public/collections/[id].tsx +++ b/pages/public/collections/[id].tsx @@ -17,7 +17,7 @@ import Image from "next/image"; import Link from "next/link"; import PublicSearchBar from "@/components/PublicPage/PublicSearchBar"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; -import { faFilter, faSort } from "@fortawesome/free-solid-svg-icons"; +import { faFilter } from "@fortawesome/free-solid-svg-icons"; import FilterSearchDropdown from "@/components/FilterSearchDropdown"; import SortDropdown from "@/components/SortDropdown"; import useLocalSettingsStore from "@/store/localSettings"; @@ -66,7 +66,6 @@ export default function PublicCollections() { }); const [filterDropdown, setFilterDropdown] = useState(false); - const [sortDropdown, setSortDropdown] = useState(false); const [sortBy, setSortBy] = useState(Sort.DateNewestFirst); useLinks({ @@ -129,13 +128,14 @@ export default function PublicCollections() {

+ Linkwarden @@ -230,25 +230,7 @@ export default function PublicCollections() {
-
setSortDropdown(!sortDropdown)} - id="sort-dropdown" - className="btn btn-ghost btn-square btn-sm" - > - -
- - {sortDropdown ? ( - setSortDropdown(!sortDropdown)} - /> - ) : null} +
diff --git a/pages/search.tsx b/pages/search.tsx index 34da3c6..058d4ed 100644 --- a/pages/search.tsx +++ b/pages/search.tsx @@ -24,7 +24,6 @@ export default function Search() { }); const [filterDropdown, setFilterDropdown] = useState(false); - const [sortDropdown, setSortDropdown] = useState(false); const [sortBy, setSortBy] = useState(Sort.DateNewestFirst); useLinks({ @@ -77,25 +76,7 @@ export default function Search() {
-
setSortDropdown(!sortDropdown)} - id="sort-dropdown" - className="btn btn-ghost btn-square btn-sm" - > - -
- - {sortDropdown ? ( - setSortDropdown(!sortDropdown)} - /> - ) : null} +
diff --git a/pages/tags/[id].tsx b/pages/tags/[id].tsx index 0ad9a71..528bb16 100644 --- a/pages/tags/[id].tsx +++ b/pages/tags/[id].tsx @@ -4,7 +4,6 @@ import { faCheck, faEllipsis, faHashtag, - faSort, faXmark, } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; @@ -24,7 +23,6 @@ export default function Index() { const { links } = useLinkStore(); const { tags, updateTag, removeTag } = useTagStore(); - const [sortDropdown, setSortDropdown] = useState(false); const [sortBy, setSortBy] = useState(Sort.DateNewestFirst); const [expandDropdown, setExpandDropdown] = useState(false); @@ -194,25 +192,7 @@ export default function Index() {
-
setSortDropdown(!sortDropdown)} - id="sort-dropdown" - className="btn btn-ghost btn-square btn-sm" - > - -
- - {sortDropdown ? ( - setSortDropdown(!sortDropdown)} - /> - ) : null} +