add route for pinned links + better dashboard UX

This commit is contained in:
daniel31x13
2023-11-11 14:57:46 -05:00
parent 49b1ea4875
commit b19d6694ec
8 changed files with 186 additions and 124 deletions
+24 -45
View File
@@ -1,7 +1,6 @@
import useCollectionStore from "@/store/collections";
import {
faChartSimple,
faChevronDown,
faChevronRight,
faClockRotateLeft,
faFileImport,
@@ -36,14 +35,7 @@ export default function Dashboard() {
const [numberOfLinks, setNumberOfLinks] = useState(0);
const [showRecents, setShowRecents] = useState(3);
const [linkPinDisclosure, setLinkPinDisclosure] = useState<boolean>(() => {
const storedValue =
typeof window !== "undefined" &&
localStorage.getItem("linkPinDisclosure");
return storedValue ? storedValue === "true" : true;
});
const [showLinks, setShowLinks] = useState(3);
useLinks({ pinnedOnly: true, sort: 0 });
@@ -57,25 +49,18 @@ export default function Dashboard() {
);
}, [collections]);
useEffect(() => {
localStorage.setItem(
"linkPinDisclosure",
linkPinDisclosure ? "true" : "false"
);
}, [linkPinDisclosure]);
const handleNumberOfRecents = () => {
if (window.innerWidth > 1550) {
setShowRecents(6);
const handleNumberOfLinksToShow = () => {
if (window.innerWidth > 1535) {
setShowLinks(6);
} else if (window.innerWidth > 1295) {
setShowRecents(4);
} else setShowRecents(3);
setShowLinks(4);
} else setShowLinks(3);
};
const { width } = useWindowDimensions();
useEffect(() => {
handleNumberOfRecents();
handleNumberOfLinksToShow();
}, [width]);
const [importDropdown, setImportDropdown] = useState(false);
@@ -197,7 +182,7 @@ export default function Dashboard() {
<div
className={`grid overflow-hidden 2xl:grid-cols-3 xl:grid-cols-2 grid-cols-1 gap-5 w-full`}
>
{links.slice(0, showRecents).map((e, i) => (
{links.slice(0, showLinks).map((e, i) => (
<LinkCard key={i} link={e} count={i} />
))}
</div>
@@ -314,38 +299,32 @@ export default function Dashboard() {
/>
<p className="text-2xl text-black dark:text-white">Pinned Links</p>
</div>
{links.some((e) => e.pinnedBy && e.pinnedBy[0]) ? (
<button
className="text-black dark:text-white flex items-center gap-2 cursor-pointer"
onClick={() => setLinkPinDisclosure(!linkPinDisclosure)}
>
{linkPinDisclosure ? "Show Less" : "Show More"}
<FontAwesomeIcon
icon={faChevronDown}
className={`w-4 h-4 text-black dark:text-white ${
linkPinDisclosure ? "rotate-reverse" : "rotate"
}`}
/>
</button>
) : undefined}
<Link
href="/links/pinned"
className="text-black dark:text-white flex items-center gap-2 cursor-pointer"
>
View All
<FontAwesomeIcon
icon={faChevronRight}
className={`w-4 h-4 text-black dark:text-white`}
/>
</Link>
</div>
<div
style={{ flex: "1 1 auto" }}
style={{ flex: "0 1 auto" }}
className="flex flex-col 2xl:flex-row items-start 2xl:gap-2"
>
{links.some((e) => e.pinnedBy && e.pinnedBy[0]) ? (
{links[0] ? (
<div className="w-full">
<div
className={`grid overflow-hidden 2xl:grid-cols-3 xl:grid-cols-2 grid-cols-1 gap-5 w-full ${
linkPinDisclosure ? "h-full" : "max-h-[20rem]"
}`}
className={`grid overflow-hidden 2xl:grid-cols-3 xl:grid-cols-2 grid-cols-1 gap-5 w-full`}
>
{links
.filter((e) => e.pinnedBy && e.pinnedBy[0])
.map((e, i) => (
<LinkCard key={i} link={e} count={i} />
))}
.map((e, i) => <LinkCard key={i} link={e} count={i} />)
.slice(0, showLinks)}
</div>
</div>
) : (
+74
View File
@@ -0,0 +1,74 @@
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 { 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>(Sort.DateNewestFirst);
useLinks({ sort: sortBy, pinnedOnly: true });
return (
<MainLayout>
<div className="p-5 flex flex-col gap-5 w-full h-full">
<div className="flex gap-3 justify-between">
<div className="flex items-center gap-3">
<FontAwesomeIcon
icon={faThumbTack}
className="sm:w-10 sm:h-10 w-6 h-6 text-sky-500 dark:text-sky-500 drop-shadow"
/>
<div>
<p className="text-3xl capitalize text-black dark:text-white font-thin">
Pinned Links
</p>
<p className="text-black dark:text-white">
Pinned Links from your Collections
</p>
</div>
</div>
<div className="relative mt-2">
<div
onClick={() => setSortDropdown(!sortDropdown)}
id="sort-dropdown"
className="inline-flex rounded-md cursor-pointer hover:bg-slate-200 hover:dark:bg-neutral-700 duration-100 p-1"
>
<FontAwesomeIcon
icon={faSort}
id="sort-dropdown"
className="w-5 h-5 text-gray-500 dark:text-gray-300"
/>
</div>
{sortDropdown ? (
<SortDropdown
sortBy={sortBy}
setSort={setSortBy}
toggleSortDropdown={() => setSortDropdown(!sortDropdown)}
/>
) : null}
</div>
</div>
{links[0] ? (
<div className="grid 2xl:grid-cols-3 xl:grid-cols-2 grid-cols-1 gap-5">
{links.map((e, i) => {
return <LinkCard key={i} link={e} count={i} />;
})}
</div>
) : (
<NoLinksFound text="You Haven't Created Any Links Yet" />
)}
</div>
</MainLayout>
);
}
+1 -1
View File
@@ -334,7 +334,7 @@ export default function Account() {
</p>
{user.isPrivate && (
<div className="pl-5 border-l">
<div className="pl-5">
<p className="text-black dark:text-white mt-2">
Whitelisted Users
</p>