Fix sorting links when editing and handle not providing any data

This commit is contained in:
Isaac Wise
2024-02-11 01:01:52 -06:00
parent e753f1dded
commit 63597a041f
7 changed files with 45 additions and 32 deletions
@@ -7,15 +7,16 @@ import CreatableSelect from "react-select/creatable";
type Props = {
onChange: any;
showDefaultValue?: boolean;
defaultValue?:
| {
label: string;
value?: number;
}
| undefined;
| {
label: string;
value?: number;
}
| undefined;
};
export default function CollectionSelection({ onChange, defaultValue }: Props) {
export default function CollectionSelection({ onChange, defaultValue, showDefaultValue = true }: Props) {
const { collections } = useCollectionStore();
const router = useRouter();
@@ -50,8 +51,8 @@ export default function CollectionSelection({ onChange, defaultValue }: Props) {
onChange={onChange}
options={options}
styles={styles}
defaultValue={defaultValue}
// menuPosition="fixed"
defaultValue={showDefaultValue ? defaultValue : null}
// menuPosition="fixed"
/>
);
}
+8 -6
View File
@@ -35,11 +35,13 @@ export default function LinkCardCompact({
const { account } = useAccountStore();
const { links, setSelectedLinks, selectedLinks } = useLinkStore();
const handleCheckboxClick = (
link: LinkIncludingShortenedCollectionAndTags
) => {
if (selectedLinks.includes(link)) {
setSelectedLinks(selectedLinks.filter((e) => e !== link));
const handleCheckboxClick = (link: LinkIncludingShortenedCollectionAndTags) => {
const linkIndex = selectedLinks.findIndex(selectedLink => selectedLink.id === link.id);
if (linkIndex !== -1) {
const updatedLinks = [...selectedLinks];
updatedLinks.splice(linkIndex, 1);
setSelectedLinks(updatedLinks);
} else {
setSelectedLinks([...selectedLinks, link]);
}
@@ -85,7 +87,7 @@ export default function LinkCardCompact({
<input
type="checkbox"
className="checkbox checkbox-primary my-auto mr-2"
checked={selectedLinks.includes(link)}
checked={selectedLinks.some(selectedLink => selectedLink.id === link.id)}
onChange={() => handleCheckboxClick(link)}
/>
)}
@@ -57,7 +57,7 @@ export default function BulkEditLinksModal({ onClose }: Props) {
<div className="grid sm:grid-cols-2 gap-3">
<div>
<p className="mb-2">Collection</p>
<CollectionSelection onChange={setCollection} />
<CollectionSelection showDefaultValue={false} onChange={setCollection} />
</div>
<div>