This commit is contained in:
@@ -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; }
|
||||
|
||||
|
||||
@@ -11,13 +11,27 @@ const id = data.id;
|
||||
const handle = ref(null);
|
||||
const wrapper = ref(null);
|
||||
const saving = ref(false);
|
||||
const form = ref({
|
||||
name: '', type: 'character', species: '', className: '', level: '', background: '', challengeRating: '',
|
||||
category: 'adventuring-gear', rarity: 'common', quantity: 1, weight: '', properties: '', description: ''
|
||||
});
|
||||
|
||||
// The window edits items when the sidebar passes one in; actors have their sheet.
|
||||
const editing = data.entry || null;
|
||||
const isActor = data.entityType === 'actor';
|
||||
const endpoint = isActor ? '/actor/create' : '/item/create';
|
||||
const endpoint = isActor ? '/actor/create' : (editing ? '/item/update' : '/item/create');
|
||||
|
||||
function initialForm() {
|
||||
if (!editing) {
|
||||
return {
|
||||
name: '', type: 'character', species: '', className: '', level: '', background: '', challengeRating: '',
|
||||
category: 'adventuring-gear', rarity: 'common', quantity: 1, weight: '', properties: '', description: ''
|
||||
};
|
||||
}
|
||||
return {
|
||||
name: editing.name ?? '', type: 'character', species: '', className: '', level: '', background: '', challengeRating: '',
|
||||
category: editing.category ?? 'adventuring-gear', rarity: editing.rarity ?? 'common',
|
||||
quantity: editing.quantity ?? 1, weight: editing.weight ?? '', properties: editing.properties ?? '',
|
||||
description: editing.description ?? ''
|
||||
};
|
||||
}
|
||||
|
||||
const form = ref(initialForm());
|
||||
|
||||
onMounted(() => {
|
||||
SetupHandle(id, handle);
|
||||
@@ -31,7 +45,9 @@ async function saveEntry() {
|
||||
if (!form.value.name.trim() || saving.value) return;
|
||||
saving.value = true;
|
||||
try {
|
||||
const payload = { name: form.value.name.trim(), campaign: data.campaign };
|
||||
const payload = isActor
|
||||
? { name: form.value.name.trim(), campaign: data.campaign }
|
||||
: { name: form.value.name.trim(), ...(editing ? { id: editing._id } : { campaign: data.campaign }) };
|
||||
if (!isActor) {
|
||||
for (const field of ['category', 'rarity', 'quantity', 'weight', 'properties', 'description']) {
|
||||
payload[field] = form.value[field];
|
||||
@@ -39,7 +55,7 @@ async function saveEntry() {
|
||||
}
|
||||
const response = await Server().post(endpoint, payload);
|
||||
if (response.data.status === 'ok') {
|
||||
emitter.emit('campaign-entry-created', { entityType: data.entityType, entry: response.data[isActor ? 'actor' : 'item'] });
|
||||
emitter.emit(editing ? 'campaign-entry-updated' : 'campaign-entry-created', { entityType: data.entityType, entry: response.data[isActor ? 'actor' : 'item'] });
|
||||
ClearWindow({ id });
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -54,7 +70,8 @@ async function saveEntry() {
|
||||
<div class="window-wrapper" :id="'window-wrapper-' + id" ref="wrapper">
|
||||
<WindowHandle :window="id" ref="handle" />
|
||||
<div class="body">
|
||||
<h3>{{ $t(isActor ? 'campaigns.actor.new' : 'campaigns.item.new') }}</h3>
|
||||
<h3>{{ $t(editing ? 'campaigns.item.edit' : (isActor ? 'campaigns.actor.new' : 'campaigns.item.new')) }}</h3>
|
||||
<p v-if="!isActor && editing?.foundryItemId" class="sync-note">{{ $t('campaigns.item.foundry-sync-note') }}</p>
|
||||
<form @submit.prevent="saveEntry">
|
||||
<label class="form-field">
|
||||
<span>{{ $t('campaigns.fields.name') }}</span>
|
||||
@@ -109,7 +126,7 @@ async function saveEntry() {
|
||||
</label>
|
||||
<div class="form-actions">
|
||||
<button class="btn-primary sound-click" type="submit" :disabled="saving">
|
||||
{{ saving ? $t('campaigns.actions.saving') : $t('campaigns.actions.submit') }}
|
||||
{{ saving ? $t('campaigns.actions.saving') : $t(editing ? 'campaigns.actions.save' : 'campaigns.actions.submit') }}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
@@ -121,6 +138,7 @@ async function saveEntry() {
|
||||
.window-wrapper { display: flex; align-items: center; flex-direction: column; }
|
||||
.body { width: 100%; padding: 10px 18px 16px; overflow-y: auto; }
|
||||
h3 { margin: 0 0 12px; font-family: MrEavesRemake; }
|
||||
.sync-note { margin: -8px 0 12px; font-size: 12px; opacity: 0.72; }
|
||||
form { display: flex; flex-direction: column; gap: 10px; }
|
||||
.form-field { min-width: 0; display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
|
||||
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
|
||||
|
||||
Reference in New Issue
Block a user