Foundry and discord bot
All checks were successful
Build and Deploy Nuxt / build (push) Successful in 1m51s

This commit is contained in:
2026-10-11 22:26:29 +02:00
parent a2b512699a
commit 1402045001
65 changed files with 5962 additions and 144 deletions

View File

@@ -1,25 +1,23 @@
<script setup>
import { onMounted, ref } from 'vue';
import { computed, onMounted, ref } from 'vue';
import { AddSound } from '../../services/Sound';
import { useCampaignService } from '~/services/Campaign';
import { ClearWindow } from '~/services/Windows';
import { ClearWindow, CreateChildWindow, GetFirstWindowId } from '~/services/Windows';
const { SetCampaign } = useCampaignService();
const props = defineProps(['data']);
const data = props.data;
const title = ref("");
const title = computed(() => data.name);
const campaignStyle = computed(() => data.color
? { background: `linear-gradient(90deg, ${data.color}, ${data.color}44)` }
: {});
const container = ref(null);
onMounted(() => {
title.value = data.name;
if (data.color && container.value) {
container.value.style.background = `linear-gradient(90deg, ${data.color}, ${data.color}44)`;
}
AddSound(container.value)
});
@@ -27,11 +25,16 @@ function ViewCampaign(){
SetCampaign(data);
ClearWindow({type: "main_menu"});
}
function OpenSettings(){
ClearWindow({type: 'campaign_settings'});
CreateChildWindow(GetFirstWindowId('main_menu'), 'campaign_settings', { campaign: data });
}
</script>
<template>
<div class="campaign-entry-container" ref="container">
<div class="campaign-entry-container" ref="container" :style="campaignStyle">
<div class="main-campaign-entry-container-inner">
<img class="campaign-icon" src="/img/def-avatar.jpg" draggable="false">
<div class="campaign-info">
@@ -39,6 +42,7 @@ function ViewCampaign(){
</div>
<div class="campaign-user-actions">
<button class="btn-primary button-small sound-click" v-on:click.prevent="OpenSettings">{{ $t('main-menu.settings') }}</button>
<button class="btn-primary button-small sound-click" v-on:click.prevent="ViewCampaign">{{ $t('general.open')}}</button>
</div>
</div>
@@ -81,5 +85,7 @@ function ViewCampaign(){
.campaign-user-actions {
margin-left: auto;
display: flex;
gap: 6px;
}
</style>

View File

@@ -1,28 +1,43 @@
<script setup>
import { computed, onMounted, ref, watch } from 'vue';
import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue';
import { useI18n } from 'vue-i18n';
import { useCampaignService } from '~/services/Campaign.js';
import { emitter } from '~/services/Emitter';
import Server from '~/services/Server';
import { CreateWindow } from '~/services/Windows';
import { ClearWindow, CreateWindow, GetFirstWindowId } from '~/services/Windows';
import { HideContextMenu, ShowContextMenu } from '~/services/ContextMenu';
import NestedNoteList from './NestedNoteList.vue';
const { Campaign } = useCampaignService();
const { t } = useI18n();
const notes = ref([]);
const folders = ref([]);
const actors = ref([]);
const items = ref([]);
const loadingNotes = ref(false);
const loadingEntries = ref(false);
const notesError = ref('');
const entriesError = ref('');
const sidebarCollapsed = ref(false);
const activeSection = ref('notes');
const isDragOverSidebar = ref(false);
const expandedFolderIds = ref([]);
const expandedEntryIds = ref([]);
const nestedNoteListRef = ref(null);
let actorRefreshInterval;
async function handleSidebarDrop(event) {
if (activeSection.value !== 'notes') return;
const noteKey = event.dataTransfer.getData('text/plain');
if (!noteKey) return;
try {
await Server().post('/note/update', { id: noteKey, folder: null });
fetchCampaignNotes();
if (nestedNoteListRef.value) {
nestedNoteListRef.value.clearCacheAndReloadExpanded();
} else {
fetchCampaignNotes();
}
} catch (e) {}
}
@@ -58,7 +73,13 @@ function handleNoteCreated(note) {
};
notes.value = notes.value.filter((currentNote) => currentNote.key !== createdNote.key);
notes.value.unshift(createdNote);
// Notes created inside a folder are added by NestedNoteList's own cache handler
const noteFolderId = note.folder?._id ?? note.folder ?? null;
if (!noteFolderId) {
notes.value.unshift(createdNote);
}
openNote(createdNote);
}
@@ -70,6 +91,32 @@ function handleNoteRenamed(data) {
emitter.emit('title-updated', { key: data.key, title: data.title });
}
function handleNoteDeleted(noteKey) {
notes.value = notes.value.filter(n => n.key !== noteKey);
}
function handleFolderSaved() {
fetchCampaignNotes();
}
function handleFolderDeleted(folderId) {
expandedFolderIds.value = expandedFolderIds.value.filter((id) => id !== folderId);
}
function handleCampaignEntryCreated({ entityType, entry }) {
if (!entry || (entry.campaign && String(entry.campaign) !== String(campaignId.value))) return;
const list = entityType === 'actor' ? actors : items;
list.value = [...list.value.filter((current) => current._id !== entry._id), entry]
.sort((a, b) => a.name.localeCompare(b.name));
}
function handleCampaignEntryUpdated({ entityType, entry }) {
if (!entry) return;
const list = entityType === 'actor' ? actors : items;
list.value = list.value.map((current) => current._id === entry._id ? entry : current)
.sort((a, b) => a.name.localeCompare(b.name));
}
const campaignId = computed(() => {
return Campaign.value?._id ?? Campaign.value?.id ?? null;
});
@@ -111,24 +158,97 @@ async function fetchCampaignNotes() {
}
}
async function createNote() {
async function fetchCampaignEntries(entityType = activeSection.value, silent = false) {
if (!campaignId.value || !['actors', 'items'].includes(entityType)) return;
if (!silent) {
loadingEntries.value = true;
entriesError.value = '';
}
try {
const collection = entityType === 'actors' ? 'actor' : 'item';
const response = await Server().get(`/${collection}/list`, { params: { campaign: campaignId.value } });
if (response.data.status !== 'ok') {
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 });
}
}
} else {
items.value = response.data.items;
}
} catch (error) {
if (!silent) entriesError.value = t('campaigns.errors.load');
} finally {
if (!silent) loadingEntries.value = false;
}
}
function selectSection(section) {
activeSection.value = section;
if (section === 'actors' || section === 'items') fetchCampaignEntries(section);
}
function createEntry(entityType) {
if (!campaignId.value) return;
CreateWindow('create_campaign_entry', { entityType, campaign: campaignId.value });
}
function entrySummary(actor) {
const bits = [t(`campaigns.actor.types.${actor.type}`)];
if (actor.species) bits.push(actor.species);
if (actor.className) bits.push(actor.className);
if (actor.level) bits.push(`${t('campaigns.actor.level-short')} ${actor.level}`);
if (actor.challengeRating) bits.push(`${t('campaigns.actor.cr-short')} ${actor.challengeRating}`);
return bits.join(' · ');
}
function itemSummary(item) {
return `${t(`campaigns.item.categories.${item.category}`)} · ${t(`campaigns.item.rarities.${item.rarity}`)} · ${t('campaigns.item.quantity-short')} ${item.quantity}`;
}
function showEntryMenu(entry, entityType) {
const collection = entityType === 'actor' ? 'actor' : 'item';
ShowContextMenu([{
name: t('campaigns.actions.delete'),
icon: '/icons/iconoir/regular/trash.svg',
action: async () => {
try {
const response = await Server().post(`/${collection}/delete`, { id: entry._id });
if (response.data.status === 'ok') {
if (entityType === 'actor') actors.value = actors.value.filter((actor) => actor._id !== entry._id);
else items.value = items.value.filter((item) => item._id !== entry._id);
}
} catch (error) {} finally { HideContextMenu(); }
}
}]);
}
function toggleEntryDetails(entryId) {
expandedEntryIds.value = expandedEntryIds.value.includes(entryId)
? expandedEntryIds.value.filter((id) => id !== entryId)
: [...expandedEntryIds.value, entryId];
}
async function openCharacterSheet(actor) {
const existingWindowId = GetFirstWindowId('character_sheet');
if (existingWindowId !== undefined) {
ClearWindow({ id: existingWindowId });
await nextTick();
}
CreateWindow('character_sheet', { actor });
}
function createNote() {
if (!Campaign.value) return;
const cid = Campaign.value?._id;
try {
const response = await Server().post('/note/create', {
title: 'New note',
content: '',
campaign: cid
});
if (response.data.status !== 'ok') return;
emitter.emit('note-created', response.data.note);
} catch (err) {
console.log(err);
}
CreateWindow('new_note', { campaign: campaignId.value });
}
function createFolder() {
@@ -143,18 +263,46 @@ const rootNotes = computed(() => notes.value.filter(n => !n._folder));
watch(campaignId, (newVal) => {
if (newVal) {
actors.value = [];
items.value = [];
fetchCampaignNotes();
if (activeSection.value === 'actors' || activeSection.value === 'items') fetchCampaignEntries(activeSection.value);
} else {
notes.value = [];
folders.value = [];
actors.value = [];
items.value = [];
notesError.value = '';
entriesError.value = '';
}
});
onMounted(() => {
emitter.on('note-created', handleNoteCreated);
emitter.on('note-renamed', handleNoteRenamed);
emitter.on('delete-note', handleNoteDeleted);
emitter.on('folder-saved', handleFolderSaved);
emitter.on('folder-deleted', handleFolderDeleted);
emitter.on('campaign-entry-created', handleCampaignEntryCreated);
emitter.on('campaign-entry-updated', handleCampaignEntryUpdated);
if (campaignId.value) {
fetchCampaignNotes();
}
actorRefreshInterval = setInterval(() => {
if (activeSection.value === 'actors' && campaignId.value) fetchCampaignEntries('actors', true);
}, 5000);
});
onBeforeUnmount(() => {
clearInterval(actorRefreshInterval);
emitter.off('note-created', handleNoteCreated);
emitter.off('note-renamed', handleNoteRenamed);
emitter.off('delete-note', handleNoteDeleted);
emitter.off('folder-saved', handleFolderSaved);
emitter.off('folder-deleted', handleFolderDeleted);
emitter.off('campaign-entry-created', handleCampaignEntryCreated);
emitter.off('campaign-entry-updated', handleCampaignEntryUpdated);
});
</script>
@@ -166,9 +314,9 @@ onMounted(() => {
type="button"
@click="toggleSidebar"
:aria-expanded="(!sidebarCollapsed).toString()"
aria-controls="campaign-notes-list"
:title="sidebarCollapsed ? 'Expand notes' : 'Collapse notes'"
:aria-label="sidebarCollapsed ? 'Expand notes' : 'Collapse notes'"
aria-controls="campaign-section-list"
:title="sidebarCollapsed ? t('campaigns.actions.expand-sidebar') : t('campaigns.actions.collapse-sidebar')"
:aria-label="sidebarCollapsed ? t('campaigns.actions.expand-sidebar') : t('campaigns.actions.collapse-sidebar')"
>
<img
class="sidebar-action-icon"
@@ -180,72 +328,100 @@ onMounted(() => {
<button
class="sidebar-action"
type="button"
@click="createNote"
:disabled="!Campaign"
title="New note"
aria-label="New note"
:class="{ selected: activeSection === 'notes' }"
type="button" @click="selectSection('notes')"
:title="t('campaigns.sections.notes')" :aria-label="t('campaigns.sections.notes')"
:aria-pressed="(activeSection === 'notes').toString()"
>
<img class="sidebar-action-icon" src="/icons/iconoir/regular/plus.svg" alt="" aria-hidden="true">
<img class="sidebar-action-icon" src="/icons/iconoir/regular/book.svg" alt="" aria-hidden="true">
</button>
<button
class="sidebar-action"
type="button"
@click="createFolder"
:disabled="!Campaign"
title="New folder"
aria-label="New folder"
:class="{ selected: activeSection === 'actors' }"
type="button" @click="selectSection('actors')"
:title="t('campaigns.sections.actors')" :aria-label="t('campaigns.sections.actors')"
:aria-pressed="(activeSection === 'actors').toString()"
>
<img class="sidebar-action-icon" src="/icons/iconoir/regular/folder.svg" alt="" aria-hidden="true">
<img class="sidebar-action-icon" src="/icons/iconoir/regular/user.svg" alt="" aria-hidden="true">
</button>
<button
class="sidebar-action"
type="button"
@click="fetchCampaignNotes"
:disabled="!Campaign || loadingNotes"
title="Refresh notes"
aria-label="Refresh notes"
:class="{ selected: activeSection === 'items' }"
type="button" @click="selectSection('items')"
:title="t('campaigns.sections.items')" :aria-label="t('campaigns.sections.items')"
:aria-pressed="(activeSection === 'items').toString()"
>
<img class="sidebar-action-icon" src="/icons/iconoir/regular/refresh.svg" alt="" aria-hidden="true">
<img class="sidebar-action-icon" src="/icons/iconoir/regular/box.svg" alt="" aria-hidden="true">
</button>
</nav>
<aside class="notes-sidebar" :class="{ collapsed: sidebarCollapsed }">
<div class="sidebar-header">
<div class="sidebar-copy">
<span class="sidebar-eyebrow">Campaign</span>
<strong class="sidebar-title">Notes</strong>
<span class="sidebar-eyebrow">{{ t('campaigns.sidebar-label') }}</span>
<strong class="sidebar-title">{{ t(`campaigns.sections.${activeSection}`) }}</strong>
</div>
<div class="sidebar-header-actions">
<template v-if="activeSection === 'notes'">
<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="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>
<button class="sidebar-action" type="button" @click="fetchCampaignNotes" :disabled="!Campaign || loadingNotes" :title="t('campaigns.actions.refresh')" :aria-label="t('campaigns.actions.refresh')">
<img class="sidebar-action-icon" src="/icons/iconoir/regular/refresh.svg" alt="" aria-hidden="true">
</button>
</template>
<template v-else>
<button class="sidebar-action" type="button" @click="createEntry(activeSection === 'actors' ? 'actor' : 'item')" :disabled="!Campaign" :title="t('campaigns.actions.create', { section: t(`campaigns.sections.${activeSection}`).toLowerCase() })" :aria-label="t('campaigns.actions.create', { section: t(`campaigns.sections.${activeSection}`).toLowerCase() })">
<img class="sidebar-action-icon" src="/icons/iconoir/regular/plus.svg" alt="" aria-hidden="true">
</button>
<button class="sidebar-action" type="button" @click="fetchCampaignEntries(activeSection)" :disabled="!Campaign || loadingEntries" :title="t('campaigns.actions.refresh')" :aria-label="t('campaigns.actions.refresh')">
<img class="sidebar-action-icon" src="/icons/iconoir/regular/refresh.svg" alt="" aria-hidden="true">
</button>
</template>
</div>
</div>
<div class="sidebar-list-drop-wrap" :class="{ 'drag-over': isDragOverSidebar }" id="campaign-notes-list" @dragenter.self="isDragOverSidebar = true" @dragleave.self="isDragOverSidebar = false" @dragover.prevent @drop.stop="handleSidebarDrop">
<div v-if="loadingNotes" class="sidebar-state">
Loading notes...
</div>
<div class="sidebar-list-drop-wrap" :class="{ 'drag-over': activeSection === 'notes' && isDragOverSidebar }" id="campaign-section-list" @dragenter.self="isDragOverSidebar = true" @dragleave.self="isDragOverSidebar = false" @dragover.prevent @drop.stop="handleSidebarDrop">
<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>
<NestedNoteList v-else ref="nestedNoteListRef"
:parent-folder-id="null" :folders="folders" :notes="rootNotes" :campaign-id="campaignId"
:expanded-folder-ids="expandedFolderIds" @open-note="openNote"
@reload-notes="fetchCampaignNotes" @toggle-expanded-folder="toggleExpandedFolder" />
</template>
<div v-else-if="notesError" class="sidebar-state error">
{{ notesError }}
</div>
<template v-else-if="activeSection === 'actors'">
<div v-if="loadingEntries" class="sidebar-state">{{ t('campaigns.states.loading') }}</div>
<div v-else-if="entriesError" class="sidebar-state error">{{ entriesError }}</div>
<div v-else-if="actors.length === 0" class="sidebar-state">{{ t('campaigns.states.empty-actors') }}</div>
<div v-for="actor in actors" :key="actor._id" class="entity-entry" role="button" tabindex="0" @click="openCharacterSheet(actor)" @keydown.enter="openCharacterSheet(actor)" @keydown.space.prevent="openCharacterSheet(actor)" @contextmenu.prevent="showEntryMenu(actor, 'actor')">
<span class="entity-entry-name">{{ actor.name }}</span>
<span class="entity-entry-meta">{{ entrySummary(actor) }}</span>
</div>
</template>
<div v-else-if="folders.length === 0 && notes.length === 0" class="sidebar-state">
No notes in this campaign yet.
</div>
<template v-else>
<NestedNoteList ref="nestedNoteListRef"
:parent-folder-id="null"
:folders="folders"
:notes="rootNotes"
:campaign-id="campaignId"
:expanded-folder-ids="expandedFolderIds"
@open-note="openNote"
@reload-notes="fetchCampaignNotes"
@toggle-expanded-folder="toggleExpandedFolder"
/>
</template>
</div>
<template v-else>
<div v-if="loadingEntries" class="sidebar-state">{{ t('campaigns.states.loading') }}</div>
<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-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>
<span v-if="item.properties" class="entity-entry-description">{{ item.properties }}</span>
<span v-if="item.description" class="entity-entry-description">{{ item.description }}</span>
</template>
</div>
</template>
</div>
</aside>
</div>
</template>
@@ -258,8 +434,8 @@ onMounted(() => {
}
.sidebar-actions {
width: 32px;
min-width: 32px;
width: 46px;
min-width: 46px;
padding: 8px 6px;
border-right: 1px solid var(--color-border);
background-color: var(--color-background-light);
@@ -284,6 +460,11 @@ onMounted(() => {
cursor: pointer;
}
.sidebar-action.selected {
background: var(--color-button-hover);
border-color: var(--color-link);
}
.sidebar-action:hover {
background: var(--color-button-hover);
}
@@ -322,11 +503,16 @@ onMounted(() => {
box-sizing: border-box;
padding: 12px;
display: flex;
align-items: flex-start;
gap: 10px;
align-items: center;
justify-content: space-between;
gap: 8px;
border-bottom: 1px solid var(--color-border);
}
.sidebar-header-actions { display: flex; align-items: center; gap: 4px; }
.sidebar-header-actions .sidebar-action { width: 30px; height: 30px; }
.sidebar-header-actions .sidebar-action-icon { width: 16px; height: 16px; }
.sidebar-copy {
display: flex;
flex-direction: column;
@@ -374,6 +560,17 @@ onMounted(() => {
color: #9e2a2b;
}
.entity-entry {
width: 100%; padding: 9px 10px; border: 1px solid transparent; border-radius: 8px;
background: transparent; color: var(--color-text); text-align: left; display: flex; flex-direction: column;
gap: 3px; cursor: pointer;
}
.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 { font-weight: bold; }
.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; }
@media (max-width: 900px) {
.notes-sidebar {
width: 220px;

View File

@@ -1,5 +1,5 @@
<script setup>
import { ref, onMounted, watch } from 'vue';
import { ref, onBeforeUnmount, onMounted, watch } from 'vue';
import { emitter } from '~/services/Emitter';
import Server from '~/services/Server';
import { CreateWindow } from '~/services/Windows';
@@ -40,8 +40,54 @@ watch(
onMounted(() => {
loadExpandedFolders();
emitter.on('note-created', handleNoteCreated);
emitter.on('note-renamed', handleNoteRenamed);
emitter.on('delete-note', handleNoteDeleted);
emitter.on('folder-saved', handleFolderSaved);
});
onBeforeUnmount(() => {
emitter.off('note-created', handleNoteCreated);
emitter.off('note-renamed', handleNoteRenamed);
emitter.off('delete-note', handleNoteDeleted);
emitter.off('folder-saved', handleFolderSaved);
});
// Keep this instance's folder content cache in sync with changes made anywhere in the app.
// The cache entry for a folder only lives on the instance that renders it, so every
// instance listens and updates whichever entries it owns.
function handleNoteCreated(note) {
if (!note) return;
const folderId = note.folder?._id ?? note.folder ?? null;
const entry = folderId ? folderContentCache.value[folderId] : null;
if (entry) {
entry.notes.unshift({ key: note._id, title: note.title, text: note.content || '' });
}
}
function handleNoteRenamed(data) {
if (!data) return;
for (const entry of Object.values(folderContentCache.value)) {
const note = entry.notes.find((n) => n.key === data.key);
if (note) note.title = data.title;
}
}
function handleNoteDeleted(noteKey) {
for (const entry of Object.values(folderContentCache.value)) {
entry.notes = entry.notes.filter((n) => n.key !== noteKey);
}
}
function handleFolderSaved(folder) {
const folderId = folder?._id ?? folder?.id;
if (!folderId) return;
for (const entry of Object.values(folderContentCache.value)) {
const subfolder = entry.subfolders.find((f) => (f._id ?? f.id) === folderId);
if (subfolder) subfolder.name = folder.name;
}
}
function loadFolderContents(folderId) {
if (loadingFolders.has(folderId)) return;
loadingFolders.add(folderId);
@@ -86,7 +132,7 @@ async function handleDropNoteOnFolder(folderId, event) {
try {
await Server().post('/note/update', { id: noteKey, folder: folderId });
emit('reload-notes');
clearCacheAndReloadExpanded();
} catch (e) {}
}
@@ -98,29 +144,23 @@ async function handleDropNoteOnRoot(event) {
try {
await Server().post('/note/update', { id: noteKey, folder: null });
emit('reload-notes');
clearCacheAndReloadExpanded();
} catch (e) {}
}
// Called on reload — clears cache so expanded folders refetch fresh content
// Called on reload — clears cache and refetches what this instance is responsible for,
// then bubbles the reload up so ancestors (and eventually the sidebar) refresh too
function clearCacheAndReloadExpanded() {
const folderIdsToReLoad = [];
if (props.level === 0) {
for (const id of props.expandedFolderIds) {
if (folderContentCache.value[id]) folderIdsToReLoad.push(id);
delete folderContentCache.value[id];
}
} else if (props.parentFolderId && folderContentCache.value[props.parentFolderId]) {
folderIdsToReLoad.push(props.parentFolderId);
delete folderContentCache.value[props.parentFolderId];
}
const loadedIds = Object.keys(folderContentCache.value);
// Force reactivity by creating a new object
folderContentCache.value = {};
for (const id of folderIdsToReLoad) {
for (const id of loadedIds) {
loadFolderContents(id);
}
emit('reload-notes');
}
// Exposed to parent components
@@ -180,7 +220,7 @@ function renameNote(note) { CreateWindow('rename_note', { title: note.title, key
async function deleteNote(note) {
try {
const response = await Server().post('/note/delete', { id: note.key });
if (response.data.status === 'ok') { emit('reload-notes'); emitter.emit('delete-note', note.key); }
if (response.data.status === 'ok') emitter.emit('delete-note', note.key);
} catch (error) {} finally {
HideContextMenu();
}
@@ -190,7 +230,10 @@ function renameFolder(folderId, name) { CreateWindow('new_folder', { folderId, c
async function deleteFolder(folderId) {
const response = await Server().post('/folder/delete', { id: folderId });
if (response.data.status === 'ok') emit('reload-notes');
if (response.data.status === 'ok') {
emitter.emit('folder-deleted', folderId);
clearCacheAndReloadExpanded();
}
HideContextMenu();
}
@@ -198,16 +241,13 @@ async function moveNoteToFolder(note, folderId) {
try {
const response = await Server().post('/note/update', { id: note.key, folder: folderId || null });
if (response.data.status !== 'ok') return;
emit('reload-notes');
clearCacheAndReloadExpanded();
} catch (e) {}
HideContextMenu();
}
async function createNoteInFolder(folderId) {
try {
const response = await Server().post('/note/create', { title: 'New note', content: '', campaign: props.campaignId, folder: folderId });
if (response.data.status === 'ok') emit('reload-notes');
} catch (e) {}
function createNoteInFolder(folderId) {
CreateWindow('new_note', { campaign: props.campaignId, folder: folderId });
}
</script>
@@ -251,10 +291,6 @@ async function createNoteInFolder(folderId) {
@reload-notes="clearCacheAndReloadExpanded"
@toggle-expanded-folder="toggleExpanded"
/>
<div v-if="expandedFolderIds.includes(folder._id) && folderContentCache[folder._id] !== undefined && (getFolderNotes(folder._id).length === 0 && getFolderSubfolders(folder._id).length === 0)" class="sidebar-state">
Empty folder
</div>
</div>
</div>
</template>