Display checkbox on card & reset when collection is changed
This commit is contained in:
parent
b51355b406
commit
eba9d3c86d
|
@ -24,13 +24,17 @@ type Props = {
|
||||||
flipDropdown?: boolean;
|
flipDropdown?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function LinkGrid({
|
export default function LinkCard({
|
||||||
link,
|
link,
|
||||||
flipDropdown,
|
flipDropdown,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
const { collections } = useCollectionStore();
|
const { collections } = useCollectionStore();
|
||||||
|
|
||||||
const { links, getLink } = useLinkStore();
|
const { links, getLink, setSelectedLinks, selectedLinks } = useLinkStore();
|
||||||
|
|
||||||
|
const handleCheckboxClick = (checkboxId: number) => {
|
||||||
|
setSelectedLinks((selectedLinks.includes(checkboxId) ? selectedLinks.filter((id) => id !== checkboxId) : [...selectedLinks, checkboxId]));
|
||||||
|
};
|
||||||
|
|
||||||
let shortendURL;
|
let shortendURL;
|
||||||
|
|
||||||
|
@ -85,6 +89,12 @@ export default function LinkGrid({
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className="border border-solid border-neutral-content bg-base-200 shadow-md hover:shadow-none duration-100 rounded-2xl relative"
|
className="border border-solid border-neutral-content bg-base-200 shadow-md hover:shadow-none duration-100 rounded-2xl relative"
|
||||||
>
|
>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
className="checkbox checkbox-primary my-auto ml-3 mt-3 fixed z-50 bg-white"
|
||||||
|
checked={selectedLinks.includes(link.id)}
|
||||||
|
onChange={() => handleCheckboxClick(link.id)}
|
||||||
|
/>
|
||||||
<Link
|
<Link
|
||||||
href={generateLinkHref(link)}
|
href={generateLinkHref(link)}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
|
|
|
@ -24,7 +24,6 @@ import CardView from "@/components/LinkViews/Layouts/CardView";
|
||||||
// import GridView from "@/components/LinkViews/Layouts/GridView";
|
// import GridView from "@/components/LinkViews/Layouts/GridView";
|
||||||
import ListView from "@/components/LinkViews/Layouts/ListView";
|
import ListView from "@/components/LinkViews/Layouts/ListView";
|
||||||
import { dropdownTriggerer } from "@/lib/client/utils";
|
import { dropdownTriggerer } from "@/lib/client/utils";
|
||||||
import Link from "next/link";
|
|
||||||
import NewCollectionModal from "@/components/ModalContent/NewCollectionModal";
|
import NewCollectionModal from "@/components/ModalContent/NewCollectionModal";
|
||||||
|
|
||||||
export default function Index() {
|
export default function Index() {
|
||||||
|
@ -81,6 +80,9 @@ export default function Index() {
|
||||||
};
|
};
|
||||||
|
|
||||||
fetchOwner();
|
fetchOwner();
|
||||||
|
|
||||||
|
// When the collection changes, reset the selected links
|
||||||
|
setSelectedLinks([]);
|
||||||
}, [activeCollection]);
|
}, [activeCollection]);
|
||||||
|
|
||||||
const [editCollectionModal, setEditCollectionModal] = useState(false);
|
const [editCollectionModal, setEditCollectionModal] = useState(false);
|
||||||
|
@ -294,9 +296,11 @@ export default function Index() {
|
||||||
onChange={() => handleSelectAll()}
|
onChange={() => handleSelectAll()}
|
||||||
checked={selectedLinks.length === links.length}
|
checked={selectedLinks.length === links.length}
|
||||||
/>
|
/>
|
||||||
{selectedLinks.length > 0 &&
|
{selectedLinks.length > 0 && (
|
||||||
<span>{selectedLinks.length} link selected</span>
|
<span>
|
||||||
}
|
{selectedLinks.length} {selectedLinks.length === 1 ? 'link' : 'links'} selected
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
{selectedLinks.length > 0 && permissions &&
|
{selectedLinks.length > 0 && permissions &&
|
||||||
<div className="flex gap-3">
|
<div className="flex gap-3">
|
||||||
|
|
Ŝarĝante…
Reference in New Issue