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

2.5 KB
Raw Blame
import { useState } from 'react';
import { Link2, X, GripVertical } from 'lucide-react';
import { faviconUrl } 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). `dragHandleProps`
 * (a dnd-kit `useDraggable` handle's `attributes`/`listeners`/ref, wired by
 * the caller so the drag id carries the chip's bucket + index) turns the
 * grip icon into the pointer/keyboard drag activator.
 */
export default function LinkChip({ link, onRemove, dragHandleProps }) {
  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">
      {dragHandleProps && (
        <button
          type="button"
          ref={dragHandleProps.setActivatorNodeRef}
          {...dragHandleProps.attributes}
          {...dragHandleProps.listeners}
          className="shrink-0 flex items-center justify-center text-gray-600 hover:text-gray-300 cursor-grab active:cursor-grabbing"
          aria-label={`Drag ${link.title}`}
          title="Drag to reorder or move to another bucket"
        >
          <GripVertical size={12} />
        </button>
      )}
      <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}
      >
        {favicon && !iconFailed ? (
          <img
            src={favicon}
            alt=""
            width={16}
            height={16}
            draggable={false}
            className="shrink-0 rounded-sm"
            onError={() => setIconFailed(true)}
          />
        ) : (
          <Link2 size={14} className="shrink-0 text-gray-500" />
        )}
        <span className="truncate">{link.title}</span>
      </a>
      {onRemove && (
        <button
          onClick={() => onRemove(link)}
          className="min-h-[44px] min-w-[44px] inline-flex items-center justify-center shrink-0 p-0.5 text-gray-600 hover:text-port-error opacity-40 sm:opacity-0 sm:group-hover:opacity-100 focus-visible:opacity-100 transition-opacity"
          title="Remove from bucket" aria-label="Remove from bucket"
        >
          <X size={13} />
        </button>
      )}
    </div>
  );
}