2023-11-11 13:57:46 -06:00
|
|
|
import SortDropdown from "@/components/SortDropdown";
|
|
|
|
import useLinks from "@/hooks/useLinks";
|
|
|
|
import MainLayout from "@/layouts/MainLayout";
|
|
|
|
import useLinkStore from "@/store/links";
|
2024-02-13 09:55:51 -06:00
|
|
|
import React, { useEffect, useState } from "react";
|
2023-12-16 09:33:33 -06:00
|
|
|
import PageHeader from "@/components/PageHeader";
|
2023-12-17 00:25:46 -06:00
|
|
|
import { Sort, ViewMode } from "@/types/global";
|
|
|
|
import ViewDropdown from "@/components/ViewDropdown";
|
2023-12-21 04:08:56 -06:00
|
|
|
import CardView from "@/components/LinkViews/Layouts/CardView";
|
|
|
|
import ListView from "@/components/LinkViews/Layouts/ListView";
|
2024-02-11 01:06:46 -06:00
|
|
|
import BulkDeleteLinksModal from "@/components/ModalContent/BulkDeleteLinksModal";
|
|
|
|
import BulkEditLinksModal from "@/components/ModalContent/BulkEditLinksModal";
|
|
|
|
import useCollectivePermissions from "@/hooks/useCollectivePermissions";
|
|
|
|
import toast from "react-hot-toast";
|
2024-02-13 09:55:51 -06:00
|
|
|
import { useRouter } from "next/router";
|
2024-04-23 20:48:15 -05:00
|
|
|
import MasonryView from "@/components/LinkViews/Layouts/MasonryView";
|
2023-11-11 13:57:46 -06:00
|
|
|
|
|
|
|
export default function PinnedLinks() {
|
2024-02-11 01:29:11 -06:00
|
|
|
const { links, selectedLinks, deleteLinksById, setSelectedLinks } =
|
|
|
|
useLinkStore();
|
2023-11-11 13:57:46 -06:00
|
|
|
|
2023-12-17 00:25:46 -06:00
|
|
|
const [viewMode, setViewMode] = useState<string>(
|
2023-12-21 09:55:07 -06:00
|
|
|
localStorage.getItem("viewMode") || ViewMode.Card
|
2023-12-17 00:25:46 -06:00
|
|
|
);
|
2023-11-11 13:57:46 -06:00
|
|
|
const [sortBy, setSortBy] = useState<Sort>(Sort.DateNewestFirst);
|
|
|
|
|
|
|
|
useLinks({ sort: sortBy, pinnedOnly: true });
|
|
|
|
|
2024-02-13 09:55:51 -06:00
|
|
|
const router = useRouter();
|
2024-02-11 01:06:46 -06:00
|
|
|
const [bulkDeleteLinksModal, setBulkDeleteLinksModal] = useState(false);
|
|
|
|
const [bulkEditLinksModal, setBulkEditLinksModal] = useState(false);
|
|
|
|
const [editMode, setEditMode] = useState(false);
|
2024-03-06 08:06:38 -06:00
|
|
|
|
2024-02-13 09:55:51 -06:00
|
|
|
useEffect(() => {
|
2024-03-06 08:06:38 -06:00
|
|
|
if (editMode) return setEditMode(false);
|
2024-02-13 09:55:51 -06:00
|
|
|
}, [router]);
|
|
|
|
|
2024-02-11 01:29:11 -06:00
|
|
|
const collectivePermissions = useCollectivePermissions(
|
2024-02-13 04:54:18 -06:00
|
|
|
selectedLinks.map((link) => link.collectionId as number)
|
2024-02-11 01:29:11 -06:00
|
|
|
);
|
2024-02-11 01:06:46 -06:00
|
|
|
|
|
|
|
const handleSelectAll = () => {
|
|
|
|
if (selectedLinks.length === links.length) {
|
|
|
|
setSelectedLinks([]);
|
|
|
|
} else {
|
|
|
|
setSelectedLinks(links.map((link) => link));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const bulkDeleteLinks = async () => {
|
|
|
|
const load = toast.loading(
|
2024-04-23 20:53:33 -05:00
|
|
|
`Deleting ${selectedLinks.length} Link${
|
|
|
|
selectedLinks.length > 1 ? "s" : ""
|
2024-02-11 01:06:46 -06:00
|
|
|
}...`
|
|
|
|
);
|
|
|
|
|
|
|
|
const response = await deleteLinksById(
|
|
|
|
selectedLinks.map((link) => link.id as number)
|
|
|
|
);
|
|
|
|
|
|
|
|
toast.dismiss(load);
|
|
|
|
|
|
|
|
response.ok &&
|
|
|
|
toast.success(
|
2024-04-23 20:53:33 -05:00
|
|
|
`Deleted ${selectedLinks.length} Link${
|
|
|
|
selectedLinks.length > 1 ? "s" : ""
|
2024-02-11 01:06:46 -06:00
|
|
|
}!`
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2023-12-17 00:25:46 -06:00
|
|
|
const linkView = {
|
2023-12-21 09:55:07 -06:00
|
|
|
[ViewMode.Card]: CardView,
|
2023-12-17 00:25:46 -06:00
|
|
|
[ViewMode.List]: ListView,
|
2024-04-23 20:48:15 -05:00
|
|
|
[ViewMode.Masonry]: MasonryView,
|
2023-12-17 00:25:46 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
const LinkComponent = linkView[viewMode];
|
|
|
|
|
2023-11-11 13:57:46 -06:00
|
|
|
return (
|
|
|
|
<MainLayout>
|
|
|
|
<div className="p-5 flex flex-col gap-5 w-full h-full">
|
2023-12-17 22:32:33 -06:00
|
|
|
<div className="flex justify-between">
|
|
|
|
<PageHeader
|
|
|
|
icon={"bi-pin-angle"}
|
|
|
|
title={"Pinned Links"}
|
|
|
|
description={"Pinned Links from your Collections"}
|
|
|
|
/>
|
|
|
|
<div className="mt-2 flex items-center justify-end gap-2">
|
2024-02-13 04:54:18 -06:00
|
|
|
{!(links.length === 0) && (
|
2024-02-11 01:08:28 -06:00
|
|
|
<div
|
|
|
|
role="button"
|
|
|
|
onClick={() => {
|
2024-02-11 01:29:11 -06:00
|
|
|
setEditMode(!editMode);
|
|
|
|
setSelectedLinks([]);
|
2024-02-11 01:08:28 -06:00
|
|
|
}}
|
2024-04-23 20:53:33 -05:00
|
|
|
className={`btn btn-square btn-sm btn-ghost ${
|
|
|
|
editMode
|
2024-02-22 03:15:14 -06:00
|
|
|
? "bg-primary/20 hover:bg-primary/20"
|
|
|
|
: "hover:bg-neutral/20"
|
2024-04-23 20:53:33 -05:00
|
|
|
}`}
|
2024-02-11 01:08:28 -06:00
|
|
|
>
|
|
|
|
<i className="bi-pencil-fill text-neutral text-xl"></i>
|
|
|
|
</div>
|
|
|
|
)}
|
2023-12-17 22:32:33 -06:00
|
|
|
<SortDropdown sortBy={sortBy} setSort={setSortBy} />
|
|
|
|
<ViewDropdown viewMode={viewMode} setViewMode={setViewMode} />
|
|
|
|
</div>
|
2023-11-11 13:57:46 -06:00
|
|
|
</div>
|
2023-12-17 02:47:32 -06:00
|
|
|
|
2024-02-22 03:15:14 -06:00
|
|
|
{editMode && links.length > 0 && (
|
2024-02-11 02:48:34 -06:00
|
|
|
<div className="w-full flex justify-between items-center min-h-[32px]">
|
|
|
|
{links.length > 0 && (
|
|
|
|
<div className="flex gap-3 ml-3">
|
|
|
|
<input
|
|
|
|
type="checkbox"
|
|
|
|
className="checkbox checkbox-primary"
|
|
|
|
onChange={() => handleSelectAll()}
|
|
|
|
checked={
|
|
|
|
selectedLinks.length === links.length && links.length > 0
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
{selectedLinks.length > 0 ? (
|
|
|
|
<span>
|
|
|
|
{selectedLinks.length}{" "}
|
|
|
|
{selectedLinks.length === 1 ? "link" : "links"} selected
|
|
|
|
</span>
|
|
|
|
) : (
|
|
|
|
<span>Nothing selected</span>
|
|
|
|
)}
|
|
|
|
</div>
|
2024-02-11 02:38:41 -06:00
|
|
|
)}
|
2024-02-11 02:48:34 -06:00
|
|
|
<div className="flex gap-3">
|
2024-02-13 09:55:51 -06:00
|
|
|
<button
|
|
|
|
onClick={() => setBulkEditLinksModal(true)}
|
|
|
|
className="btn btn-sm btn-accent text-white w-fit ml-auto"
|
|
|
|
disabled={
|
|
|
|
selectedLinks.length === 0 ||
|
|
|
|
!(
|
|
|
|
collectivePermissions === true ||
|
|
|
|
collectivePermissions?.canUpdate
|
|
|
|
)
|
|
|
|
}
|
|
|
|
>
|
|
|
|
Edit
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
onClick={(e) => {
|
|
|
|
(document?.activeElement as HTMLElement)?.blur();
|
|
|
|
e.shiftKey
|
|
|
|
? bulkDeleteLinks()
|
|
|
|
: setBulkDeleteLinksModal(true);
|
|
|
|
}}
|
2024-05-24 18:13:04 -05:00
|
|
|
className="btn btn-sm bg-red-500 hover:bg-red-400 text-white w-fit ml-auto"
|
2024-02-13 09:55:51 -06:00
|
|
|
disabled={
|
|
|
|
selectedLinks.length === 0 ||
|
|
|
|
!(
|
|
|
|
collectivePermissions === true ||
|
|
|
|
collectivePermissions?.canDelete
|
|
|
|
)
|
|
|
|
}
|
|
|
|
>
|
|
|
|
Delete
|
|
|
|
</button>
|
2024-02-11 02:48:34 -06:00
|
|
|
</div>
|
2024-02-11 01:06:46 -06:00
|
|
|
</div>
|
2024-02-11 02:48:34 -06:00
|
|
|
)}
|
2024-02-11 01:06:46 -06:00
|
|
|
|
2023-11-11 15:06:50 -06:00
|
|
|
{links.some((e) => e.pinnedBy && e.pinnedBy[0]) ? (
|
2024-02-11 01:06:46 -06:00
|
|
|
<LinkComponent editMode={editMode} links={links} />
|
2023-11-11 13:57:46 -06:00
|
|
|
) : (
|
2023-11-11 15:06:50 -06:00
|
|
|
<div
|
|
|
|
style={{ flex: "1 1 auto" }}
|
2024-05-24 18:13:04 -05:00
|
|
|
className="flex flex-col gap-2 justify-center h-full w-full mx-auto p-10"
|
2023-11-11 15:06:50 -06:00
|
|
|
>
|
2024-05-24 18:13:04 -05:00
|
|
|
<svg
|
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
className="w-1/4 min-w-[7rem] max-w-[15rem] h-auto mx-auto mb-5 text-primary drop-shadow"
|
|
|
|
fill="currentColor"
|
|
|
|
viewBox="0 0 16 16"
|
|
|
|
>
|
|
|
|
<path d="M4.146.146A.5.5 0 0 1 4.5 0h7a.5.5 0 0 1 .5.5c0 .68-.342 1.174-.646 1.479-.126.125-.25.224-.354.298v4.431l.078.048c.203.127.476.314.751.555C12.36 7.775 13 8.527 13 9.5a.5.5 0 0 1-.5.5h-4v4.5c0 .276-.224 1.5-.5 1.5s-.5-1.224-.5-1.5V10h-4a.5.5 0 0 1-.5-.5c0-.973.64-1.725 1.17-2.189A6 6 0 0 1 5 6.708V2.277a3 3 0 0 1-.354-.298C4.342 1.674 4 1.179 4 .5a.5.5 0 0 1 .146-.354m1.58 1.408-.002-.001zm-.002-.001.002.001A.5.5 0 0 1 6 2v5a.5.5 0 0 1-.276.447h-.002l-.012.007-.054.03a5 5 0 0 0-.827.58c-.318.278-.585.596-.725.936h7.792c-.14-.34-.407-.658-.725-.936a5 5 0 0 0-.881-.61l-.012-.006h-.002A.5.5 0 0 1 10 7V2a.5.5 0 0 1 .295-.458 1.8 1.8 0 0 0 .351-.271c.08-.08.155-.17.214-.271H5.14q.091.15.214.271a1.8 1.8 0 0 0 .37.282" />
|
|
|
|
</svg>
|
2023-11-24 07:39:55 -06:00
|
|
|
<p className="text-center text-2xl">
|
2023-11-11 15:06:50 -06:00
|
|
|
Pin Your Favorite Links Here!
|
|
|
|
</p>
|
2024-05-24 18:13:04 -05:00
|
|
|
<p className="text-center mx-auto max-w-96 w-fit text-neutral text-sm">
|
2023-11-11 15:06:50 -06:00
|
|
|
You can Pin your favorite Links by clicking on the three dots on
|
|
|
|
each Link and clicking{" "}
|
|
|
|
<span className="font-semibold">Pin to Dashboard</span>.
|
|
|
|
</p>
|
|
|
|
</div>
|
2023-11-11 13:57:46 -06:00
|
|
|
)}
|
|
|
|
</div>
|
2024-02-11 01:06:46 -06:00
|
|
|
{bulkDeleteLinksModal && (
|
|
|
|
<BulkDeleteLinksModal
|
|
|
|
onClose={() => {
|
|
|
|
setBulkDeleteLinksModal(false);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{bulkEditLinksModal && (
|
2024-02-11 01:29:11 -06:00
|
|
|
<BulkEditLinksModal
|
|
|
|
onClose={() => {
|
|
|
|
setBulkEditLinksModal(false);
|
|
|
|
}}
|
|
|
|
/>
|
2024-02-11 01:06:46 -06:00
|
|
|
)}
|
2023-11-11 13:57:46 -06:00
|
|
|
</MainLayout>
|
|
|
|
);
|
|
|
|
}
|