⚡️⚡️⚡️ 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
final fixes
Isaac7ce78fc31471
diff --git a/apps/web/components/CollectionListing.tsx b/apps/web/components/CollectionListing.tsxindex bb63f60d..81480758 100644--- a/apps/web/components/CollectionListing.tsx+++ b/apps/web/components/CollectionListing.tsx@@ -57,7 +57,7 @@ const CollectionListing = () => {useEffect(() => {if (user?.username) {- refetch();+ // refetch();if ((!user.collectionOrder || user.collectionOrder.length === 0) &&collections.length > 0@@ -297,11 +297,10 @@ const renderItem = (return (<div ref={provided.innerRef} {...provided.draggableProps} className="mb-1"><div- className={`${- currentPath === `/collections/${collection.id}`+ className={`${currentPath === `/collections/${collection.id}`? "bg-primary/20 is-active": "hover:bg-neutral/20"- } duration-100 flex gap-1 items-center pr-2 pl-1 rounded-md`}+ } duration-100 flex gap-1 items-center pr-2 pl-1 rounded-md`}>{Dropdown(item as ExtendedTreeItem, onExpand, onCollapse)}diff --git a/apps/web/components/DashboardLayoutDropdown.tsx b/apps/web/components/DashboardLayoutDropdown.tsxindex decedf37..aeb75605 100644--- a/apps/web/components/DashboardLayoutDropdown.tsx+++ b/apps/web/components/DashboardLayoutDropdown.tsx@@ -183,7 +183,7 @@ export default function DashboardLayoutDropdown() {updateDashboardLayout.mutateAsync(updatedSections);},});- }, [filteredSections, updateDashboardLayout]);+ }, [filteredSections]);const handleCheckboxChange = (section: DashboardSectionOption) => {const enabledSections = allSections.filter((s) => s.enabled);@@ -314,9 +314,8 @@ function DraggableListItem({onChange={() => onCheckboxChange(section)}/><label- htmlFor={`section-${section.type}-${- section.collectionId || "default"- }`}+ htmlFor={`section-${section.type}-${section.collectionId || "default"+ }`}className="text-sm select-none">{section.name}@@ -324,9 +323,8 @@ function DraggableListItem({</div><i- className={`bi-grip-vertical text-neutral ${- section.enabled ? "cursor-grab" : "opacity-50"- }`}+ className={`bi-grip-vertical text-neutral ${section.enabled ? "cursor-grab" : "opacity-50"+ }`}/></li>);diff --git a/apps/web/lib/api/controllers/dashboard/updateDashboardLayout.ts b/apps/web/lib/api/controllers/dashboard/updateDashboardLayout.tsindex 1954f6bb..8f811fcd 100644--- a/apps/web/lib/api/controllers/dashboard/updateDashboardLayout.ts+++ b/apps/web/lib/api/controllers/dashboard/updateDashboardLayout.ts@@ -14,9 +14,8 @@ export default async function updateDashboardLayout(if (!dataValidation.success) {console.log(dataValidation.error.issues[0].message);return {- response: `Error: ${- dataValidation.error.issues[0].message- } [${dataValidation.error.issues[0].path.join(", ")}]`,+ response: `Error: ${dataValidation.error.issues[0].message+ } [${dataValidation.error.issues[0].path.join(", ")}]`,status: 400,};}@@ -40,20 +39,33 @@ export default async function updateDashboardLayout(DashboardSection,"userId" | "type" | "collectionId" | "order">[] = [];- const sectionsToUpdate: Partial<DashboardSection>[] = [];- const sectionsToDelete: number[] = [];+ const sectionsToUpdate: Array<{+ id: number;+ newOrder: number;+ oldOrder: number;+ }> = [];+ const sectionsToDelete: Array<{+ id: number;+ order: number;+ }> = [];for (const section of data) {const key = `${section.type}-${section.collectionId || "default"}`;const existingSection = existingSectionsMap.get(key);if (existingSection && !section.enabled) {- sectionsToDelete.push(existingSection.id);- } else if (existingSection && section.enabled) {- sectionsToUpdate.push({+ sectionsToDelete.push({id: existingSection.id,- order: section.order,+ order: existingSection.order,});+ } else if (existingSection && section.enabled) {+ if (existingSection.order !== section.order) {+ sectionsToUpdate.push({+ id: existingSection.id,+ newOrder: section.order!,+ oldOrder: existingSection.order,+ });+ }} else if (section.enabled) {sectionsToCreate.push({userId: userId,@@ -65,25 +77,76 @@ export default async function updateDashboardLayout(}await prisma.$transaction(async (tx) => {- if (sectionsToDelete.length > 0) {- await tx.dashboardSection.deleteMany({+ for (const sectionToDelete of sectionsToDelete) {+ await tx.dashboardSection.delete({+ where: {+ id: sectionToDelete.id,+ },+ });++ // Decrement order for all sections with order greater than deleted section+ await tx.dashboardSection.updateMany({where: {- id: {- in: sectionsToDelete,+ userId,+ order: {+ gt: sectionToDelete.order,+ },+ },+ data: {+ order: {+ decrement: 1,},},});}- if (sectionsToUpdate.length > 0) {- await Promise.all(- sectionsToUpdate.map((section: any) =>- tx.dashboardSection.update({- where: { id: section.id },- data: { order: section.order },- })- )- );+ // Handle order updates - need to be careful about conflicts+ for (const sectionToUpdate of sectionsToUpdate) {+ const { id, newOrder, oldOrder } = sectionToUpdate;++ if (newOrder > oldOrder) {+ // Moving down: decrement order for sections between oldOrder and newOrder+ await tx.dashboardSection.updateMany({+ where: {+ userId,+ order: {+ gt: oldOrder,+ lte: newOrder,+ },+ id: {+ not: id,+ },+ },+ data: {+ order: {+ decrement: 1,+ },+ },+ });+ } else if (newOrder < oldOrder) {+ await tx.dashboardSection.updateMany({+ where: {+ userId,+ order: {+ gte: newOrder,+ lt: oldOrder,+ },+ id: {+ not: id,+ },+ },+ data: {+ order: {+ increment: 1,+ },+ },+ });+ }++ await tx.dashboardSection.update({+ where: { id },+ data: { order: newOrder },+ });}if (sectionsToCreate.length > 0) {@@ -97,4 +160,4 @@ export default async function updateDashboardLayout(status: 200,response: data,};-}+}\ No newline at end of filediff --git a/apps/web/lib/api/controllers/users/userId/updateUserById.ts b/apps/web/lib/api/controllers/users/userId/updateUserById.tsindex fec89e00..ccca68eb 100644--- a/apps/web/lib/api/controllers/users/userId/updateUserById.ts+++ b/apps/web/lib/api/controllers/users/userId/updateUserById.ts@@ -17,9 +17,8 @@ export default async function updateUserById(if (!dataValidation.success) {return {- response: `Error: ${- dataValidation.error.issues[0].message- } [${dataValidation.error.issues[0].path.join(", ")}]`,+ response: `Error: ${dataValidation.error.issues[0].message+ } [${dataValidation.error.issues[0].path.join(", ")}]`,status: 400,};}@@ -31,18 +30,18 @@ export default async function updateUserById(id: { not: userId },OR: emailEnabled? [- {- username: data.username.toLowerCase(),- },- {- email: data.email?.toLowerCase(),- },- ]+ {+ username: data.username.toLowerCase(),+ },+ {+ email: data.email?.toLowerCase(),+ },+ ]: [- {- username: data.username.toLowerCase(),- },- ],+ {+ username: data.username.toLowerCase(),+ },+ ],},});@@ -220,6 +219,7 @@ export default async function updateUserById(include: {whitelistedUsers: true,subscriptions: true,+ dashboardSections: true,parentSubscription: {include: {user: true,@@ -232,6 +232,7 @@ export default async function updateUserById(whitelistedUsers,password,subscriptions,+ dashboardSections,parentSubscription,...userInfo} = updatedUser;@@ -289,6 +290,7 @@ export default async function updateUserById(email: parentSubscription?.user.email,},},+ dashboardSections: dashboardSections,};return { response, status: 200 };diff --git a/apps/web/pages/dashboard.tsx b/apps/web/pages/dashboard.tsxindex 5f1b8907..f6de3268 100644--- a/apps/web/pages/dashboard.tsx+++ b/apps/web/pages/dashboard.tsx@@ -57,7 +57,7 @@ export default function Dashboard() {user.referredBy === null &&// if user is using Linkwarden for more than 3 daysnew Date().getTime() - new Date(user.createdAt).getTime() >- 3 * 24 * 60 * 60 * 1000+ 3 * 24 * 60 * 60 * 1000) {setTimeout(() => {setShowsSurveyModal(true);@@ -340,7 +340,7 @@ export default function Dashboard() {/></div>) : links?.filter((link: any) => link.collection.id === collection.id)- .length > 0 ? (+ .length > 0 ? (<div className="w-full"><Linkslinks={linksdiff --git a/packages/router/collections.tsx b/packages/router/collections.tsxindex ab9e2da1..00cd591e 100644--- a/packages/router/collections.tsx+++ b/packages/router/collections.tsx@@ -100,11 +100,22 @@ const useDeleteCollection = () => {return data.response;},- onSuccess: (data) => {- // Need to get the updated dashboard order- queryClient.invalidateQueries({ queryKey: ["user"] });- return queryClient.setQueryData(["collections"], (oldData: any) => {- return oldData.filter((collection: any) => collection.id !== data.id);+ onSuccess: (data, id) => {+ queryClient.setQueryData(["collections"], (oldData: any) => {+ return oldData.filter((collection: any) => collection.id !== id);+ });++ // Update dashboardData query data+ queryClient.setQueryData(["dashboardData"], (oldData: any) => {+ if (!oldData) return oldData;++ return {+ ...oldData,+ links: oldData.links?.filter((link: any) => link.collectionId !== id) || [],+ numberOfPinnedLinks: oldData.links?.filter((link: any) =>+ link.collectionId !== id && link.isPinned+ ).length || 0+ };});},});diff --git a/packages/router/dashboardData.tsx b/packages/router/dashboardData.tsxindex c8789f16..4f772f2d 100644--- a/packages/router/dashboardData.tsx+++ b/packages/router/dashboardData.tsx@@ -41,7 +41,6 @@ const useUpdateDashboardLayout = () => {const previousData = queryClient.getQueryData(["user"]);- console.log("newData", newData);queryClient.setQueryData(["user"], (oldData: any) => {return {...oldData,