diff --git a/backend/src/models/Actor.js b/backend/src/models/Actor.js index 2eb11d21..787b19e7 100644 --- a/backend/src/models/Actor.js +++ b/backend/src/models/Actor.js @@ -35,6 +35,13 @@ const ActorSchema = new Schema({ ref: 'Campaign', required: true }, + // The folder this actor stands in: a Folder of the same campaign whose target is + // 'actor' (null = the root of the actor list). + folder: { + type: Schema.Types.ObjectId, + ref: 'Folder', + default: null + }, foundryActorId: { type: String }, date: { type: Date, default: Date.now } }); diff --git a/backend/src/models/Folder.js b/backend/src/models/Folder.js index 138f4134..bb735df3 100644 --- a/backend/src/models/Folder.js +++ b/backend/src/models/Folder.js @@ -1,6 +1,12 @@ const mongoose = require('mongoose'); const Schema = mongoose.Schema; +// Which campaign list a folder belongs to. Every sidebar section files its rows into +// folders of its own, and all of them share this model: note folders are what it has +// always held, and their rows carry no target at all, so anything reading the note tree +// asks with `filterForTarget('note')` and keeps finding them. +const FOLDER_TARGETS = ['note', 'actor', 'item', 'map']; + const FolderSchema = new Schema({ name: { type: String, required: true }, campaign: { @@ -12,10 +18,7 @@ const FolderSchema = new Schema({ type: Schema.Types.ObjectId, ref: 'Folder' }, - // Which campaign list a folder belongs to. Note folders are what this model has - // always held, and their rows carry no target at all, so everything reading the - // note tree asks for `{ target: { $ne: 'item' } }` and keeps finding them. - target: { type: String, enum: ['note', 'item'], default: 'note' }, + target: { type: String, enum: FOLDER_TARGETS, default: 'note' }, // The Foundry item folder this row mirrors, set by the item sync only // (see routes/foundry-link.js). foundryFolderId: { type: String }, @@ -28,4 +31,33 @@ FolderSchema.index( { unique: true, partialFilterExpression: { foundryFolderId: { $type: 'string' } } } ); +// The sections a folder can file rows of, and whether a request names one of them. +FolderSchema.statics.isTarget = function isTarget(target) { + return FOLDER_TARGETS.includes(target); +}; + +// The filter matching one section's folders, to spread into a `find` along with whatever +// else the listing asks for. The notes ask for "none of the other sections" because the +// rows saved before `target` existed carry none at all and are all note folders. +FolderSchema.statics.filterForTarget = function filterForTarget(target) { + if (target === 'note') { + return { target: { $nin: FOLDER_TARGETS.filter((other) => other !== 'note') } }; + } + return { target }; +}; + +// The folder an entry of a section may stand in: `null` is the root of that list, and +// anything else has to be a folder of the same campaign *and* the same section, so a +// move never files an entry where its own list would not show it again. Answers whether +// it does — an id that is none of those says `false` rather than throwing. +FolderSchema.statics.belongsToSection = async function belongsToSection(folderId, campaignId, target) { + if (folderId === null || folderId === undefined || folderId === '') return true; + if (!mongoose.isValidObjectId(folderId)) return false; + + const folder = await this + .findOne({ _id: folderId, campaign: campaignId, ...this.filterForTarget(target) }) + .lean(); + return Boolean(folder); +}; + module.exports = mongoose.model('Folder', FolderSchema); diff --git a/backend/src/models/Map.js b/backend/src/models/Map.js index f18ce092..c3545d21 100644 --- a/backend/src/models/Map.js +++ b/backend/src/models/Map.js @@ -32,6 +32,13 @@ const MapSchema = new Schema({ ref: 'Campaign', required: true }, + // The folder this map stands in: a Folder of the same campaign whose target is + // 'map' (null = the root of the map list). + folder: { + type: Schema.Types.ObjectId, + ref: 'Folder', + default: null + }, date: { type: Date, default: Date.now } }); diff --git a/backend/src/routes/actor.js b/backend/src/routes/actor.js index f48fdea4..2a9f881b 100644 --- a/backend/src/routes/actor.js +++ b/backend/src/routes/actor.js @@ -5,6 +5,7 @@ const upload = require('../services/storage'); const Campaign = require('../models/Campaign'); const Actor = require('../models/Actor'); +const Folder = require('../models/Folder'); const Map = require('../models/Map'); async function userOwnsCampaign(campaignId, userId) { @@ -12,6 +13,15 @@ async function userOwnsCampaign(campaignId, userId) { return Boolean(campaign); } +// Folders the campaign's actors are grouped into, in the shape the sidebar groups by +// (the notes, items and maps each keep a tree of their own, see models/Folder.js). +async function actorFolders(campaignId) { + return Folder.find({ campaign: campaignId, target: 'actor' }) + .select('_id name parentFolder date color') + .sort({ date: -1 }) + .lean(); +} + router.get('/list', async (req, res) => { try { const { campaign } = req.query; @@ -19,7 +29,7 @@ router.get('/list', async (req, res) => { if (!(await userOwnsCampaign(campaign, req.user.id))) return res.json({ status: 'error', msg: 'unauthorized' }); const actors = await Actor.find({ campaign }).sort({ name: 1 }).lean(); - res.json({ status: 'ok', actors }); + res.json({ status: 'ok', actors, folders: await actorFolders(campaign) }); } catch (err) { console.error(err); res.json({ status: 'error', msg: 'errors.internal' }); @@ -46,13 +56,22 @@ router.post('/create', async (req, res) => { router.post('/update', async (req, res) => { try { - const { id, name, species, className, subclass, level, abilityScores, armorClass, speed, proficiencies, inventory, traits, spells, image } = req.body; + const { id, name, species, className, subclass, level, abilityScores, armorClass, speed, proficiencies, inventory, traits, spells, image, folder } = req.body; if (!id) return res.json({ status: 'error', msg: 'errors.missing-data' }); const actor = await Actor.findById(id); if (!actor) return res.json({ status: 'error', msg: 'errors.notfound' }); if (!(await userOwnsCampaign(actor.campaign, req.user.id))) return res.json({ status: 'error', msg: 'unauthorized' }); + // `null` moves the actor to the root of the actor list, an id files it in one of + // this campaign's actor folders; anything else is refused. + if (folder !== undefined) { + if (!(await Folder.belongsToSection(folder || null, actor.campaign, 'actor'))) { + return res.json({ status: 'error', msg: 'errors.notfound' }); + } + actor.folder = folder || null; + } + if (name !== undefined) actor.name = String(name).trim(); if (species !== undefined) actor.species = species; if (className !== undefined) actor.className = className; diff --git a/backend/src/routes/folder.js b/backend/src/routes/folder.js index a12ffdf4..b71ce337 100644 --- a/backend/src/routes/folder.js +++ b/backend/src/routes/folder.js @@ -2,7 +2,9 @@ const express = require('express'); const router = express.Router(); const Campaign = require('../models/Campaign'); +const Actor = require('../models/Actor'); const Folder = require('../models/Folder'); +const Map = require('../models/Map'); const Note = require('../models/Note'); const Item = require('../models/Item'); @@ -13,14 +15,16 @@ async function userOwnsCampaign(campaignId, userId) { router.get('/list', async (req, res) => { try { - const { campaign } = req.query; - if (!campaign) return res.json({ status: 'error', msg: 'errors.missing-data' }); + // Every sidebar section has its own folders; a request that names none means the + // notes, like every caller of this route has until the other sections got theirs. + const { campaign, target = 'note' } = req.query; + if (!campaign || !Folder.isTarget(target)) return res.json({ status: 'error', msg: 'errors.missing-data' }); const hasAccess = await userOwnsCampaign(campaign, req.user.id); if (!hasAccess) return res.json({ status: 'error', msg: 'unauthorized' }); - const folders = await Folder.find({ campaign, target: { $ne: 'item' } }) - .select('_id name date color') + const folders = await Folder.find({ campaign, ...Folder.filterForTarget(target) }) + .select('_id name parentFolder date color') .sort({ date: -1 }) .lean(); @@ -33,15 +37,16 @@ router.get('/list', async (req, res) => { router.post('/create', async (req, res) => { try { - const { name, campaign } = req.body; - if (!name || !campaign) return res.json({ status: 'error', msg: 'errors.missing-data' }); + const { name, campaign, target = 'note' } = req.body; + if (!name || !campaign || !Folder.isTarget(target)) return res.json({ status: 'error', msg: 'errors.missing-data' }); const hasAccess = await userOwnsCampaign(campaign, req.user.id); if (!hasAccess) return res.json({ status: 'error', msg: 'unauthorized' }); const newFolder = new Folder({ name: name.trim(), - campaign + campaign, + target }); await newFolder.save(); res.json({ status: 'ok', folder: newFolder }); @@ -51,6 +56,7 @@ router.post('/create', async (req, res) => { } }); +// Renaming and colouring works the same for the folders of every campaign section. router.post('/update', async (req, res) => { try { const { id, name, color } = req.body; @@ -86,16 +92,25 @@ router.post('/delete', async (req, res) => { async function moveRecursive(folderId) { const subfolders = await Folder.find({ parentFolder: folderId }).select('_id').lean(); + // Every section files rows into a folder of its own, so each of them moves what + // stands in this one to the root of its own list instead of leaving it pointing + // at a folder that is gone. await Note.updateMany( { folder: folderId }, { $set: { folder: null, date: Date.now() } } ); - // Item folders share this model: the items inside move to the root of - // the item list rather than point at a folder that is gone. + await Actor.updateMany( + { folder: folderId }, + { $set: { folder: null } } + ); await Item.updateMany( { folder: folderId }, { $set: { folder: null } } ); + await Map.updateMany( + { folder: folderId }, + { $set: { folder: null } } + ); await Folder.deleteOne({ _id: folderId }); for (const sub of subfolders) { await moveRecursive(sub._id); diff --git a/backend/src/routes/foundry-link.js b/backend/src/routes/foundry-link.js index d76e2ec9..a88147bf 100644 --- a/backend/src/routes/foundry-link.js +++ b/backend/src/routes/foundry-link.js @@ -119,8 +119,8 @@ async function saveFoundryItem(campaign, source, fullSync = false, folders = nul // Which folder of the campaign's item tree the world says this item stands in. // `undefined` means the push says nothing about folders — an item embedded in an // actor, or a module that knows nothing about them — and the item stays where it - // is. The world owns the folder of its own directory, so a move lands on a full - // snapshot too: nothing on the Dragonroll side files items by hand. + // is. The world owns the folder of its own directory, so a move it reports lands on + // a full snapshot too and wins over one a campaign made from its item list. const folder = resolveFoundryItemFolder(source, folders); if (folder !== undefined) item.folder = folder; await item.save(); diff --git a/backend/src/routes/item.js b/backend/src/routes/item.js index c8feb205..3491c813 100644 --- a/backend/src/routes/item.js +++ b/backend/src/routes/item.js @@ -16,7 +16,7 @@ async function userOwnsCampaign(campaignId, userId) { // (the world's own item folders arrive through the sync, see routes/foundry-link.js). async function itemFolders(campaignId) { return Folder.find({ campaign: campaignId, target: 'item' }) - .select('_id name parentFolder date') + .select('_id name parentFolder date color') .sort({ date: -1 }) .lean(); } @@ -56,13 +56,23 @@ router.post('/create', async (req, res) => { router.post('/update', async (req, res) => { try { - const { id, name, category, rarity, quantity, weight, properties, description, image } = req.body; + const { id, name, category, rarity, quantity, weight, properties, description, image, folder } = req.body; if (!id) return res.json({ status: 'error', msg: 'errors.missing-data' }); const item = await Item.findById(id); if (!item) return res.json({ status: 'error', msg: 'errors.notfound' }); if (!(await userOwnsCampaign(item.campaign, req.user.id))) return res.json({ status: 'error', msg: 'unauthorized' }); + // `null` moves the item to the root of the item list, an id files it in one of + // this campaign's item folders; anything else is refused. The linked world owns + // its own folder tree, so a move it reports later wins over one made here. + if (folder !== undefined) { + if (!(await Folder.belongsToSection(folder || null, item.campaign, 'item'))) { + return res.json({ status: 'error', msg: 'errors.notfound' }); + } + item.folder = folder || null; + } + if (name !== undefined) item.name = String(name).trim(); if (category !== undefined) item.category = category; if (rarity !== undefined) item.rarity = rarity; diff --git a/backend/src/routes/map.js b/backend/src/routes/map.js index f7cac9f6..5bff4435 100644 --- a/backend/src/routes/map.js +++ b/backend/src/routes/map.js @@ -5,6 +5,7 @@ const upload = require('../services/storage'); const Campaign = require('../models/Campaign'); const Map = require('../models/Map'); +const Folder = require('../models/Folder'); const Note = require('../models/Note'); const Actor = require('../models/Actor'); @@ -13,6 +14,15 @@ async function userOwnsCampaign(campaignId, userId) { return Boolean(campaign); } +// Folders the campaign's maps are grouped into, in the shape the sidebar groups by +// (the notes, actors and items each keep a tree of their own, see models/Folder.js). +async function mapFolders(campaignId) { + return Folder.find({ campaign: campaignId, target: 'map' }) + .select('_id name parentFolder date color') + .sort({ date: -1 }) + .lean(); +} + // Grid values arrive as strings when the request is a multipart form upload. function toNumber(value, fallback) { if (value === undefined || value === null || value === '') return fallback; @@ -27,7 +37,7 @@ router.get('/list', async (req, res) => { if (!(await userOwnsCampaign(campaign, req.user.id))) return res.json({ status: 'error', msg: 'unauthorized' }); const maps = await Map.find({ campaign }).sort({ name: 1 }).lean(); - res.json({ status: 'ok', maps }); + res.json({ status: 'ok', maps, folders: await mapFolders(campaign) }); } catch (err) { console.error(err); res.json({ status: 'error', msg: 'errors.internal' }); @@ -57,13 +67,22 @@ router.post('/create', upload.single('image'), async (req, res) => { router.post('/update', upload.single('image'), async (req, res) => { try { - const { id, name, gridSize, offsetX, offsetY, scale } = req.body; + const { id, name, gridSize, offsetX, offsetY, scale, folder } = req.body; if (!id) return res.json({ status: 'error', msg: 'errors.missing-data' }); const map = await Map.findById(id); if (!map) return res.json({ status: 'error', msg: 'errors.notfound' }); if (!(await userOwnsCampaign(map.campaign, req.user.id))) return res.json({ status: 'error', msg: 'unauthorized' }); + // `null` moves the map to the root of the map list, an id files it in one of this + // campaign's map folders; anything else is refused. + if (folder !== undefined) { + if (!(await Folder.belongsToSection(folder || null, map.campaign, 'map'))) { + return res.json({ status: 'error', msg: 'errors.notfound' }); + } + map.folder = folder || null; + } + if (name !== undefined) map.name = String(name).trim(); if (gridSize !== undefined) map.gridSize = toNumber(gridSize, map.gridSize); if (offsetX !== undefined) map.offsetX = toNumber(offsetX, map.offsetX); diff --git a/backend/src/routes/note.js b/backend/src/routes/note.js index f9028df5..61aeb265 100644 --- a/backend/src/routes/note.js +++ b/backend/src/routes/note.js @@ -19,9 +19,9 @@ router.get('/list', async (req, res) => { const hasAccess = await userOwnsCampaign(campaign, req.user.id); if (!hasAccess) return res.json({ status: 'error', msg: 'unauthorized' }); - // The note tree only: item folders share this model and would otherwise - // turn up as empty folders between the notes. - const folders = await Folder.find({ campaign, target: { $ne: 'item' } }) + // The note tree only: the folders of the actors, items and maps share this model + // and would otherwise turn up as empty folders between the notes. + const folders = await Folder.find({ campaign, ...Folder.filterForTarget('note') }) .select('_id name parentFolder date color') .sort({ date: -1 }) .lean(); @@ -50,7 +50,7 @@ router.get('/subfolder/list', async (req, res) => { const folderDoc = await Folder.findOne({ _id: folder, campaign }).lean(); if (!folderDoc) return res.json({ status: 'error', msg: 'errors.notfound' }); - const subfolders = await Folder.find({ campaign, parentFolder: folder, target: { $ne: 'item' } }) + const subfolders = await Folder.find({ campaign, parentFolder: folder, ...Folder.filterForTarget('note') }) .select('_id name date color') .sort({ date: -1 }) .lean(); @@ -82,7 +82,7 @@ router.get('/all', async (req, res) => { .sort({ title: 1 }) .lean(); - const folders = await Folder.find({ campaign, target: { $ne: 'item' } }) + const folders = await Folder.find({ campaign, ...Folder.filterForTarget('note') }) .select('_id name parentFolder') .lean(); diff --git a/frontend/app/components/partials/ContentSidebar.vue b/frontend/app/components/partials/ContentSidebar.vue index e6c87212..c32591cc 100644 --- a/frontend/app/components/partials/ContentSidebar.vue +++ b/frontend/app/components/partials/ContentSidebar.vue @@ -5,11 +5,13 @@ import { useI18n } from 'vue-i18n'; import { useCampaignService } from '~/services/Campaign.js'; import { AnchorMap, AnchoredMap, ClearAnchoredMap, SetActivePane } from '~/services/Content.js'; import { emitter } from '~/services/Emitter'; +import { BuildColorMenu } from '~/services/EntryColors'; import { BuildItemRows } from '~/services/ItemFolders'; import Server from '~/services/Server'; import { ClearWindow, CreateWindow, GetFirstWindowId } from '~/services/Windows'; import { HideContextMenu, ShowContextMenu } from '~/services/ContextMenu'; import { ACTOR_DRAG_TYPE } from '~/services/MapTokens'; +import EntryFolderRow from './EntryFolderRow.vue'; import NestedNoteList from './NestedNoteList.vue'; const { Campaign } = useCampaignService(); @@ -18,12 +20,13 @@ const notes = ref([]); const folders = ref([]); const actors = ref([]); const items = ref([]); -// The folders items stand in, and which of them the list has collapsed. Folders are -// open by default: a folder synced from Foundry should show its items, not hide them. -const itemFolders = ref([]); -const collapsedItemFolderIds = ref([]); const maps = ref([]); const entryLists = { actor: actors, item: items, map: maps }; +// Every sidebar section files its rows into folders of its own (see models/Folder.js), so +// each entry list keeps the tree `/actor|item|map/list` sends along. Folders are open by +// default: a folder synced from Foundry should show what stands in it, not hide it. +const entryFolders = { actor: ref([]), item: ref([]), map: ref([]) }; +const collapsedFolderIds = ref([]); const loadingNotes = ref(false); const loadingEntries = ref(false); const notesError = ref(''); @@ -111,12 +114,27 @@ function handleNoteDeleted(noteKey) { notes.value = notes.value.filter(n => n.key !== noteKey); } -function handleFolderSaved() { - fetchCampaignNotes(); +function sectionForTarget(target) { + if (target === 'actor') return 'actors'; + if (target === 'item') return 'items'; + if (target === 'map') return 'maps'; + return null; +} + +function handleFolderSaved(folder) { + // A folder only shows up once the list it belongs to reads it back: the notes refetch + // their tree, an entry list refetches its own (silently, its rows are already there). + const section = sectionForTarget(folder?.target ?? 'note'); + if (!section) { + fetchCampaignNotes(); + return; + } + fetchCampaignEntries(section, true); } function handleFolderDeleted(folderId) { expandedFolderIds.value = expandedFolderIds.value.filter((id) => id !== folderId); + collapsedFolderIds.value = collapsedFolderIds.value.filter((id) => id !== folderId); } function handleCampaignEntryCreated({ entityType, entry }) { @@ -207,9 +225,10 @@ async function fetchCampaignEntries(entityType = activeSection.value, silent = f const previousById = new Map(list.value.map((entry) => [entry._id, entry])); list.value = response.data[entityType] ?? []; - // Items come with the folder tree their world synced over, so the list can - // group them the way the Foundry item directory does. - if (kind === 'item') itemFolders.value = response.data.folders ?? []; + // Every entry list comes with the folders its rows stand in, so the sidebar can + // group them the way the note tree does (and the way the Foundry item directory + // arrives for items). + entryFolders[kind].value = response.data.folders ?? []; // Tell open windows about Foundry changes landing behind them. for (const entry of list.value) { const previous = previousById.get(entry._id); @@ -243,6 +262,14 @@ function createEntry(entityType) { CreateWindow('create_campaign_entry', { entityType, campaign: campaignId.value }); } +// Every section files its rows into folders of its own: the window passes along which +// list the folder belongs to, so the notes, the actors, the items and the maps each keep +// a tree the others never show. +function createFolder(target = 'note') { + if (!campaignId.value) return; + CreateWindow('new_folder', { campaign: campaignId.value, target }); +} + function entrySummary(actor) { const bits = [t(`campaigns.actor.types.${actor.type}`)]; if (actor.species) bits.push(actor.species); @@ -289,6 +316,14 @@ function showEntryMenu(entry, entityType) { }); } + // Rows of every section can be filed into a folder of their own list, like a note + // into a folder of the note tree. + menuItems.push({ + name: t('campaigns.folders.move-to'), + icon: '/icons/iconoir/regular/folder.svg', + context: moveToFolderMenu(entityType, entry) + }); + menuItems.push({ name: t('campaigns.actions.delete'), icon: '/icons/iconoir/regular/trash.svg', @@ -305,6 +340,74 @@ function showEntryMenu(entry, entityType) { ShowContextMenu(menuItems); } +// The menu of a folder row: rename it, colour it, delete it. The notes' folders are +// renamed and coloured the same way, through the same `/folder/*` routes. +function folderMenuItems(folder) { + return [ + { + name: t('campaigns.folders.rename'), icon: '/icons/iconoir/regular/edit-pencil.svg', + action: () => { + HideContextMenu(); + CreateWindow('new_folder', { folderId: folder._id, campaign: campaignId.value, name: folder.name }); + } + }, + { + name: t('campaigns.folders.color'), icon: '/icons/iconoir/regular/palette.svg', + context: BuildColorMenu((color) => setFolderColor(folder, color), { defaultLabel: t('campaigns.folders.default') }) + }, + { divider: true }, + { name: t('campaigns.folders.delete'), icon: '/icons/iconoir/regular/trash.svg', action: () => deleteEntryFolder(folder) } + ]; +} + +async function setFolderColor(folder, color) { + try { + const response = await Server().post('/folder/update', { id: folder._id, color }); + if (response.data.status === 'ok') folder.color = color; + } catch (error) {} finally { + HideContextMenu(); + } +} + +async function deleteEntryFolder(folder) { + try { + const response = await Server().post('/folder/delete', { id: folder._id }); + if (response.data.status !== 'ok') return; + collapsedFolderIds.value = collapsedFolderIds.value.filter((id) => id !== folder._id); + // Whatever stood in the folder moved to the root of the list along with it. + await fetchCampaignEntries(activeSection.value, true); + } catch (error) {} finally { + HideContextMenu(); + } +} + +// The 'move to folder' submenu of an entry: the folders of its own list and its root. +function moveToFolderMenu(entityType, entry) { + const menuItems = entryFolders[entityType].value.map((folder) => ({ + name: folder.name, icon: '/icons/iconoir/regular/folder.svg', + action: () => moveEntryToFolder(entityType, entry, folder._id) + })); + + if (menuItems.length > 0) menuItems.push({ divider: true }); + menuItems.push({ + name: t('campaigns.folders.root'), icon: '/icons/iconoir/regular/xmark-circle.svg', + action: () => moveEntryToFolder(entityType, entry, null) + }); + return menuItems; +} + +async function moveEntryToFolder(entityType, entry, folderId) { + try { + const response = await Server().post(`/${entityType}/update`, { id: entry._id, folder: folderId }); + if (response.data.status !== 'ok') return; + // The row walks over to its new folder. This is the event a Foundry sync of the + // entry sends, so the list regroups and a window open on it sees the change. + emitter.emit('campaign-entry-updated', { entityType, entry: response.data[entityType] }); + } catch (error) {} finally { + HideContextMenu(); + } +} + async function openCharacterSheet(actor) { const existingWindowId = GetFirstWindowId('character_sheet'); if (existingWindowId !== undefined) { @@ -343,38 +446,41 @@ function createNote() { CreateWindow('new_note', { campaign: campaignId.value }); } -function createFolder() { - CreateWindow('new_folder', { campaign: campaignId.value }); -} - function toggleSidebar() { sidebarCollapsed.value = !sidebarCollapsed.value; } const rootNotes = computed(() => notes.value.filter(n => !n._folder)); -// The items of the campaign, each under the folder it stands in (see -// services/ItemFolders.js). Without any folder this is the plain item list. -const itemRows = computed(() => BuildItemRows(items.value, itemFolders.value, collapsedItemFolderIds.value)); +// The rows of each entry list: every folder followed by what stands in it, deeper and +// deeper, the way the item list has done since its folders arrived from the linked world +// (services/ItemFolders.js builds them from the list and the folders the API sends). +// Without any folder this is the plain list, and `row.item` is the entry of the section +// the row belongs to: its actor, item or map. +const entryRows = { + actor: computed(() => BuildItemRows(actors.value, entryFolders.actor.value, collapsedFolderIds.value)), + item: computed(() => BuildItemRows(items.value, entryFolders.item.value, collapsedFolderIds.value)), + map: computed(() => BuildItemRows(maps.value, entryFolders.map.value, collapsedFolderIds.value)) +}; // Rows one step deeper per folder level; the sidebar list's own padding is the base. function rowIndent(depth) { return { paddingLeft: `${10 + depth * 14}px` }; } -function toggleItemFolder(folderId) { - collapsedItemFolderIds.value = collapsedItemFolderIds.value.includes(folderId) - ? collapsedItemFolderIds.value.filter((id) => id !== folderId) - : [...collapsedItemFolderIds.value, folderId]; +function toggleFolder(folderId) { + collapsedFolderIds.value = collapsedFolderIds.value.includes(folderId) + ? collapsedFolderIds.value.filter((id) => id !== folderId) + : [...collapsedFolderIds.value, folderId]; } watch(campaignId, (newVal) => { if (newVal) { actors.value = []; items.value = []; - itemFolders.value = []; - collapsedItemFolderIds.value = []; maps.value = []; + for (const sectionFolders of Object.values(entryFolders)) sectionFolders.value = []; + collapsedFolderIds.value = []; ClearAnchoredMap(); fetchCampaignNotes(); if (isEntrySection(activeSection.value)) fetchCampaignEntries(activeSection.value); @@ -383,9 +489,9 @@ watch(campaignId, (newVal) => { folders.value = []; actors.value = []; items.value = []; - itemFolders.value = []; - collapsedItemFolderIds.value = []; maps.value = []; + for (const sectionFolders of Object.values(entryFolders)) sectionFolders.value = []; + collapsedFolderIds.value = []; notesError.value = ''; entriesError.value = ''; ClearAnchoredMap(); @@ -496,7 +602,7 @@ onBeforeUnmount(() => { - + @@ -528,36 +637,38 @@ onBeforeUnmount(() => {