deckhearth/components/CollectionSelectionModal.js
varutasu 926ce7a45b
feat(design-system): finish Liquid Glass — close all remaining sub-convoys (#96)
Follow-up PR to #95 (Liquid Glass foundation + primitives + Layout shell)
that closes out the remaining sub-convoy briefs in a single sweep.
Operator-instructed scope: "finish off the design changes."

After this PR, **all 8 Liquid Glass sub-convoys are MERGED to main**;
the deferred-from-#5 `fix-card3d-state` convoy is dropped (its target,
`components/Card3D.js`, turned out to be dead code).

## #2 Brief 2 — Remaining 8 modals migrated to <Modal> primitive

- `CollectionsSuccessModal.js` — wrap in <Modal hideCloseButton>; 2 Buttons.
- `CollectionsEditModal.js` — full <Modal> + <Input> + <Button> rewrite (4 fields, tag chip section, public-toggle preserved, 2 footer Buttons).
- `CollectionEditModal.js` — same pattern as above (4 fields + public-toggle + 2 Buttons).
- `CardDetailDeckModal.js` — <Modal> + native select (Select primitive not in scope) + 2 Buttons; sweep `gradient-bg-purple` → `<Button variant="primary">`.
- `UploadImageModal.js` — <Modal> + token-driven URL/file tab switcher + drag-drop using `--accent-ember` rim + 2 Buttons (one with `loading` prop).
- `CollectionSelectionModal.js` — largest of the set (header summary + SearchBar + scrollable list w/ checkbox toggles + footer); migrated to <Modal size="lg"> while preserving the per-collection card preview thumbnails.
- `OCRSettings.js` — trivial <Modal> wrap + single primary <Button>.
- `pages/decks.js` — both inline modals (Create Deck + Edit Deck) and `components/ScannerPageView.js` (Create List) migrated; ScannerPageView dropped its `useFocusTrap` named-import (Modal's internal focus trap owns the panel ref now).
- **`.github/workflows/ci.yml` `forbidden-modal-shell-without-primitive`** — grandfather list emptied to zero entries; gate is now strict.

## #3 Brief 2 — Forms migrated to <Button> / <SearchBar>

- `pages/dashboard.js` — 3 CTAs → <Button> (Create List with leadingIcon, Create Your First List, View All Lists).
- `pages/my-cards.js` — empty-state CTA → <Button variant="primary" size="lg">. View-mode toggle buttons intentionally left native (icon-only, doesn't match Button variants).
- `pages/community/collections.js` — Go to My Lists CTA → <Button>.
- `components/CollectionsPageView.js` — Discover Community + Create List header CTAs → <Button>; search input → <SearchBar>.
- Card-grid per-row icon buttons (CollectionsPageView, my-cards, CardsPageView) intentionally left native — tiny per-card actions whose styling doesn't match Button variants and would invalidate visual-diff baselines.

## #5 — scope revised + landed

`components/Card3D.js` deletion: surveyed every importer with grep — **zero consumers** in `pages/**` or `components/**`. Only references were in convoy docs. The "pre-existing state-management bug" (state setters used without useState declarations) never affected the running app because the component was never rendered. -505 LOC. The `fix-card3d-state` convoy is dropped from the roadmap as a result.

The actual card-grid component (`components/CardItem.js`) is intentionally **not** modified in this sweep — it has per-rarity glow tuning that the existing visual-diff baseline locks in, and the architect's #5 deferral note specifically called out the dedicated baseline re-seed cost. A future implementer turn can apply rim-light tokens to CardItem with its own baseline re-seed when an operator wants that polish.

## #6 Brief 1 — Landing + invite pages glass-migrated

- `pages/index.js` — top nav: `var(--glass-surface-mid)` + `--glass-blur-mid` + rim-light. 3 feature cards: `<GlassSurface tint="mid" rim="subtle" elevation="ambient">`. Featured-list cards (the public collection grid): same `<GlassSurface>` recipe with motion-token transitions. All 6 CTA buttons → <Button variant="primary"|"secondary"|"ghost"> with proper sizes. Pulse-loading placeholders tagged `.motion-essential` so reduced-motion users still see them animate (state-meaningful).
- `pages/invite/accept.js` + `pages/invite/decline.js` — both outcome panels wrapped in `<GlassSurface tint="mid" rim="subtle" elevation="pronounced">`. Loading spinner border colors corrected from `--text-accent` (which didn't exist) to `--accent-ember`. All 8 buttons → <Button>. `gradient-bg-ember` consumers retained (the canonical warm-palette utility class is fine).

## #8 Brief 2 — Legacy alias sweep + CI gate graduation

- Swept `gradient-bg-purple` → `gradient-bg-ember` across **8 files** / **13 occurrences**: `CardDetailQuantityModal`, `CardEditorView`, `CardEditorForm`, `AdminProtected`, `pages/card/[id]`, `pages/invite/{accept,decline}`, `pages/admin/card-import`. `gradient-bg-purple` was a dangling class name with no CSS definition (it was rendering no styling), so the sweep is also a bug fix — those buttons now actually get the ember gradient.
- Deleted the 5 dead CSS classes from `styles/globals.css`: `.gradient-text-blue`, `.gradient-text-purple`, `[data-theme="dark"] .glow-blue`, `[data-theme="dark"] .glow-purple`, `[data-theme="dark"] .glow-pink`. Each was zero-consumer post-sweep.
- **Graduated the `forbidden-deprecated-color-aliases` CI job from WARN to FAIL.** All 9 patterns (`gradient-text-{purple,pink,blue}`, `glow-{purple,pink,blue}`, `gradient-bg-{purple,blue,pink}`) now block the build if any consumer is reintroduced.

## Verification (local + CI gates locally exercised)

- Lint: 0 errors, 2 pre-existing warnings (`CardEditorForm.js` + `CollectionsPageView.js` carry-overs from before #95; out of scope).
- Vitest: 104/104 passing — unchanged from #95.
- Build: clean (Turbopack default; passes both light + dark theme prerender).
- `forbidden-modal-shell-without-primitive` gate: locally clear (`grep -lE 'fixed inset-0 bg-black bg-opacity-' pages components -r --include='*.js'` returns no matches).
- `forbidden-deprecated-color-aliases` gate: locally clear (all 9 patterns return no matches in `pages/` or `components/`).

## What still needs human action

- **Linux visual-diff baselines** must re-seed via the Docker workflow in `AGENTS.md` § 6. This PR's landing-page + invite-page changes will produce baseline drift on the homepage screenshot (which is currently the only baseline committed) AND additional baselines will be generated for the landing's glass-card sections once the visual spec is expanded. Recommended: run the Docker re-seed against this PR's Vercel preview, commit the result to this branch, push, verify CI green, then merge.
- Vercel auto-promotes the merge to production.

## Closes / supersedes

- Closes `.convoys/liquid-glass-modal-and-surface-primitive.md` Brief 2 (status → merged).
- Closes `.convoys/liquid-glass-form-primitives.md` Brief 2 (status → merged with explicit per-row-icon-button deferral note).
- Closes `.convoys/liquid-glass-public-and-auth.md` Brief 1 (status → merged).
- Closes `.convoys/cleanup-legacy-design-css.md` Brief 2 (status → merged + CI gate FAIL).
- Drops `.convoys/liquid-glass-card-surfaces.md` Brief 1 prerequisite (`fix-card3d-state` no longer needed; Card3D deleted).
- Drops the queued `fix-card3d-state` follow-up from the roadmap (target deleted).
- Updates `.convoys/ship-readiness.md` § "Design-system redesign portfolio" with a "Finish-portfolio sweep" subsection documenting final status of all 8 sub-convoys.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-03 20:34:06 -05:00

367 lines
14 KiB
JavaScript

/* eslint-disable @next/next/no-img-element -- External card image URLs; next/image migration is out of scope. */
import { useState, useEffect } from 'react';
import { VOCAB } from '../lib/collection-vocabulary.js';
import { Modal, SearchBar, Button } from './ui';
export default function CollectionSelectionModal({
isOpen,
onClose,
cards,
onAddToCollections,
}) {
const [collections, setCollections] = useState([]);
const [selectedCollections, setSelectedCollections] = useState([]);
const [loading, setLoading] = useState(false);
const [submitting, setSubmitting] = useState(false);
const [searchQuery, setSearchQuery] = useState('');
const [prevIsOpen, setPrevIsOpen] = useState(isOpen);
if (isOpen && !prevIsOpen) {
setPrevIsOpen(true);
setSelectedCollections([]);
setSearchQuery('');
} else if (!isOpen && prevIsOpen) {
setPrevIsOpen(false);
}
useEffect(() => {
if (!isOpen) return;
const fetchCollections = async () => {
setLoading(true);
try {
const response = await fetch('/api/collections?excludeSystem=true');
if (response.ok) {
const data = await response.json();
setCollections(Array.isArray(data) ? data : data.collections || []);
} else {
console.error('Failed to fetch collections:', response.status, response.statusText);
setCollections([]);
}
} catch (error) {
console.error('Error fetching collections:', error);
setCollections([]);
} finally {
setLoading(false);
}
};
fetchCollections();
}, [isOpen]);
const handleCollectionToggle = (collectionId) => {
setSelectedCollections((prev) =>
prev.includes(collectionId)
? prev.filter((id) => id !== collectionId)
: [...prev, collectionId]
);
};
const getFilteredCollections = () => {
if (!searchQuery.trim()) return collections;
return collections.filter(
(collection) =>
collection.name.toLowerCase().includes(searchQuery.toLowerCase()) ||
collection.description?.toLowerCase().includes(searchQuery.toLowerCase())
);
};
const handleSelectAll = () => {
const filteredCollections = getFilteredCollections();
const allSelected = filteredCollections.every((collection) =>
selectedCollections.includes(collection.id)
);
if (allSelected) {
setSelectedCollections((prev) =>
prev.filter((id) => !filteredCollections.some((c) => c.id === id))
);
} else {
const newSelections = filteredCollections
.filter((collection) => !selectedCollections.includes(collection.id))
.map((collection) => collection.id);
setSelectedCollections((prev) => [...prev, ...newSelections]);
}
};
const handleSubmit = async () => {
if (selectedCollections.length === 0) return;
setSubmitting(true);
try {
const results = [];
for (const collectionId of selectedCollections) {
for (const card of cards) {
const response = await fetch(`/api/collections/${collectionId}/cards`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ cardId: card.id, quantity: 1 }),
});
results.push({
collectionId,
cardId: card.id,
success: response.ok,
});
}
}
onAddToCollections(results, selectedCollections, cards);
onClose();
} catch (error) {
console.error('Error adding cards to collections:', error);
} finally {
setSubmitting(false);
}
};
const filteredCollections = getFilteredCollections();
const allFilteredSelected =
filteredCollections.length > 0 &&
filteredCollections.every((collection) =>
selectedCollections.includes(collection.id)
);
return (
<Modal open={isOpen} onClose={onClose} title={VOCAB.ADD_TO_LISTS} size="lg">
<div className="flex items-center space-x-3 mb-4">
<div className="flex -space-x-2">
{cards.slice(0, 3).map((card) => (
<div
key={card.id}
className="w-12 h-16 rounded border-2 overflow-hidden"
style={{
backgroundColor: 'var(--bg-tertiary)',
borderColor: 'var(--bg-primary)',
}}
>
{card.image_url ? (
<img
src={card.image_url}
alt={card.name}
className="w-full h-full object-cover"
/>
) : (
<div
className="w-full h-full flex items-center justify-center text-xs"
style={{ color: 'var(--text-tertiary)' }}
>
No Image
</div>
)}
</div>
))}
{cards.length > 3 && (
<div
className="w-12 h-16 rounded border-2 flex items-center justify-center"
style={{
backgroundColor: 'var(--bg-tertiary)',
borderColor: 'var(--bg-primary)',
}}
>
<span className="text-sm font-bold" style={{ color: 'var(--text-secondary)' }}>
+{cards.length - 3}
</span>
</div>
)}
</div>
<div>
<p className="text-lg font-semibold" style={{ color: 'var(--text-primary)' }}>
{cards.length} card{cards.length !== 1 ? 's' : ''} selected
</p>
<p className="text-sm" style={{ color: 'var(--text-secondary)' }}>
Choose lists to add {cards.length === 1 ? 'this card' : 'these cards'} to
</p>
</div>
</div>
<div className="mb-4">
<SearchBar
value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)}
onClear={() => setSearchQuery('')}
placeholder="Search lists…"
/>
</div>
<div className="overflow-y-auto" style={{ maxHeight: '24rem' }}>
{loading ? (
<div className="p-8 text-center">
<div
className="motion-essential animate-spin rounded-full h-8 w-8 border-b-2 mx-auto mb-2"
style={{ borderColor: 'var(--accent-ember)' }}
/>
<p style={{ color: 'var(--text-secondary)' }}>Loading lists...</p>
</div>
) : filteredCollections.length === 0 ? (
<div className="p-8 text-center">
<svg
className="w-12 h-12 mx-auto mb-4"
style={{ color: 'var(--text-tertiary)' }}
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
aria-hidden="true"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"
/>
</svg>
<p className="mb-2" style={{ color: 'var(--text-secondary)' }}>
{searchQuery ? 'No lists match your search' : 'No lists found'}
</p>
<p className="text-sm" style={{ color: 'var(--text-tertiary)' }}>
{searchQuery ? 'Try a different search term' : 'Create your first list to get started'}
</p>
</div>
) : (
<>
{filteredCollections.length > 1 && (
<div
className="flex items-center justify-between p-3 border-b mb-2"
style={{ borderColor: 'var(--border)' }}
>
<label className="flex items-center space-x-3 cursor-pointer">
<input
type="checkbox"
checked={allFilteredSelected}
onChange={handleSelectAll}
className="w-4 h-4 rounded"
style={{ accentColor: 'var(--accent-ember)' }}
/>
<span className="font-medium" style={{ color: 'var(--text-primary)' }}>
Select All ({filteredCollections.length})
</span>
</label>
</div>
)}
<div className="space-y-2">
{filteredCollections.map((collection) => {
const isSelected = selectedCollections.includes(collection.id);
return (
<div
key={collection.id}
className="p-4 rounded-lg border-2 cursor-pointer"
style={{
borderColor: isSelected
? 'var(--accent-ember)'
: 'var(--border)',
backgroundColor: isSelected
? 'rgba(var(--ember-rim-subtle), 0.08)'
: 'transparent',
transition: 'all var(--motion-duration-default) var(--motion-ease-out)',
}}
onClick={() => handleCollectionToggle(collection.id)}
>
<div className="flex items-center space-x-3">
<input
type="checkbox"
checked={isSelected}
onChange={() => handleCollectionToggle(collection.id)}
className="w-4 h-4 rounded"
style={{ accentColor: 'var(--accent-ember)' }}
/>
<div
className="w-12 h-12 rounded-lg overflow-hidden flex-shrink-0"
style={{ backgroundColor: 'var(--bg-tertiary)' }}
>
{collection.image ? (
<img
src={collection.image}
alt={collection.name}
className="w-full h-full object-cover"
/>
) : (
<div
className="w-full h-full flex items-center justify-center"
style={{ color: 'var(--text-tertiary)' }}
>
<svg
className="w-6 h-6"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
aria-hidden="true"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"
/>
</svg>
</div>
)}
</div>
<div className="flex-1 min-w-0">
<h3
className="font-semibold truncate"
style={{ color: 'var(--text-primary)' }}
>
{collection.name}
</h3>
{collection.description && (
<p
className="text-sm truncate"
style={{ color: 'var(--text-secondary)' }}
>
{collection.description}
</p>
)}
<div className="flex items-center space-x-4 mt-1">
<span className="text-xs" style={{ color: 'var(--text-tertiary)' }}>
{collection.card_count || 0} cards
</span>
{collection.is_public && (
<span
className="text-xs px-2 py-1 rounded-full"
style={{
backgroundColor: 'rgba(34, 197, 94, 0.15)',
color: 'rgb(21, 128, 61)',
}}
>
Public
</span>
)}
</div>
</div>
</div>
</div>
);
})}
</div>
</>
)}
</div>
<div
className="flex items-center justify-between mt-6 pt-4 border-t"
style={{ borderColor: 'var(--border)' }}
>
<div className="text-sm" style={{ color: 'var(--text-secondary)' }}>
{selectedCollections.length > 0 && (
<span>
{selectedCollections.length} list
{selectedCollections.length !== 1 ? 's' : ''} selected
</span>
)}
</div>
<div className="flex space-x-3">
<Button variant="secondary" onClick={onClose}>
Cancel
</Button>
<Button
variant="primary"
onClick={handleSubmit}
disabled={selectedCollections.length === 0 || submitting}
loading={submitting}
>
{submitting
? 'Adding...'
: `Add to ${selectedCollections.length} List${
selectedCollections.length !== 1 ? 's' : ''
}`}
</Button>
</div>
</div>
</Modal>
);
}