diff --git a/GLOSSARY.md b/GLOSSARY.md index 56ca6b9c..2294687f 100644 --- a/GLOSSARY.md +++ b/GLOSSARY.md @@ -13,13 +13,21 @@ Plucking a URL that is already in your library. It brings the existing Item back _Avoid_: Duplicate, re-save **Item**: -One plucked thing. Link Items have a URL and a kept page; Notes, Todos and Things are Items with no URL. +One plucked thing. Link Items have a URL and a kept page, except an Image or PDF plucked as a file, which has neither; Notes, Todos and Things are Items with no URL. _Avoid_: Save, bookmark, entry, card **Kind**: What an Item is: Read, Watch, PDF, Image, Note, Todo or Thing. "Links" is the group of Read, Watch, PDF and Image. _Avoid_: Type, category +**Note**: +An Item of your own words, typed or dictated. Not the note on a link Item, a List entry or a Highlight, which is a short comment on something else. +_Avoid_: Memo, doc, page + +**Found on**: +The web page an Image was plucked from, kept with it as the way back. +_Avoid_: Source, origin, referrer + **Kept page**: What is worth keeping from a link Item's page, stored with it so it survives the original going away: an article's text and HTML, a post's words, a repo's README, a product's name and price. Never a login wall or an empty app shell. _Avoid_: Snapshot, cache, archive copy @@ -39,11 +47,11 @@ Where an Item sits in triage: Inbox (untriaged), Later (kept on purpose), Archiv _Avoid_: State, folder **Tag**: -A short label you made. A Tag your AI made carries a "by AI" mark until you touch it. +A short label you made, from a picker or by writing `#word` in a Note or a note. A Tag your AI made carries a "by AI" mark until you touch it. _Avoid_: Label, category, smart tag **List**: -A named, ordered group of Items with a purpose line. Each Item in a List has its own note and tick, which belong to the List, not the Item. Private or Public. +A named, ordered group of Items with a purpose line. Each Item in a List has its own note and tick, which belong to the List, not the Item. Private or Public. The first place a pluck can be put, ahead of Tags; an account starts with two, Favourites and Ideas. _Avoid_: Collection, folder, board, playlist **Tick**: diff --git a/apps/extension/entrypoints/background.ts b/apps/extension/entrypoints/background.ts index a2173ec3..c67b3d02 100644 --- a/apps/extension/entrypoints/background.ts +++ b/apps/extension/entrypoints/background.ts @@ -1,5 +1,5 @@ import { finishSignIn } from "@/lib/auth"; -import { drain, pluckForPopup, pluckTab, pluckUrl, refreshBadge, resume, type PluckOutcome } from "@/lib/pluck"; +import { drain, pluckForPopup, pluckImage, pluckTab, pluckUrl, refreshBadge, resume, type PluckOutcome } from "@/lib/pluck"; import { settings } from "@/lib/store"; import { t } from "@/lib/t"; @@ -48,7 +48,7 @@ async function onMenu(info: MenuClick, tab?: { id?: number; url?: string; title? case "pluck-link": return info.linkUrl ? pluckUrl(info.linkUrl) : null; case "pluck-image": - return info.srcUrl ? pluckUrl(info.srcUrl) : null; + return info.srcUrl ? pluckImage(info.srcUrl, tab) : null; case "pluck-selection": return tab ? pluckTab(tab, { asHighlight: true }) : null; case "pluck-page": diff --git a/apps/extension/entrypoints/popup/Popup.tsx b/apps/extension/entrypoints/popup/Popup.tsx index ec3fb5c6..2caef555 100644 --- a/apps/extension/entrypoints/popup/Popup.tsx +++ b/apps/extension/entrypoints/popup/Popup.tsx @@ -1,4 +1,4 @@ -import type { Item, Kind, List, PluckResponse, Status, Tag } from "@pluck/shared-schemas"; +import type { Item, Kind, List, ListMembership, PluckResponse, Status, Tag } from "@pluck/shared-schemas"; import { KindGlyph, Logo } from "@pluck/ui"; import { useEffect, useState, type ReactNode } from "react"; import { useFormatter, useTranslations } from "use-intl"; @@ -173,7 +173,8 @@ function Shell({ children }: { children: ReactNode }) { ); } -// One panel for a page in the library, plucked just now or weeks ago: tags, Kind, a List, a note, where it goes next. +// One panel for a page in the library, plucked just now or weeks ago: its Lists first (the place it goes), then tags, +// Kind, a note, where it goes next. function ItemPanel({ initial, fresh, tips, remove }: { initial: Item; fresh: boolean; tips: boolean; remove: (item: Item) => void }) { const t = useTranslations("extension"); const format = useFormatter(); @@ -183,7 +184,9 @@ function ItemPanel({ initial, fresh, tips, remove }: { initial: Item; fresh: boo const [lastListId, setLastListId] = useState(null); const [filter, setFilter] = useState(""); const [note, setNote] = useState(initial.note ?? ""); - const [listId, setListId] = useState(""); + const [inLists, setInLists] = useState>(new Set()); + const [naming, setNaming] = useState(null); // the name of a List being made; null: not making one + const [allLists, setAllLists] = useState(false); const [tabCount, setTabCount] = useState(0); const [footer, setFooter] = useState(null); const [keys, setKeys] = useState(""); @@ -193,10 +196,17 @@ function ItemPanel({ initial, fresh, tips, remove }: { initial: Item; fresh: boo api<{ tags: Tag[] }>("/api/v1/tags").then((r) => setTags(r.tags)).catch(() => {}); api<{ lists: List[] }>("/api/v1/lists").then((r) => setLists(r.lists)).catch(() => {}); get("lastListId").then(setLastListId); + // A page plucked just now is in no List yet; one from before shows the Lists it is in. + if (!fresh) api<{ lists: ListMembership[] }>(`/api/v1/items/${initial.id}?include=lists`).then((r) => setInLists(new Set(r.lists.map((m) => m.list.id)))).catch(() => {}); browser.tabs.query({ currentWindow: true }).then((t) => setTabCount(t.length)); }, []); - const patch = async (body: Record) => setItem((await api<{ item: Item }>(`/api/v1/items/${item.id}`, { method: "PATCH", json: body })).item); + const patch = async (body: Record) => { + const { item: saved } = await api<{ item: Item }>(`/api/v1/items/${item.id}`, { method: "PATCH", json: body }); + setItem(saved); + // A #tag in the note may have made a tag this popup has not heard of: read them again so its chip shows. + if (saved.tagIds.some((id) => !tags.some((t) => t.id === id))) api<{ tags: Tag[] }>("/api/v1/tags").then((r) => setTags(r.tags)).catch(() => {}); + }; const move = async (status: Status) => { await patch({ status }); window.close(); @@ -220,14 +230,35 @@ function ItemPanel({ initial, fresh, tips, remove }: { initial: Item; fresh: boo ...tags.filter((t) => item.tagIds.includes(t.id)), ...tags.filter((t) => !item.tagIds.includes(t.id) && t.name.toLowerCase().includes(typed.toLowerCase())), ].slice(0, 8); - const orderedLists = [...lists].sort((a, b) => Number(b.id === lastListId) - Number(a.id === lastListId)); + // The Lists it is in, then the one used last, then the rest as the server orders them (last touched first). + const rank = (l: List) => (inLists.has(l.id) ? 2 : l.id === lastListId ? 1 : 0); + // Every List it is in always shows (so it can be taken out); the rest fill up to six, and "More" shows them all. + const ranked = [...lists].sort((a, b) => rank(b) - rank(a)); + const shownLists = allLists ? ranked : ranked.slice(0, Math.max(6, inLists.size)); const listName = t("popup.tabs.listName", { date: format.dateTime(new Date(), DAY_MONTH) }); - const addToList = async (id: string) => { - setListId(id); - if (!id) return; - await api(`/api/v1/lists/${id}/items`, { json: { itemId: item.id } }); - await set({ lastListId: id }); + // On and off again, like a tag. The chip changes at once and goes back if the server says no. + const toggleList = async (id: string) => { + const on = !inLists.has(id); + const flip = (to: boolean) => setInLists((cur) => { const next = new Set(cur); if (to) next.add(id); else next.delete(id); return next; }); + flip(on); + try { + if (on) await api(`/api/v1/lists/${id}/items`, { json: { itemId: item.id } }); + else await api(`/api/v1/lists/${id}/items/${item.id}`, { method: "DELETE" }); + if (on) await set({ lastListId: id }); + } catch { + flip(!on); + } + }; + // Enter, or leaving the field: a name makes the List with this Item in it; no name goes back to the chips. + const makeList = async () => { + const name = naming?.trim(); + setNaming(null); + if (!name) return; + const { list } = await api<{ list: List }>("/api/v1/lists", { json: { name, items: [{ itemId: item.id }] } }); + setLists((all) => [list, ...all]); + setInLists((cur) => new Set(cur).add(list.id)); + await set({ lastListId: list.id }); }; const pluckAllTabs = async () => { @@ -277,6 +308,32 @@ function ItemPanel({ initial, fresh, tips, remove }: { initial: Item; fresh: boo ) : ( <>
+
+ {t("popup.plucked.lists")} + {naming === null ? ( +
+ {shownLists.map((l) => ( + + ))} + {ranked.length > shownLists.length && ( + + )} + +
+ ) : ( + setNaming(e.target.value)} + onBlur={() => void makeList().catch(() => {})} + onKeyDown={(e) => e.key === "Enter" && (e.currentTarget as HTMLInputElement).blur()} + /> + )} +
-