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

@@ -2,13 +2,15 @@
import { ref, onBeforeUnmount, onMounted, watch } from 'vue';
import { emitter } from '~/services/Emitter';
import { BuildColorMenu } from '~/services/EntryColors';
import Server from '~/services/Server';
import Server, { getBaseUrl } from '~/services/Server';
import { CreateWindow } from '~/services/Windows';
import { ShowContextMenu, HideContextMenu } from '~/services/ContextMenu';
const props = defineProps({
folders: Array,
notes: Array,
// Media files standing beside the notes at this level of the tree.
media: { type: Array, default: () => [] },
campaignId: String,
level: { type: Number, default: 0 },
parentFolderId: String,
@@ -44,6 +46,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);
});
@@ -51,6 +54,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);
});
@@ -80,6 +84,12 @@ function handleNoteDeleted(noteKey) {
}
}
function handleMediaDeleted(mediaId) {
for (const entry of Object.values(folderContentCache.value)) {
entry.media = entry.media.filter((m) => m._id !== mediaId);
}
}
function handleFolderSaved(folder) {
const folderId = folder?._id ?? folder?.id;
if (!folderId) return;
@@ -98,6 +108,7 @@ function loadFolderContents(folderId) {
if (res.data.status !== 'ok') return;
folderContentCache.value[folderId] = {
notes: res.data.notes.map(n => ({ key: n._id, title: n.title, text: n.content || '', color: n.color })),
media: res.data.media || [],
subfolders: res.data.subfolders || []
};
}).catch(() => {}).finally(() => {
@@ -113,6 +124,10 @@ function getFolderSubfolders(folderId) {
return folderContentCache.value[folderId]?.subfolders || [];
}
function getFolderMedia(folderId) {
return folderContentCache.value[folderId]?.media || [];
}
// Load contents for all currently-expanded folders
function loadExpandedFolders() {
const idsToLoad = props.level === 0
@@ -125,26 +140,32 @@ function loadExpandedFolders() {
}
}
// A row dragged into a folder is either a note (its key) or a media file ("media:<id>").
async function moveDraggedRow(payload, folderId) {
const mediaId = payload.startsWith('media:') ? payload.slice(6) : null;
await Server().post(mediaId ? '/media/update' : '/note/update', { id: mediaId ?? payload, folder: folderId });
}
async function handleDropNoteOnFolder(folderId, event) {
const noteKey = event.dataTransfer.getData('text/plain');
if (!noteKey || !folderId) return;
const row = event.dataTransfer.getData('text/plain');
if (!row || !folderId) return;
dragHoveredFolderId.value = null;
try {
await Server().post('/note/update', { id: noteKey, folder: folderId });
await moveDraggedRow(row, folderId);
clearCacheAndReloadExpanded();
} catch (e) {}
}
async function handleDropNoteOnRoot(event) {
const noteKey = event.dataTransfer.getData('text/plain');
if (!noteKey) return;
const row = event.dataTransfer.getData('text/plain');
if (!row) return;
dragHoveredFolderId.value = null;
try {
await Server().post('/note/update', { id: noteKey, folder: null });
await moveDraggedRow(row, null);
clearCacheAndReloadExpanded();
} catch (e) {}
}
@@ -172,6 +193,31 @@ function startDragNote(event, note) {
event.dataTransfer.effectAllowed = 'move';
}
// A media row drags into a folder like a note does, under a prefixed key so the drop knows
// which of the two lists it is moving.
function startDragMedia(event, media) {
event.dataTransfer.setData('text/plain', `media:${media._id}`);
event.dataTransfer.effectAllowed = 'move';
}
// The icon a media row leads with, the way the sidebar tells a picture from a sound at a glance.
function mediaIcon(media) {
const type = media?.mimeType ?? '';
if (type.startsWith('image/')) return '/icons/iconoir/regular/media-image.svg';
if (type.startsWith('audio/')) return '/icons/iconoir/regular/music-note.svg';
if (type.startsWith('video/')) return '/icons/iconoir/regular/media-video.svg';
if (type === 'application/pdf') return '/icons/iconoir/regular/page.svg';
return '/icons/iconoir/regular/attachment.svg';
}
function mediaUrl(media) {
return media?.file ? `${getBaseUrl()}/public/${media.file}` : '';
}
function openMedia(media) {
CreateWindow('media_viewer', { media });
}
function setDragHover(id) {
dragHoveredFolderId.value = id;
}
@@ -194,6 +240,18 @@ function buildNoteContextMenu(note) {
];
}
function buildMediaContextMenu(media) {
return [
{ name: 'Open', icon: '/icons/iconoir/regular/attachment.svg', action: () => openMedia(media) },
{
name: 'Move to Folder...', icon: '/icons/iconoir/regular/folder.svg',
context: buildMediaMoveToMenu(media)
},
{ divider: true },
{ name: 'Delete', icon: '/icons/iconoir/regular/trash.svg', action: () => deleteMedia(media) }
];
}
function buildFolderContextMenu(folder) {
if (!folder || !folder._id) return [];
return [
@@ -262,6 +320,35 @@ async function deleteFolder(folderId) {
HideContextMenu();
}
function buildMediaMoveToMenu(media) {
const moveItems = (props.folders || []).map(folder => ({
name: folder.name, icon: '/icons/iconoir/regular/folder.svg', action: () => moveMediaToFolder(media, folder._id)
}));
if (moveItems.length > 0) moveItems.push({ divider: true });
moveItems.push({ name: '(Root)', icon: '/icons/iconoir/regular/attachment.svg', action: () => moveMediaToFolder(media, null) });
return moveItems;
}
async function moveMediaToFolder(media, folderId) {
try {
const response = await Server().post('/media/update', { id: media._id, folder: folderId || null });
if (response.data.status !== 'ok') return;
clearCacheAndReloadExpanded();
} catch (e) {}
HideContextMenu();
}
async function deleteMedia(media) {
try {
const response = await Server().post('/media/delete', { id: media._id });
if (response.data.status === 'ok') emitter.emit('media-deleted', media._id);
} catch (error) {} finally {
HideContextMenu();
}
}
async function moveNoteToFolder(note, folderId) {
try {
const response = await Server().post('/note/update', { id: note.key, folder: folderId || null });
@@ -308,6 +395,7 @@ function createNoteInFolder(folderId) {
v-if="expandedFolderIds.includes(folder._id)"
:folders="getFolderSubfolders(folder._id)"
:notes="getFolderNotes(folder._id)"
:media="getFolderMedia(folder._id)"
:campaign-id="campaignId"
:level="level + 1"
:parent-folder-id="folder._id"
@@ -323,15 +411,24 @@ function createNoteInFolder(folderId) {
<!-- Notes at this level -->
<template v-for="note in notes" :key="note.key">
<button type="button" class="note-link" :class="{ 'has-color': !!note.color }" :style="entryColorStyle(note)" draggable="true" @dragstart="startDragNote($event, note)" @click.stop="$emit('open-note', note)" @contextmenu.prevent="ShowContextMenu(buildNoteContextMenu(note))">
<img class="note-link-icon" src="/icons/iconoir/regular/journal-page.svg" alt="" aria-hidden="true">
<span class="note-link-title">{{ note.title }}</span>
</button>
</template>
<!-- Media files at this level, VSCode-explorer style: the type's icon, then the file name -->
<template v-for="item in media" :key="item._id">
<button type="button" class="note-link media-link" draggable="true" :title="item.name" @dragstart="startDragMedia($event, item)" @click.stop="openMedia(item)" @contextmenu.prevent="ShowContextMenu(buildMediaContextMenu(item))">
<img class="media-link-icon" :src="mediaIcon(item)" alt="" aria-hidden="true">
<span class="media-link-name">{{ item.name }}</span>
</button>
</template>
<!-- Drop zone for root-level notes -->
<div v-if="level === 0" class="root-drop-zone" :class="{ 'drag-over': dragHoveredFolderId === 'root' }" @drop.stop="handleDropNoteOnRoot($event)">
</div>
<div v-if="folders.length === 0 && (!notes || notes.length === 0) && level === 0" class="sidebar-state">Empty</div>
<div v-if="folders.length === 0 && (!notes || notes.length === 0) && (!media || media.length === 0) && level === 0" class="sidebar-state">Empty</div>
</div>
</template>
@@ -353,10 +450,17 @@ function createNoteInFolder(folderId) {
.folder-children { padding-left: 20px; margin-top: 2px; cursor: default; }
.folder-children.drag-over { background: #ffffff22; border-radius: 10px; }
.note-link { width: 100%; padding: 6px; margin: 0; box-shadow: none; border: none; display: flex; flex-direction: column; align-items: flex-start; text-align: left; cursor: grab; border-radius: 8px; }
.note-link { width: 100%; padding: 6px; margin: 0; box-shadow: none; border: none; display: flex; flex-direction: row; align-items: center; gap: 8px; text-align: left; cursor: grab; border-radius: 8px; }
.note-link.has-color { background: color-mix(in srgb, var(--entry-color) 32%, transparent); }
.note-link.has-color:hover { background: color-mix(in srgb, var(--entry-color) 50%, transparent); }
.note-link-title { font-weight: 600; word-break: break-word; }
/* Every note row leads with the page icon, like a media row with the icon of its type. */
.note-link-icon { width: 15px; height: 15px; flex: 0 0 15px; filter: invert(var(--color-icon-invert)); }
.note-link-title { flex: 1; min-width: 0; font-weight: 600; word-break: break-word; }
/* Media rows share the note row's box, with the file type's icon where a note has none. */
.media-link { flex-direction: row; align-items: center; gap: 8px; }
.media-link-icon { width: 15px; height: 15px; flex: 0 0 15px; filter: invert(var(--color-icon-invert)); }
.media-link-name { min-width: 0; font-weight: 500; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-state { padding: 12px; border-radius: 10px; background: var(--color-background-soft); font-size: 14px; }