Repository navigation
feat: protect and unprotect a copy from the copy page - #175
Merged
Merged
Conversation
Reilley64
added a commit
that referenced
this pull request
Oct 14, 2026
Closes #149
## Summary
```diff
Copy page (apps/mobile/src/app/copy.tsx)
chips
+ User tags: one disclosure row, chips or "Add user tags", chevron
+ -> pushes the user tag picker (src/app/user-tag-picker.tsx)
Price
Rules
+User tag picker
+ "User tags" title, copy line, "Find or create a user tag" field (64 characters)
+ Create "<name>" row -> create_user_tag, then set_copy_user_tag
+ check rows -> set_copy_user_tag({ copy_id, user_tag_id, tagged })
+ "No user tags yet. Type a name to create one."
```
```diff
supabase/migrations/20261031130000_put_user_tags_on_copies.sql
+user_tags (id, user_id, name trimmed 1-64, created_at), unique (user_id, lower(name))
+copy_user_tags (user_id, copy_id, user_tag_id), cascades from copies and user_tags
+create_user_tag(request) security definer, user_tag_exists on name
+set_copy_user_tag(request) security definer, idempotent, returns nothing, not_found on copy_id or user_tag_id
+list_user_tags() security invoker, copy_count, sorted by name ignoring case
get_copy(query)
+ user_tags: [{ user_tag_id, name }] sorted by name ignoring case
```
- Write functions take one jsonb argument named `request`, like
`set_copy_protected` (#175) and `delete_copy` (#174).
`set_copy_user_tag` reuses `private.checked_copy_id` and
`private.raise_copy_not_found`, and the app write goes through
`collection/copy-writes.ts`.
- The migration sorts after protect (20261031120000).
- `PushedScreen` keeps the keyboard up when a tap lands on a control, so
the first tap on a picker row acts. The Simulator showed that the first
tap only closed the keyboard before this change.
- New primitives: `ListRow` with `checked` (a check row, read as a
checkbox) and `DisclosureRow`. Both are in the primitive catalog and
`molecules.test.tsx`.
- `useFocusedRead` now holds the focus reload that `useCopy` and
`useUserTags` share. `copyChipLabels` gives the copy page chips and the
picker's copy line.
- The test user's sample collection adds "Signed" on one copy and "Trade
binder" on three copies.
- README lists `user_tags` and `copy_user_tags` as per-user data and
describes the functions. DESIGN.md describes the User tags row, the user
tag picker, check rows, and disclosure rows.
## Evidence
Database tests at seam (a), `supabase/tests/user-tags.test.ts` (32
tests), plus `copy-reads`, `per-user-reads`, and `test-user`:
```text
creating a user tag
creates a user tag with the trimmed name as typed
a name is trimmed of tabs and line breaks too
a name that matches a user tag ignoring case is refused with user_tag_exists on name
empty, only spaces, 65 characters, not a string, unknown field -> invalid_argument on the field
putting a user tag on a copy
puts a user tag on one copy and takes it off, and doing either twice changes nothing
putting a user tag on a copy and taking it off change no collection entry
not_found on copy_id or user_tag_id
the user tag list
sorted by name ignoring case, with how many copies have each
deleting a copy (delete_copy) removes its user tag links, and the count drops
access
another user's user tags and links are not visible and cannot be used
an anonymous caller and the secret key are refused; direct writes are refused
```
Component tests at seam (c), `apps/mobile/test/copy-page.test.tsx`: the
User tags row and its VoiceOver label, the picker title, copy line, 64
character field, edge swipe back, matching rows with checks and counts,
toggling, Create, the empty text, a failed change, a failed read, and a
copy that no longer exists. Binder tiles still show no user tags.
Mutation checks (each test went red, then green after restoring):
| Change | Test that went red |
| --- | --- |
| drop the unique index on `(user_id, lower(name))` | a name that
matches a user tag ignoring case is refused |
| `user_tags` read policy `using (true)` | a user cannot see another
user's user tags or links |
| `copy_user_tags` copy foreign key without cascade | deleting a copy
removes its user tag links |
| app match without `toLowerCase()` | a name that matches no user tag
ignoring case offers to create it |
| `ListRow` without `aria-checked` | tapping a row adds the user tag to
this copy |
Local runs after the rebase on #174 and #175: `bun test` in `supabase`
783 pass; Jest 530 pass; lint and typecheck clean.
**Simulator** (shared iPhone 16e, development build, test sign-in, local
Supabase, sample collection). The screenshots are on the owner's Mac in
`/tmp/mtgscan-149/`:
- `copy-page-user-tags.png`: the protected sample copy with the User
tags heading and the row with "Signed" and "Trade binder" chips and the
chevron.
- `user-tag-picker.png`: "User tags", the line "Smothering Tithe · CMM ·
473 · Etched · NM · English", the field, and lime checks on "Signed, 1
copy" and "Trade binder, 3 copies".
- `user-tag-picker-created.png`: after "Mint" was typed and **Create
"Mint"** tapped with the keyboard up: "Mint, 1 copy" checked, the field
cleared, "Signed" unchecked with an empty circle.
- `copy-page-after.png`: back with the edge swipe, the row shows "Foil
binder", "Mint", and "Trade binder".
- `copy-page-add-user-tags.png`: a copy with no user tags shows "Add
user tags" with the chevron.
Owner check on the phone: the edge swipe back from the picker and the
keyboard behavior.
## Merge Danger
**Door:** two-way
New tables and functions only. `get_copy` gains one field.
**Blast Radius:** small
The copy page gains a section. Rolling back drops the two new tables and
their data.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #147
Summary
The copy page's actions menu now has Protect for a free copy and Unprotect for a protected copy, before Delete copy. The Protected chip changes at once. A protected copy's binder tile shows a warning shield before the set icon.
Other changes:
20261031120000_protect_and_unprotect_a_copy.sql. It sorts after20261031100000_delete_a_copy.sqland reuses itsprivate.checked_copy_idandprivate.raise_copy_not_found.copy-writes.tsmaps both writes to oneCopyWriteResultthroughresultOf.Protected 1 sample copy.theme.tsgainssizes.protectedSymbol(11). The primitive catalog has a protected binder tile.README.mdgains Protect a copy.DESIGN.md(Collection, Copy page, Binder tile) gains the menu items, the tile shield, and the VoiceOver word.docs/agents/local-development.mdsays the sample has one protected copy.copyNotFoundanswer for the read and both writes.Evidence
Tests:
supabase/tests/copy-protection.test.ts, 14 tests. Protect and unprotect change only one copy, among two copies of one collection entry and a copy of another card. Doing it twice changes nothing. Refused requests name their field. An unknown copy and another user's copy arenot_found, and the other user's copy stays unprotected. An anonymous caller and the secret key are refused. A direct update ofcopiesis refused.test-user.test.tschecks that the sample collection has one protected copy and still 30 collection entries. The full database suite passed before the rebase onto feat: delete a copy from the copy page #174 (733 tests). After it,copy-protection,copy-deletes, andtest-userpass (36 tests), and CI runs the full suite.apps/mobile/test/copy-protection.test.tsx, 10 tests: the menu of a free copy, a protected copy, and a copy that is not free. Protect protects only the opened copy and shows the chip. Unprotect removes it. After Protect, the binder tile shows the shield and the other tile does not. A copy that is gone shows the missing copy alert and goes back. A failed write says so and keeps the copy. A protected tile has the 11 px warning shield before the set icon, and VoiceOver hears "protected" before the price.molecules.test.tsxcovers theCopyMetashield. Full Jest run: 514 tests pass. Lint and type checks pass.Mutation checks:
set_copy_protectedupdateswhere copy.user_id = callerwithout the copy ID ->protecting a copy protects only that copy,unprotecting a copy unprotects only that copy, andprotecting a protected copy again changes nothingfail. Restored, they pass.protected: true->Unprotect unprotects this copy and removes the Protected chipfails. Restored, it passes.isProtected-> the two tile shield tests fail. Restored, they pass.copy_not_freehas no test. Every copy is free until decks exist (spec 6), so no copy can reach it yet.Simulator (shared iPhone 16e, test sign-in, sample collection with one protected copy):
is:protectedfinds the one protected copy, Smothering Tithe CMM 473 etched. Its tile shows the warning shield before the set icon. VoiceOver reads "Smothering Tithe, CMM 473, etched, protected, $72.72".Merge Danger
Door: two-way
The migration adds
set_copy_protected. It replaces no function.Blast Radius: small
The binder tile's VoiceOver label gains "protected" for protected copies.
Decisions to check:
DESIGN.mdnow holds it.copy_not_freeis on thecopy_idfield, because the copy is what is not free.