Things
All checks were successful
Build and Deploy Nuxt / build (push) Successful in 1m6s

This commit is contained in:
2026-10-13 22:50:51 +02:00
parent 50828af674
commit af76cf1050
18 changed files with 847 additions and 86 deletions

View File

@@ -25,7 +25,7 @@ const isDragOverSidebar = ref(false);
const expandedFolderIds = ref([]);
const expandedEntryIds = ref([]);
const nestedNoteListRef = ref(null);
let actorRefreshInterval;
let entryRefreshInterval;
async function handleSidebarDrop(event) {
if (activeSection.value !== 'notes') return;
@@ -171,17 +171,17 @@ async function fetchCampaignEntries(entityType = activeSection.value, silent = f
if (!silent) entriesError.value = response.data.msg ?? t('campaigns.errors.load');
return;
}
if (entityType === 'actors') {
const previousById = new Map(actors.value.map((actor) => [actor._id, actor]));
actors.value = response.data.actors;
for (const actor of actors.value) {
const previous = previousById.get(actor._id);
if (previous && JSON.stringify(previous) !== JSON.stringify(actor)) {
emitter.emit('campaign-entry-updated', { entityType: 'actor', entry: actor });
}
const kind = entityType === 'actors' ? 'actor' : 'item';
const list = entityType === 'actors' ? actors : items;
const previousById = new Map(list.value.map((entry) => [entry._id, entry]));
list.value = response.data[entityType];
// Tell open windows about Foundry changes landing behind them.
for (const entry of list.value) {
const previous = previousById.get(entry._id);
if (previous && JSON.stringify(previous) !== JSON.stringify(entry)) {
emitter.emit('campaign-entry-updated', { entityType: kind, entry });
}
} else {
items.value = response.data.items;
}
} catch (error) {
if (!silent) entriesError.value = t('campaigns.errors.load');
@@ -213,9 +213,25 @@ function itemSummary(item) {
return `${t(`campaigns.item.categories.${item.category}`)} · ${t(`campaigns.item.rarities.${item.rarity}`)} · ${t('campaigns.item.quantity-short')} ${item.quantity}`;
}
function editItem(entry) {
if (!campaignId.value) return;
CreateWindow('create_campaign_entry', { entityType: 'item', campaign: campaignId.value, entry });
}
function showEntryMenu(entry, entityType) {
const collection = entityType === 'actor' ? 'actor' : 'item';
ShowContextMenu([{
const menuItems = [];
// Characters are edited in their sheet; items get the entry window in edit mode.
if (entityType !== 'actor') {
menuItems.push({
name: t('campaigns.actions.edit'),
icon: '/icons/iconoir/regular/edit.svg',
action: () => { HideContextMenu(); editItem(entry); }
});
}
menuItems.push({
name: t('campaigns.actions.delete'),
icon: '/icons/iconoir/regular/trash.svg',
action: async () => {
@@ -227,7 +243,8 @@ function showEntryMenu(entry, entityType) {
}
} catch (error) {} finally { HideContextMenu(); }
}
}]);
});
ShowContextMenu(menuItems);
}
function toggleEntryDetails(entryId) {
@@ -289,13 +306,16 @@ onMounted(() => {
if (campaignId.value) {
fetchCampaignNotes();
}
actorRefreshInterval = setInterval(() => {
if (activeSection.value === 'actors' && campaignId.value) fetchCampaignEntries('actors', true);
entryRefreshInterval = setInterval(() => {
// Synced Foundry entries land in the background for both lists.
if ((activeSection.value === 'actors' || activeSection.value === 'items') && campaignId.value) {
fetchCampaignEntries(activeSection.value, true);
}
}, 5000);
});
onBeforeUnmount(() => {
clearInterval(actorRefreshInterval);
clearInterval(entryRefreshInterval);
emitter.off('note-created', handleNoteCreated);
emitter.off('note-renamed', handleNoteRenamed);
emitter.off('delete-note', handleNoteDeleted);
@@ -412,7 +432,10 @@ onBeforeUnmount(() => {
<div v-else-if="entriesError" class="sidebar-state error">{{ entriesError }}</div>
<div v-else-if="items.length === 0" class="sidebar-state">{{ t('campaigns.states.empty-items') }}</div>
<div v-for="item in items" :key="item._id" class="entity-entry" role="button" tabindex="0" :aria-expanded="expandedEntryIds.includes(item._id)" @click="toggleEntryDetails(item._id)" @keydown.enter="toggleEntryDetails(item._id)" @keydown.space.prevent="toggleEntryDetails(item._id)" @contextmenu.prevent="showEntryMenu(item, 'item')">
<span class="entity-entry-name">{{ item.name }}</span>
<span class="entity-entry-name-row">
<span class="entity-entry-name">{{ item.name }}</span>
<span v-if="item.foundryItemId" class="entity-entry-sync">{{ t('campaigns.synced') }}</span>
</span>
<span class="entity-entry-meta">{{ itemSummary(item) }}</span>
<template v-if="expandedEntryIds.includes(item._id)">
<span v-if="item.weight !== undefined" class="entity-entry-description">{{ item.weight }} lb</span>
@@ -567,7 +590,14 @@ onBeforeUnmount(() => {
}
.entity-entry:hover { border-color: var(--color-border); background: var(--color-background-soft); }
.entity-entry:focus-visible { outline: 1px solid var(--color-link); }
.entity-entry-name-row { display: flex; align-items: baseline; gap: 6px; }
.entity-entry-name { font-weight: bold; }
.entity-entry-sync {
font-size: 10px;
letter-spacing: 0.04em;
text-transform: uppercase;
opacity: 0.6;
}
.entity-entry-meta, .entity-entry-description { font-size: 12px; opacity: 0.72; }
.entity-entry-description { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }