⚡️⚡️⚡️ 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
Better drag and drop
Isaac8b6ded9179f4
diff --git a/apps/web/components/DashboardLayoutDropdown.tsx b/apps/web/components/DashboardLayoutDropdown.tsxindex 5a18b472..69538aab 100644--- a/apps/web/components/DashboardLayoutDropdown.tsx+++ b/apps/web/components/DashboardLayoutDropdown.tsx@@ -37,6 +37,7 @@ export default function DashboardLayoutDropdown() {const updateDashboardLayout = useUpdateDashboardLayout();const [searchTerm, setSearchTerm] = useState("");const [draggedItem, setDraggedItem] = useState<string | null>(null);+ const [dragOverItem, setDragOverItem] = useState<string | null>(null);const dashboardSections: DashboardSection[] = user?.dashboardSections || [];@@ -139,8 +140,6 @@ export default function DashboardLayoutDropdown() {const getSectionId = (section: DashboardSectionOption) =>`${section.type}-${section.collectionId || "default"}`;- // Set up drag and drop- // Improve this visuallyuseEffect(() => {return monitorForElements({onDrop({ source, location }) {@@ -233,7 +232,9 @@ export default function DashboardLayoutDropdown() {section={section}onCheckboxChange={handleCheckboxChange}isDragged={draggedItem === getSectionId(section)}+ isDraggingOver={dragOverItem === getSectionId(section)}setDraggedItem={setDraggedItem}+ setDragOverItem={setDragOverItem}/>))}@@ -253,14 +254,18 @@ interface DraggableListItemProps {section: DashboardSectionOption;onCheckboxChange: (section: DashboardSectionOption) => void;isDragged: boolean;+ isDraggingOver: boolean;setDraggedItem: (id: string | null) => void;+ setDragOverItem: (id: string | null) => void;}function DraggableListItem({section,onCheckboxChange,isDragged,+ isDraggingOver,setDraggedItem,+ setDragOverItem,}: DraggableListItemProps) {const [element, setElement] = useState<HTMLElement | null>(null);const sectionId = `${section.type}-${section.collectionId || "default"}`;@@ -274,23 +279,30 @@ function DraggableListItem({element: el,getInitialData: () => ({ sectionId }),onDragStart: () => setDraggedItem(sectionId),- onDrop: () => setDraggedItem(null),+ onDrop: () => {+ setDraggedItem(null);+ setDragOverItem(null);+ },}),dropTargetForElements({element: el,getData: () => ({ sectionId }),+ onDragEnter: () => setDragOverItem(sectionId),+ onDragLeave: () => setDragOverItem(null),+ onDrop: () => setDragOverItem(null),}));- }, [element, section.enabled, sectionId, setDraggedItem]);+ }, [element, section.enabled, sectionId, setDraggedItem, setDragOverItem]);return (<liref={setElement}data-section-id={sectionId}className={`- py-1 px-2 flex items-center justify-between cursor-pointer rounded+ py-1 px-2 flex items-center justify-between cursor-pointer rounded transition-colors${section.enabled ? "cursor-grab active:cursor-grabbing" : ""}- ${isDragged ? "opacity-50" : ""}+ ${isDragged ? "opacity-70" : ""}+ ${isDraggingOver && !isDragged ? "bg-base-100" : ""}`}><div className="flex items-center gap-2">@@ -302,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}@@ -312,10 +323,9 @@ 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>);-}+}\ No newline at end of filediff --git a/packages/router/collections.tsx b/packages/router/collections.tsxindex 5b6a24c2..ab9e2da1 100644--- a/packages/router/collections.tsx+++ b/packages/router/collections.tsx@@ -101,6 +101,8 @@ 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);});