Pass the entire link to the store & fix bulk update function
This commit is contained in:
@@ -35,10 +35,16 @@ export default function LinkCard({
|
||||
|
||||
const { links, getLink, setSelectedLinks, selectedLinks } = useLinkStore();
|
||||
|
||||
const handleCheckboxClick = (checkboxId: number) => {
|
||||
setSelectedLinks((selectedLinks.includes(checkboxId) ? selectedLinks.filter((id) => id !== checkboxId) : [...selectedLinks, checkboxId]));
|
||||
const handleCheckboxClick = (link: LinkIncludingShortenedCollectionAndTags) => {
|
||||
if (selectedLinks.includes(link)) {
|
||||
setSelectedLinks(selectedLinks.filter((e) => e !== link));
|
||||
} else {
|
||||
setSelectedLinks([...selectedLinks, link]);
|
||||
}
|
||||
};
|
||||
|
||||
console.log(selectedLinks)
|
||||
|
||||
let shortendURL;
|
||||
|
||||
try {
|
||||
@@ -96,8 +102,8 @@ export default function LinkCard({
|
||||
<input
|
||||
type="checkbox"
|
||||
className="checkbox checkbox-primary my-auto ml-3 mt-3 absolute z-20 bg-white dark:bg-base-200"
|
||||
checked={selectedLinks.includes(link.id)}
|
||||
onChange={() => handleCheckboxClick(link.id)}
|
||||
checked={selectedLinks.includes(link)}
|
||||
onChange={() => handleCheckboxClick(link)}
|
||||
/>
|
||||
}
|
||||
<Link
|
||||
|
||||
@@ -13,7 +13,7 @@ export default function BulkDeleteLinksModal({ onClose }: Props) {
|
||||
const deleteLink = async () => {
|
||||
const load = toast.loading(`Deleting ${selectedLinks.length} Link${selectedLinks.length > 1 ? "s" : ""}...`);
|
||||
|
||||
const response = await deleteLinksById(selectedLinks);
|
||||
const response = await deleteLinksById(selectedLinks.map(link => link.id));
|
||||
|
||||
toast.dismiss(load);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user