⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.
TypeScript bookmarkbookmark-managercollaborationnextjsreact-nativeread-it-laterself-hostedtypescript
Fix sorting links when editing and handle not providing any data
Isaac Wise63597a041fdb
diff --git a/components/InputSelect/CollectionSelection.tsx b/components/InputSelect/CollectionSelection.tsxindex 0d98bd65..cac9c46b 100644--- a/components/InputSelect/CollectionSelection.tsx+++ b/components/InputSelect/CollectionSelection.tsx@@ -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"/>);}diff --git a/components/LinkViews/LinkList.tsx b/components/LinkViews/LinkList.tsxindex 78f5cb78..df899def 100644--- a/components/LinkViews/LinkList.tsx+++ b/components/LinkViews/LinkList.tsx@@ -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({<inputtype="checkbox"className="checkbox checkbox-primary my-auto mr-2"- checked={selectedLinks.includes(link)}+ checked={selectedLinks.some(selectedLink => selectedLink.id === link.id)}onChange={() => handleCheckboxClick(link)}/>)}diff --git a/components/ModalContent/BulkEditLinksModal.tsx b/components/ModalContent/BulkEditLinksModal.tsxindex c161f93e..f274f736 100644--- a/components/ModalContent/BulkEditLinksModal.tsx+++ b/components/ModalContent/BulkEditLinksModal.tsx@@ -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>diff --git a/hooks/useLinks.tsx b/hooks/useLinks.tsxindex 77e4dce7..fde8bbb5 100644--- a/hooks/useLinks.tsx+++ b/hooks/useLinks.tsx@@ -18,7 +18,7 @@ export default function useLinks(searchByTextContent,}: LinkRequestQuery = { sort: 0 }) {- const { links, setLinks, resetLinks } = useLinkStore();+ const { links, setLinks, resetLinks, selectedLinks, setSelectedLinks } = useLinkStore();const router = useRouter();const { reachedBottom, setReachedBottom } = useDetectPageBottom();@@ -68,8 +68,12 @@ export default function useLinks(};useEffect(() => {+ // Save the selected links before resetting the links+ // and then restore the selected links after resetting the links+ const previouslySelected = selectedLinksresetLinks();+ setSelectedLinks(previouslySelected);getLinks(true);}, [router,diff --git a/pages/collections/[id].tsx b/pages/collections/[id].tsxindex 0a5196a7..1b626e60 100644--- a/pages/collections/[id].tsx+++ b/pages/collections/[id].tsx@@ -170,7 +170,7 @@ export default function Index() {<i className="bi-three-dots text-xl" title="More"></i></div><ul className="dropdown-content z-[30] menu shadow bg-base-200 border border-neutral-content rounded-box w-52 mt-1">- {permissions === true ? (+ {permissions === true && (<li><divrole="button"@@ -183,7 +183,7 @@ export default function Index() {Edit Collection Info</div></li>- ) : undefined}+ )}<li><divrole="button"@@ -198,7 +198,7 @@ export default function Index() {: "View Team"}</div></li>- {permissions === true ? (+ {permissions === true && (<li><divrole="button"@@ -211,7 +211,7 @@ export default function Index() {Create Sub-Collection</div></li>- ) : undefined}+ )}<li><divrole="button"@@ -231,7 +231,7 @@ export default function Index() {</div>)}- {activeCollection ? (+ {activeCollection && (<div className={`min-w-[15rem]`}><div className="flex gap-1 justify-center sm:justify-end items-center w-fit"><div@@ -267,18 +267,16 @@ export default function Index() {</div><p className="text-neutral text-sm font-semibold">By {collectionOwner.name}- {activeCollection.members.length > 0- ? ` and ${activeCollection.members.length} others`- : undefined}- .+ {activeCollection.members.length > 0 &&+ ` and ${activeCollection.members.length} others`}.</p></div></div>- ) : undefined}+ )}- {activeCollection?.description ? (+ {activeCollection?.description && (<p>{activeCollection?.description}</p>- ) : undefined}+ )}{/* {collections.some((e) => e.parentId === activeCollection.id) ? (<fieldset className="border rounded-md p-2 border-neutral-content">diff --git a/pages/tags/[id].tsx b/pages/tags/[id].tsxindex e2c97721..0a290ba2 100644--- a/pages/tags/[id].tsx+++ b/pages/tags/[id].tsx@@ -258,11 +258,13 @@ export default function Index() {selectedLinks.length === links.length && links.length > 0}/>- {selectedLinks.length > 0 && (+ {selectedLinks.length > 0 ? (<span>{selectedLinks.length}{" "}{selectedLinks.length === 1 ? "link" : "links"} selected</span>+ ) : (+ <span>Nothing selected</span>)}</div>)}@@ -302,11 +304,17 @@ export default function Index() {</div>{bulkDeleteLinksModal && (<BulkDeleteLinksModal- onClose={() => setBulkDeleteLinksModal(false)}+ onClose={() => {+ setBulkDeleteLinksModal(false);+ setEditMode(false);+ }}/>)}{bulkEditLinksModal && (- <BulkEditLinksModal onClose={() => setBulkEditLinksModal(false)} />+ <BulkEditLinksModal onClose={() => {+ setBulkEditLinksModal(false);+ setEditMode(false);+ }} />)}</MainLayout>);diff --git a/store/links.ts b/store/links.tsindex 2f2d4f63..6aa8e027 100644--- a/store/links.ts+++ b/store/links.ts@@ -148,7 +148,7 @@ const useLinkStore = create<LinkStore>()((set) => ({if (response.ok) {set((state) => ({links: state.links.map((e) =>- links.some((link) => link.id === e.id) ? { ...e, ...newData } : e+ links.some((link) => link.id === e.id) ? { ...e, tags: [...e.tags, ...(newData.tags ?? [])] } : e),}));useTagStore.getState().setTags();