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.2 KB
Raw Blame
import { useCallback } from 'react';
import CollectionPickerShell from './CollectionPickerShell';
import CollectionRowLabel from './CollectionRowLabel';

// Single-target picker used by MediaCollectionDetail's bulk-action bar.
// AddToCollectionMenu toggles membership for one item across many collections;
// this picker is the inverse — one click picks a destination for many items.
//
// Both share the same popover/positioning/create-form shell — see
// CollectionPickerShell.jsx. The differences this caller layers on:
//   - rows render with an item-count badge instead of a membership checkmark
//   - clicking a row calls onPick(id, name) instead of toggling membership
//   - creating a new collection picks it as the destination
//
// `collections` (optional): the parent's already-fetched list, so the shell
// skips its own listMediaCollections() round-trip. MediaCollectionDetail
// passes this to dedupe the load it already performed.

export default function BulkTargetPicker({
  anchorRef,
  excludeId,
  busy,
  title = 'Pick a collection',
  collections,
  error = null,
  onRetry = null,
  onPick,
  onClose,
}) {
  const renderItem = useCallback((c) => (
    <button
      type="button"
      disabled={busy}
      onClick={() => onPick(c.id, c.name)}
      className="w-full flex items-center gap-2 px-2 py-1.5 text-left text-[12px] text-gray-200 hover:bg-port-border rounded disabled:opacity-50"
    >
      <CollectionRowLabel name={c.name} />
      <span className="text-[10px] text-gray-500 shrink-0">{c.items?.length ?? 0}</span>
    </button>
  ), [busy, onPick]);

  const handleCreated = useCallback((created) => {
    onPick(created.id, created.name);
  }, [onPick]);

  return (
    <CollectionPickerShell
      anchorRef={anchorRef}
      open
      onClose={onClose}
      title={title}
      excludeId={excludeId}
      busy={busy}
      emptyMessage="No collections yet — create one below."
      noMatchMessage={(q) => (q ? `No matches for "${q}"` : 'No other collections — create one below.')}
      newCollectionPlaceholder="New collection"
      createTitle="Create and pick"
      collections={collections}
      error={error}
      onRetry={onRetry}
      renderItem={renderItem}
      onCreated={handleCreated}
    />
  );
}