More things
Some checks failed
Test / test (push) Failing after 5s
Build and Deploy Nuxt / build (push) Successful in 2m3s

This commit is contained in:
2026-11-20 18:59:01 +01:00
parent b83f64ff9e
commit d61659cfdd
51 changed files with 1777 additions and 3817 deletions

View File

@@ -18,6 +18,7 @@ import NestedNoteList from './NestedNoteList.vue';
const { Campaign } = useCampaignService();
const { t } = useI18n();
const notes = ref([]);
const media = ref([]);
const folders = ref([]);
const actors = ref([]);
const items = ref([]);
@@ -40,14 +41,16 @@ const activeSection = ref('notes');
const isDragOverSidebar = ref(false);
const expandedFolderIds = ref([]);
const nestedNoteListRef = ref(null);
const mediaInput = ref(null);
let entryRefreshInterval;
async function handleSidebarDrop(event) {
if (activeSection.value !== 'notes') return;
const noteKey = event.dataTransfer.getData('text/plain');
if (!noteKey) return;
const row = event.dataTransfer.getData('text/plain');
if (!row) return;
const mediaId = row.startsWith('media:') ? row.slice(6) : null;
try {
await Server().post('/note/update', { id: noteKey, folder: null });
await Server().post(mediaId ? '/media/update' : '/note/update', { id: mediaId ?? row, folder: null });
if (nestedNoteListRef.value) {
nestedNoteListRef.value.clearCacheAndReloadExpanded();
} else {
@@ -118,6 +121,11 @@ function handleNoteDeleted(noteKey) {
notes.value = notes.value.filter(n => n.key !== noteKey);
}
// A media row deleted from the tree anywhere under the sidebar.
function handleMediaDeleted(mediaId) {
media.value = media.value.filter((item) => item._id !== mediaId);
}
function sectionForTarget(target) {
if (target === 'actor') return 'actors';
if (target === 'item') return 'items';
@@ -167,6 +175,7 @@ const campaignId = computed(() => {
async function fetchCampaignNotes() {
if (!campaignId.value) {
notes.value = [];
media.value = [];
folders.value = [];
notesError.value = '';
return;
@@ -180,6 +189,7 @@ async function fetchCampaignNotes() {
if (response.data.status !== 'ok') {
notes.value = [];
media.value = [];
folders.value = [];
notesError.value = response.data.msg ?? 'Unable to load notes.';
return;
@@ -192,8 +202,10 @@ async function fetchCampaignNotes() {
notes.value = response.data.notes.map((note) => {
return { key: note._id, title: note.title, text: note.content ?? '', date: note.date, color: note.color };
});
media.value = response.data.media ?? [];
} catch (error) {
notes.value = [];
media.value = [];
folders.value = [];
notesError.value = 'Unable to load notes.';
} finally {
@@ -503,6 +515,34 @@ function createNote() {
CreateWindow('new_note', { campaign: campaignId.value });
}
function chooseMedia() {
mediaInput.value?.click();
}
// The picked files are uploaded to the root of the note tree, one request per file, and their
// rows join the list as each lands.
async function uploadMedia(event) {
const files = Array.from(event.target.files ?? []);
event.target.value = '';
if (!campaignId.value) return;
for (const file of files) {
const body = new FormData();
body.append('file', file);
body.append('campaign', campaignId.value);
try {
const response = await Server().post('/media/upload', body);
if (response.data.status !== 'ok') {
DisplayToast('red', t(response.data.msg || 'campaigns.media.upload-error'), 3000);
continue;
}
media.value = [response.data.media, ...media.value];
} catch (error) {
DisplayToast('red', t('campaigns.media.upload-error'), 3000);
}
}
}
function toggleSidebar() {
sidebarCollapsed.value = !sidebarCollapsed.value;
}
@@ -536,6 +576,7 @@ watch(campaignId, (newVal) => {
actors.value = [];
items.value = [];
maps.value = [];
media.value = [];
for (const sectionFolders of Object.values(entryFolders)) sectionFolders.value = [];
collapsedFolderIds.value = [];
ClearAnchoredMap();
@@ -543,6 +584,7 @@ watch(campaignId, (newVal) => {
if (isEntrySection(activeSection.value)) fetchCampaignEntries(activeSection.value);
} else {
notes.value = [];
media.value = [];
folders.value = [];
actors.value = [];
items.value = [];
@@ -559,6 +601,7 @@ onMounted(() => {
emitter.on('note-created', handleNoteCreated);
emitter.on('note-renamed', handleNoteRenamed);
emitter.on('delete-note', handleNoteDeleted);
emitter.on('media-deleted', handleMediaDeleted);
emitter.on('folder-saved', handleFolderSaved);
emitter.on('folder-deleted', handleFolderDeleted);
emitter.on('campaign-entry-created', handleCampaignEntryCreated);
@@ -580,6 +623,7 @@ onBeforeUnmount(() => {
emitter.off('note-created', handleNoteCreated);
emitter.off('note-renamed', handleNoteRenamed);
emitter.off('delete-note', handleNoteDeleted);
emitter.off('media-deleted', handleMediaDeleted);
emitter.off('folder-saved', handleFolderSaved);
emitter.off('folder-deleted', handleFolderDeleted);
emitter.off('campaign-entry-created', handleCampaignEntryCreated);
@@ -659,6 +703,10 @@ onBeforeUnmount(() => {
<button class="sidebar-action" type="button" @click="createNote" :disabled="!Campaign" :title="t('campaigns.actions.new-note')" :aria-label="t('campaigns.actions.new-note')">
<img class="sidebar-action-icon" src="/icons/iconoir/regular/plus.svg" alt="" aria-hidden="true">
</button>
<button class="sidebar-action" type="button" @click="chooseMedia" :disabled="!Campaign" :title="t('campaigns.media.upload')" :aria-label="t('campaigns.media.upload')">
<img class="sidebar-action-icon" src="/icons/iconoir/regular/media-image-plus.svg" alt="" aria-hidden="true">
</button>
<input ref="mediaInput" class="media-input" type="file" multiple @change="uploadMedia">
<button class="sidebar-action" type="button" @click="createFolder()" :disabled="!Campaign" :title="t('campaigns.actions.new-folder')" :aria-label="t('campaigns.actions.new-folder')">
<img class="sidebar-action-icon" src="/icons/iconoir/regular/folder.svg" alt="" aria-hidden="true">
</button>
@@ -684,9 +732,9 @@ onBeforeUnmount(() => {
<template v-if="activeSection === 'notes'">
<div v-if="loadingNotes" class="sidebar-state">{{ t('campaigns.states.loading-notes') }}</div>
<div v-else-if="notesError" class="sidebar-state error">{{ notesError }}</div>
<div v-else-if="folders.length === 0 && notes.length === 0" class="sidebar-state">{{ t('campaigns.states.empty-notes') }}</div>
<div v-else-if="folders.length === 0 && notes.length === 0 && media.length === 0" class="sidebar-state">{{ t('campaigns.states.empty-notes') }}</div>
<NestedNoteList v-else ref="nestedNoteListRef"
:parent-folder-id="null" :folders="folders" :notes="rootNotes" :campaign-id="campaignId"
:parent-folder-id="null" :folders="folders" :notes="rootNotes" :media="media" :campaign-id="campaignId"
:expanded-folder-ids="expandedFolderIds" @open-note="openNote"
@reload-notes="fetchCampaignNotes" @toggle-expanded-folder="toggleExpandedFolder" />
</template>
@@ -706,7 +754,10 @@ onBeforeUnmount(() => {
@toggle="toggleFolder(row.folder._id)"
/>
<div v-else class="entity-entry" :style="rowIndent(row.depth)" role="button" tabindex="0" draggable="true" :title="t('campaigns.map.tokens.drag')" @click="openCharacterSheet(row.item)" @keydown.enter="openCharacterSheet(row.item)" @keydown.space.prevent="openCharacterSheet(row.item)" @dragstart="startActorDrag($event, row.item)" @contextmenu.prevent="showEntryMenu(row.item, 'actor')">
<span class="entity-entry-name">{{ row.item.name }}</span>
<span class="entity-entry-title">
<img class="entity-entry-icon" src="/icons/iconoir/regular/user.svg" alt="" aria-hidden="true">
<span class="entity-entry-name">{{ row.item.name }}</span>
</span>
<span class="entity-entry-meta">{{ entrySummary(row.item) }}</span>
</div>
</template>
@@ -731,6 +782,7 @@ onBeforeUnmount(() => {
<span v-if="row.item.image" class="entity-entry-image" aria-hidden="true">
<img :src="itemImageUrl(row.item.image)" alt="">
</span>
<img v-else class="entity-entry-icon" src="/icons/iconoir/regular/box.svg" alt="" aria-hidden="true">
<span class="entity-entry-name" :class="rarityClass(row.item)">{{ row.item.name }}</span>
</span>
</div>
@@ -752,9 +804,12 @@ onBeforeUnmount(() => {
@toggle="toggleFolder(row.folder._id)"
/>
<div v-else class="entity-entry" :style="rowIndent(row.depth)" :class="{ anchored: isAnchoredMap(row.item) }" role="button" tabindex="0" @click="openMapViewer(row.item)" @keydown.enter="openMapViewer(row.item)" @keydown.space.prevent="openMapViewer(row.item)" @contextmenu.prevent="showEntryMenu(row.item, 'map')">
<span class="entity-entry-name-row">
<span class="entity-entry-name">{{ row.item.name }}</span>
<span v-if="isAnchoredMap(row.item)" class="entity-entry-sync">{{ t('campaigns.map.anchored') }}</span>
<span class="entity-entry-title">
<img class="entity-entry-icon" src="/icons/iconoir/regular/map.svg" alt="" aria-hidden="true">
<span class="entity-entry-name-row">
<span class="entity-entry-name">{{ row.item.name }}</span>
<span v-if="isAnchoredMap(row.item)" class="entity-entry-sync">{{ t('campaigns.map.anchored') }}</span>
</span>
</span>
<span class="entity-entry-meta">{{ mapSummary(row.item) }}</span>
<span v-if="!row.item.image" class="entity-entry-description">{{ t('campaigns.map.no-image') }}</span>
@@ -850,6 +905,7 @@ onBeforeUnmount(() => {
}
.sidebar-header-actions { display: flex; align-items: center; gap: 4px; }
.media-input { display: none; }
.sidebar-header-actions .sidebar-action { width: 30px; height: 30px; }
.sidebar-header-actions .sidebar-action-icon { width: 16px; height: 16px; }
@@ -923,6 +979,8 @@ onBeforeUnmount(() => {
}
.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; }
/* Every entry row leads with an icon of what it is: an actor, an item, a map. */
.entity-entry-icon { width: 16px; height: 16px; flex: 0 0 16px; filter: invert(var(--color-icon-invert)); }
/* An item row leads with the item's own icon on the left of its name, standing in for the
"SYNCED" text it used to show (Syndria98/dragonroll#53). */
.entity-entry-title { display: flex; align-items: center; gap: 9px; min-width: 0; }