diff --git a/components/LinkViews/LinkCard.tsx b/components/LinkViews/LinkCard.tsx index 3cbaf25..8f5535c 100644 --- a/components/LinkViews/LinkCard.tsx +++ b/components/LinkViews/LinkCard.tsx @@ -18,6 +18,7 @@ import useOnScreen from "@/hooks/useOnScreen"; import { generateLinkHref } from "@/lib/client/generateLinkHref"; import useAccountStore from "@/store/account"; import usePermissions from "@/hooks/usePermissions"; +import toast from "react-hot-toast"; type Props = { link: LinkIncludingShortenedCollectionAndTags; @@ -97,15 +98,25 @@ export default function LinkCard({ link, flipDropdown, editMode }: Props) { ) ? "border-primary bg-base-300" : "border-neutral-content"; + const selectable = editMode && (permissions === true || permissions?.canCreate || permissions?.canDelete); + // const unselectableStyle = + // editMode && !selectable ? "pointer-events-none" : ""; + return (
selectable && handleCheckboxClick(link)} + onClick={() => + selectable + ? handleCheckboxClick(link) + : toast.error( + "You don't have permission to edit or delete this item." + ) + } > {!editMode ? ( <> diff --git a/components/LinkViews/LinkList.tsx b/components/LinkViews/LinkList.tsx index cf2a8db..4175827 100644 --- a/components/LinkViews/LinkList.tsx +++ b/components/LinkViews/LinkList.tsx @@ -49,7 +49,6 @@ export default function LinkCardCompact({ } }; - let shortendURL; try { @@ -82,6 +81,7 @@ export default function LinkCardCompact({ ) ? "border border-primary bg-base-300" : "border-transparent"; + const selectable = editMode && (permissions === true || permissions?.canCreate || permissions?.canDelete); diff --git a/components/ModalContent/EditCollectionSharingModal.tsx b/components/ModalContent/EditCollectionSharingModal.tsx index f54a3ed..9a73d5b 100644 --- a/components/ModalContent/EditCollectionSharingModal.tsx +++ b/components/ModalContent/EditCollectionSharingModal.tsx @@ -234,11 +234,8 @@ export default function EditCollectionSharingModal({ : undefined; return ( - <> -
+ +
@@ -433,7 +430,7 @@ export default function EditCollectionSharingModal({
- +
); })}
diff --git a/pages/collections/[id].tsx b/pages/collections/[id].tsx index 284c088..323e6e6 100644 --- a/pages/collections/[id].tsx +++ b/pages/collections/[id].tsx @@ -97,6 +97,11 @@ export default function Index() { const [bulkDeleteLinksModal, setBulkDeleteLinksModal] = useState(false); const [bulkEditLinksModal, setBulkEditLinksModal] = useState(false); const [editMode, setEditMode] = useState(false); + useEffect(() => { + return () => { + setEditMode(false); + }; + }, [router]); const [viewMode, setViewMode] = useState( localStorage.getItem("viewMode") || ViewMode.Card @@ -359,29 +364,31 @@ export default function Index() {
)}
- {(permissions === true || permissions?.canUpdate) && ( - - )} - {(permissions === true || permissions?.canDelete) && ( - - )} + +
)} diff --git a/pages/links/index.tsx b/pages/links/index.tsx index 3f5aadc..3d99a9c 100644 --- a/pages/links/index.tsx +++ b/pages/links/index.tsx @@ -14,6 +14,7 @@ import toast from "react-hot-toast"; import BulkDeleteLinksModal from "@/components/ModalContent/BulkDeleteLinksModal"; import BulkEditLinksModal from "@/components/ModalContent/BulkEditLinksModal"; // import GridView from "@/components/LinkViews/Layouts/GridView"; +import { useRouter } from "next/router"; export default function Links() { const { links, selectedLinks, deleteLinksById, setSelectedLinks } = @@ -24,9 +25,17 @@ export default function Links() { ); const [sortBy, setSortBy] = useState(Sort.DateNewestFirst); + const router = useRouter(); + const [bulkDeleteLinksModal, setBulkDeleteLinksModal] = useState(false); const [bulkEditLinksModal, setBulkEditLinksModal] = useState(false); const [editMode, setEditMode] = useState(false); + useEffect(() => { + return () => { + setEditMode(false); + }; + }, [router]); + const collectivePermissions = useCollectivePermissions( selectedLinks.map((link) => link.collectionId as number) ); @@ -71,7 +80,6 @@ export default function Links() { // @ts-ignore const LinkComponent = linkView[viewMode]; - console.log(collectivePermissions); return (
@@ -127,31 +135,37 @@ export default function Links() {
)}
- {(collectivePermissions === true || - collectivePermissions?.canUpdate) && ( - - )} - {(collectivePermissions === true || - collectivePermissions?.canDelete) && ( - - )} + +
)} diff --git a/pages/links/pinned.tsx b/pages/links/pinned.tsx index c9d285d..4e8cc62 100644 --- a/pages/links/pinned.tsx +++ b/pages/links/pinned.tsx @@ -2,7 +2,7 @@ import SortDropdown from "@/components/SortDropdown"; import useLinks from "@/hooks/useLinks"; import MainLayout from "@/layouts/MainLayout"; import useLinkStore from "@/store/links"; -import React, { useState } from "react"; +import React, { useEffect, useState } from "react"; import PageHeader from "@/components/PageHeader"; import { Sort, ViewMode } from "@/types/global"; import ViewDropdown from "@/components/ViewDropdown"; @@ -13,6 +13,7 @@ import BulkEditLinksModal from "@/components/ModalContent/BulkEditLinksModal"; import useCollectivePermissions from "@/hooks/useCollectivePermissions"; import toast from "react-hot-toast"; // import GridView from "@/components/LinkViews/Layouts/GridView"; +import { useRouter } from "next/router"; export default function PinnedLinks() { const { links, selectedLinks, deleteLinksById, setSelectedLinks } = @@ -25,9 +26,16 @@ export default function PinnedLinks() { useLinks({ sort: sortBy, pinnedOnly: true }); + const router = useRouter(); const [bulkDeleteLinksModal, setBulkDeleteLinksModal] = useState(false); const [bulkEditLinksModal, setBulkEditLinksModal] = useState(false); const [editMode, setEditMode] = useState(false); + useEffect(() => { + return () => { + setEditMode(false); + }; + }, [router]); + const collectivePermissions = useCollectivePermissions( selectedLinks.map((link) => link.collectionId as number) ); @@ -124,31 +132,37 @@ export default function PinnedLinks() { )}
- {(collectivePermissions === true || - collectivePermissions?.canUpdate) && ( - - )} - {(collectivePermissions === true || - collectivePermissions?.canDelete) && ( - - )} + +
)} diff --git a/pages/tags/[id].tsx b/pages/tags/[id].tsx index 5e6c7d4..8924a3c 100644 --- a/pages/tags/[id].tsx +++ b/pages/tags/[id].tsx @@ -33,6 +33,12 @@ export default function Index() { const [bulkDeleteLinksModal, setBulkDeleteLinksModal] = useState(false); const [bulkEditLinksModal, setBulkEditLinksModal] = useState(false); const [editMode, setEditMode] = useState(false); + useEffect(() => { + return () => { + setEditMode(false); + }; + }, [router]); + const collectivePermissions = useCollectivePermissions( selectedLinks.map((link) => link.collectionId as number) ); @@ -283,31 +289,37 @@ export default function Index() { )}
- {(collectivePermissions === true || - collectivePermissions?.canUpdate) && ( - - )} - {(collectivePermissions === true || - collectivePermissions?.canDelete) && ( - - )} + +
)}