V1.12.1: each library entry goes into a campaign once
- A weapon, item, spell or monster from the library can be added to a campaign once. Adding it again is refused: "Longsword is already in this campaign." - The library list leaves out what the campaign already has, so what is left is what can still be added. When nothing is left it says so. - An entry counts as added while the campaign has one by that name, whatever its capitals. Rename or delete the campaign's copy and the library offers it again. This also covers what a world's seed put in. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "frontend",
|
||||
"private": true,
|
||||
"version": "1.12.0",
|
||||
"version": "1.12.1",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -503,6 +503,7 @@ function NpcTrade({
|
||||
|
||||
function LibraryPicker<T extends { key: string; name: string }>({
|
||||
items,
|
||||
taken,
|
||||
onAdd,
|
||||
adding,
|
||||
renderMeta,
|
||||
@@ -510,6 +511,9 @@ function LibraryPicker<T extends { key: string; name: string }>({
|
||||
placeholder,
|
||||
}: {
|
||||
items: T[];
|
||||
// What the campaign already holds: a library entry by one of these names is
|
||||
// left out, since each can be added once.
|
||||
taken: { name: string }[] | undefined;
|
||||
onAdd: (key: string) => void;
|
||||
adding: boolean;
|
||||
renderMeta: (item: T) => string;
|
||||
@@ -518,7 +522,9 @@ function LibraryPicker<T extends { key: string; name: string }>({
|
||||
placeholder: string;
|
||||
}) {
|
||||
const [query, setQuery] = useState('');
|
||||
const filtered = items.filter((i) => i.name.toLowerCase().includes(query.toLowerCase()));
|
||||
const takenNames = new Set((taken ?? []).map((t) => t.name.toLowerCase()));
|
||||
const available = items.filter((i) => !takenNames.has(i.name.toLowerCase()));
|
||||
const filtered = available.filter((i) => i.name.toLowerCase().includes(query.toLowerCase()));
|
||||
const { pageItems, page, pageCount, prevPage, nextPage } = usePagination(filtered, 6);
|
||||
|
||||
return (
|
||||
@@ -537,7 +543,11 @@ function LibraryPicker<T extends { key: string; name: string }>({
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
{filtered.length === 0 && <p style={{ color: 'var(--text-muted)' }}>No matches.</p>}
|
||||
{filtered.length === 0 && (
|
||||
<p style={{ color: 'var(--text-muted)' }}>
|
||||
{available.length === 0 ? 'Everything in the library is already in this campaign.' : 'No matches.'}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
<Pagination page={page} pageCount={pageCount} onPrev={prevPage} onNext={nextPage} />
|
||||
</div>
|
||||
@@ -1262,6 +1272,7 @@ export function CampaignHomePage() {
|
||||
{showWeaponLibrary && library && (
|
||||
<LibraryPicker<LibraryWeapon>
|
||||
items={library.weapons}
|
||||
taken={weapons}
|
||||
adding={addWeaponFromLibrary.isPending}
|
||||
onAdd={(key) => addWeaponFromLibrary.mutate(key)}
|
||||
placeholder="Search the weapon library…"
|
||||
@@ -1378,6 +1389,7 @@ export function CampaignHomePage() {
|
||||
{showItemLibrary && library && (
|
||||
<LibraryPicker<LibraryItem>
|
||||
items={library.items}
|
||||
taken={items}
|
||||
adding={addItemFromLibrary.isPending}
|
||||
onAdd={(key) => addItemFromLibrary.mutate(key)}
|
||||
placeholder="Search the item library: armor, shields, worn gear, supplies…"
|
||||
@@ -1496,6 +1508,7 @@ export function CampaignHomePage() {
|
||||
{showSpellLibrary && library && (
|
||||
<LibraryPicker<LibrarySpell>
|
||||
items={library.spells}
|
||||
taken={spells}
|
||||
adding={addSpellFromLibrary.isPending}
|
||||
onAdd={(key) => addSpellFromLibrary.mutate(key)}
|
||||
placeholder="Search the spell library…"
|
||||
@@ -1615,6 +1628,7 @@ export function CampaignHomePage() {
|
||||
{showMonsterLibrary && library && (
|
||||
<LibraryPicker<LibraryMonster>
|
||||
items={library.monsters}
|
||||
taken={monsters}
|
||||
adding={addMonsterFromLibrary.isPending}
|
||||
onAdd={(key) => addMonsterFromLibrary.mutate(key)}
|
||||
placeholder="Search the monster library…"
|
||||
|
||||
Reference in New Issue
Block a user