Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix(brain): make links draggable into buckets

Adam Eivyfd60d7a08ef8
diff --git a/client/src/components/brain/links/BucketBoard.jsx b/client/src/components/brain/links/BucketBoard.jsx
index 286ef099e5..1202325ab3 100644
--- a/client/src/components/brain/links/BucketBoard.jsx
+++ b/client/src/components/brain/links/BucketBoard.jsx
@@ -1,4 +1,4 @@
-import { useState, useRef, useCallback } from 'react';
+import { useState, useCallback } from 'react';
import { Plus, FolderPlus, X } from 'lucide-react';
import * as api from '../../../services/api';
import toast from '../../ui/Toast';
@@ -7,13 +7,14 @@ import BucketCard from './BucketCard';
/**
* The bucket board: a responsive grid of bucket cards plus a "new bucket"
* affordance. The bucket collection + links (the single source of truth) live
- * in the parent LinksTab and flow in via props; the board owns drag-and-drop.
+ * in the parent LinksTab and flow in via props. Drag-and-drop is carried via
+ * dataTransfer (link id / bucket id) so a link dragged from the list, a chip
+ * dragged from another bucket, and a bucket header dragged to reorder all
+ * resolve the same way regardless of which component started the drag.
*/
export default function BucketBoard({ links, buckets, setBuckets, onAssignLink, onAddLinkToBucket, onBucketDeleted }) {
const [creating, setCreating] = useState(false);
const [newName, setNewName] = useState('');
- const draggedLink = useRef(null);
- const draggedBucket = useRef(null);
const handleCreate = async (e) => {
e.preventDefault();
@@ -50,24 +51,21 @@ export default function BucketBoard({ links, buckets, setBuckets, onAssignLink,
}
}, [onBucketDeleted, setBuckets]);
- // --- Drag: move a chip into a bucket ---
- const handleDropChip = useCallback((bucketId) => {
- const link = draggedLink.current;
- draggedLink.current = null;
+ // --- Drag: move a link (from the list or another bucket) into a bucket ---
+ const handleDropLink = useCallback((linkId, bucketId) => {
+ const link = links.find(l => l.id === linkId);
if (link && link.bucketId !== bucketId) {
onAssignLink?.(link, bucketId);
}
- }, [onAssignLink]);
+ }, [links, onAssignLink]);
// --- Drag: reorder buckets ---
- const handleReorder = useCallback((targetBucket) => {
- const dragged = draggedBucket.current;
- draggedBucket.current = null;
- if (!dragged || dragged.id === targetBucket.id) return;
+ const handleReorder = useCallback((draggedId, targetBucket) => {
+ if (!draggedId || draggedId === targetBucket.id) return;
setBuckets(prev => {
const ids = prev.map(b => b.id);
- const from = ids.indexOf(dragged.id);
+ const from = ids.indexOf(draggedId);
const to = ids.indexOf(targetBucket.id);
if (from === -1 || to === -1) return prev;
const next = [...prev];
@@ -96,12 +94,8 @@ export default function BucketBoard({ links, buckets, setBuckets, onAssignLink,
onDelete={handleDelete}
onAddLink={onAddLinkToBucket}
onRemoveLink={(link) => onAssignLink?.(link, null)}
- onChipDragStart={(link) => { draggedLink.current = link; }}
- onChipDragEnd={() => { draggedLink.current = null; }}
- onDropChip={handleDropChip}
- onHeaderDragStart={(b) => { draggedBucket.current = b; }}
- onHeaderDragEnd={() => { draggedBucket.current = null; }}
- onHeaderDropReorder={handleReorder}
+ onDropLink={(linkId) => handleDropLink(linkId, bucket.id)}
+ onReorderBucket={(draggedId) => handleReorder(draggedId, bucket)}
/>
))}
diff --git a/client/src/components/brain/links/BucketCard.jsx b/client/src/components/brain/links/BucketCard.jsx
index 99ede795d0..a8f70b358a 100644
--- a/client/src/components/brain/links/BucketCard.jsx
+++ b/client/src/components/brain/links/BucketCard.jsx
@@ -2,12 +2,13 @@ import { useState } from 'react';
import { Plus, Edit2, Trash2, Save, X, Check, GripVertical } from 'lucide-react';
import BrailleSpinner from '../../BrailleSpinner';
import LinkChip from './LinkChip';
-import { bucketColor, BUCKET_COLORS, BUCKET_COLOR_KEYS } from './bucketColors';
+import { bucketColor, BUCKET_COLORS, BUCKET_COLOR_KEYS, LINK_DND_TYPE, BUCKET_DND_TYPE } from './bucketColors';
/**
* A single bucket (bookmark group): colored header with inline edit/delete,
* a grid of link chips, and an inline "add URL" affordance. Acts as a drop
- * target so links can be dragged in from other buckets.
+ * target so a link can be dragged in (from the list or another bucket) and
+ * so buckets can be reordered by dragging their headers.
*/
export default function BucketCard({
bucket,
@@ -16,12 +17,8 @@ export default function BucketCard({
onDelete,
onAddLink,
onRemoveLink,
- onChipDragStart,
- onChipDragEnd,
- onDropChip,
- onHeaderDragStart,
- onHeaderDragEnd,
- onHeaderDropReorder
+ onDropLink,
+ onReorderBucket
}) {
const formFromBucket = () => ({ name: bucket.name, color: bucket.color, icon: bucket.icon || '' });
const [editing, setEditing] = useState(false);
@@ -65,8 +62,10 @@ export default function BucketCard({
onDrop={(e) => {
e.preventDefault();
setDropActive(false);
- onDropChip?.(bucket.id);
- onHeaderDropReorder?.(bucket);
+ const linkId = e.dataTransfer.getData(LINK_DND_TYPE);
+ if (linkId) { onDropLink?.(linkId); return; }
+ const draggedBucketId = e.dataTransfer.getData(BUCKET_DND_TYPE);
+ if (draggedBucketId) onReorderBucket?.(draggedBucketId);
}}
>
{/* Header */}
@@ -126,12 +125,14 @@ export default function BucketCard({
</div>
) : (
<div
- className={`flex items-center gap-2 px-3 py-2 border-b ${colors.header}`}
+ className={`flex items-center gap-2 px-3 py-2 border-b cursor-grab ${colors.header}`}
draggable
- onDragStart={() => onHeaderDragStart?.(bucket)}
- onDragEnd={onHeaderDragEnd}
+ onDragStart={(e) => {
+ e.dataTransfer.setData(BUCKET_DND_TYPE, bucket.id);
+ e.dataTransfer.effectAllowed = 'move';
+ }}
>
- <GripVertical size={14} className="shrink-0 text-gray-500 cursor-grab" />
+ <GripVertical size={14} className="shrink-0 text-gray-500" />
{bucket.icon && <span className="shrink-0 text-base leading-none">{bucket.icon}</span>}
<h3 className={`font-medium truncate flex-1 ${colors.text}`}>{bucket.name}</h3>
<span className="text-xs text-gray-500">{links.length}</span>
@@ -182,8 +183,6 @@ export default function BucketCard({
link={link}
onRemove={onRemoveLink}
draggable
- onDragStart={() => onChipDragStart?.(link)}
- onDragEnd={onChipDragEnd}
/>
))}
</div>
diff --git a/client/src/components/brain/links/LinkChip.jsx b/client/src/components/brain/links/LinkChip.jsx
index 07d93a69ce..90ff6b133a 100644
--- a/client/src/components/brain/links/LinkChip.jsx
+++ b/client/src/components/brain/links/LinkChip.jsx
@@ -1,30 +1,34 @@
import { useState } from 'react';
import { Link2, X, GripVertical } from 'lucide-react';
-import { faviconUrl } from './bucketColors';
+import { faviconUrl, LINK_DND_TYPE } from './bucketColors';
/**
* A compact favicon + title button for a link inside a bucket.
* Clicking opens the link in a new tab; the hover-revealed X removes it
- * from the bucket (does not delete the underlying link).
+ * from the bucket (does not delete the underlying link). Draggable chips
+ * carry their link id so they can be dropped into another bucket.
*/
-export default function LinkChip({ link, onRemove, draggable, onDragStart, onDragEnd }) {
+export default function LinkChip({ link, onRemove, draggable }) {
const [iconFailed, setIconFailed] = useState(false);
const favicon = faviconUrl(link.url);
return (
<div
- className="group flex items-center gap-2 pl-1.5 pr-1 py-1 bg-port-bg border border-port-border rounded-md hover:border-port-accent/50 transition-colors max-w-full"
+ className={`group flex items-center gap-2 pl-1.5 pr-1 py-1 bg-port-bg border border-port-border rounded-md hover:border-port-accent/50 transition-colors max-w-full ${draggable ? 'cursor-grab' : ''}`}
draggable={draggable}
- onDragStart={onDragStart}
- onDragEnd={onDragEnd}
+ onDragStart={draggable ? (e) => {
+ e.dataTransfer.setData(LINK_DND_TYPE, link.id);
+ e.dataTransfer.effectAllowed = 'move';
+ } : undefined}
>
{draggable && (
- <GripVertical size={12} className="shrink-0 text-gray-600 cursor-grab group-hover:text-gray-400" />
+ <GripVertical size={12} className="shrink-0 text-gray-600 group-hover:text-gray-400" />
)}
<a
href={link.url}
target="_blank"
rel="noopener noreferrer"
+ draggable={false}
className="flex items-center gap-1.5 min-w-0 flex-1 text-sm text-gray-200 hover:text-white"
title={link.url}
>
diff --git a/client/src/components/brain/links/bucketColors.js b/client/src/components/brain/links/bucketColors.js
index 79dd7e6dfe..9c46e213ee 100644
--- a/client/src/components/brain/links/bucketColors.js
+++ b/client/src/components/brain/links/bucketColors.js
@@ -16,6 +16,12 @@ export const BUCKET_COLORS = {
export const BUCKET_COLOR_KEYS = Object.keys(BUCKET_COLORS);
+// Drag-and-drop payload types — shared so a link dragged from the list or
+// from another bucket, and a bucket dragged for reordering, are recognized
+// by any drop target regardless of which component initiated the drag.
+export const LINK_DND_TYPE = 'text/x-brain-link';
+export const BUCKET_DND_TYPE = 'text/x-brain-bucket';
+
export function bucketColor(key) {
return BUCKET_COLORS[key] || BUCKET_COLORS.accent;
}
diff --git a/client/src/components/brain/tabs/LinksTab.jsx b/client/src/components/brain/tabs/LinksTab.jsx
index 1f812a9cba..f10f87614a 100644
--- a/client/src/components/brain/tabs/LinksTab.jsx
+++ b/client/src/components/brain/tabs/LinksTab.jsx
@@ -19,13 +19,15 @@ import {
Search,
ChevronDown,
ChevronUp,
- FolderClosed
+ FolderClosed,
+ GripVertical
} from 'lucide-react';
import BrailleSpinner from '../../BrailleSpinner';
import toast from '../../ui/Toast';
import { timeAgo } from '../../../utils/formatters';
import { useAutoRefetch } from '../../../hooks/useAutoRefetch';
import BucketBoard from '../links/BucketBoard';
+import { LINK_DND_TYPE } from '../links/bucketColors';
/** Normalize a user-entered URL the way the quick-add form does. */
function normalizeUrl(raw) {
@@ -443,13 +445,23 @@ export default function LinksTab({ onRefresh }) {
{/* Links list */}
<div className="space-y-3">
- {visibleLinks.map(link => (
+ {visibleLinks.map(link => {
+ const isEditing = editingId === link.id;
+ return (
<div
key={link.id}
- className="p-4 bg-port-card border border-port-border rounded-lg"
+ draggable={!isEditing}
+ onDragStart={!isEditing ? (e) => {
+ e.dataTransfer.setData(LINK_DND_TYPE, link.id);
+ e.dataTransfer.effectAllowed = 'move';
+ } : undefined}
+ className={`p-4 bg-port-card border border-port-border rounded-lg ${isEditing ? '' : 'cursor-grab'}`}
>
{/* Header row */}
<div className="flex items-start justify-between gap-3 mb-2">
+ {!isEditing && (
+ <GripVertical size={16} className="shrink-0 mt-0.5 text-gray-600" title="Drag to a bucket" />
+ )}
{editingId === link.id ? (
<div className="flex-1 space-y-2">
<div>
@@ -535,6 +547,7 @@ export default function LinksTab({ onRefresh }) {
href={link.url}
target="_blank"
rel="noopener noreferrer"
+ draggable={false}
className="text-sm text-gray-400 hover:text-port-accent truncate block"
>
{link.url}
@@ -563,6 +576,7 @@ export default function LinksTab({ onRefresh }) {
href={link.url}
target="_blank"
rel="noopener noreferrer"
+ draggable={false}
className="p-1.5 text-gray-400 hover:text-port-accent transition-colors"
title="Open in new tab"
>
@@ -722,7 +736,8 @@ export default function LinksTab({ onRefresh }) {
</div>
)}
</div>
- ))}
+ );
+ })}
{visibleLinks.length === 0 && query && (
<div className="text-center py-12 text-gray-500">