Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix recent notes issues
azivner0e69f0c079dd
diff --git a/src/public/javascripts/dialogs/recent_notes.js b/src/public/javascripts/dialogs/recent_notes.jsindex a60a692f1d..99b3869248 100644--- a/src/public/javascripts/dialogs/recent_notes.js+++ b/src/public/javascripts/dialogs/recent_notes.js@@ -1,47 +1,18 @@import treeService from '../services/tree.js';-import messagingService from '../services/messaging.js';import server from '../services/server.js';-import utils from "../services/utils.js";-import treeUtils from "../services/tree_utils.js";const $dialog = $("#recent-notes-dialog");const $searchInput = $('#recent-notes-search-input');-// list of recent note paths-let list = [];--async function reload() {- const result = await server.get('recent-notes');-- list = result.map(r => r.notePath);-}-function addRecentNote(branchId, notePath) {setTimeout(async () => {// we include the note into recent list only if the user stayed on the note at least 5 secondsif (notePath && notePath === treeService.getCurrentNotePath()) {const result = await server.put('recent-notes/' + branchId + '/' + encodeURIComponent(notePath));-- list = result.map(r => r.notePath);}}, 1500);}-async function getNoteTitle(notePath) {- let noteTitle;-- try {- noteTitle = await treeUtils.getNotePathTitle(notePath);- }- catch (e) {- noteTitle = "[error - can't find note title]";-- messagingService.logError("Could not find title for notePath=" + notePath + ", stack=" + e.stack);- }-- return noteTitle;-}-async function showDialog() {glob.activeDialog = $dialog;@@ -54,16 +25,17 @@ async function showDialog() {$searchInput.val('');+ const result = await server.get('recent-notes');+// remove the current note- const recNotes = list.filter(note => note !== treeService.getCurrentNotePath());- const items = [];+ const recNotes = result.filter(note => note.notePath !== treeService.getCurrentNotePath());- for (const notePath of recNotes) {- items.push({- label: await getNoteTitle(notePath),- value: notePath- });- }+ const items = recNotes.map(rn => {+ return {+ label: rn.title,+ value: rn.notePath+ };+ });$searchInput.autocomplete({source: items,@@ -96,18 +68,7 @@ async function showDialog() {});}-setTimeout(reload, 100);--messagingService.subscribeToMessages(syncData => {- if (syncData.some(sync => sync.entityName === 'recent_notes')) {- console.log(utils.now(), "Reloading recent notes because of background changes");-- reload();- }-});-export default {showDialog,- addRecentNote,- reload+ addRecentNote};\ No newline at end of filediff --git a/src/public/javascripts/services/tree_utils.js b/src/public/javascripts/services/tree_utils.jsindex 5e8686be89..548c9fcc51 100644--- a/src/public/javascripts/services/tree_utils.js+++ b/src/public/javascripts/services/tree_utils.js@@ -52,6 +52,15 @@ async function getNotePathTitle(notePath) {const titlePath = [];+ if (notePath.startsWith('root/')) {+ notePath = notePath.substr(5);+ }++ // special case when we want just root's title+ if (notePath === 'root') {+ return await getNoteTitle(notePath);+ }+let parentNoteId = 'root';for (const noteId of notePath.split('/')) {diff --git a/src/routes/api/recent_notes.js b/src/routes/api/recent_notes.jsindex 14d779f5bf..90adc708de 100644--- a/src/routes/api/recent_notes.js+++ b/src/routes/api/recent_notes.js@@ -1,12 +1,12 @@"use strict";const repository = require('../../services/repository');-const dateUtils = require('../../services/date_utils');const optionService = require('../../services/options');const RecentNote = require('../../entities/recent_note');+const noteCacheService = require('../../services/note_cache');async function getRecentNotes() {- return await repository.getEntities(`+ const recentNotes = await repository.getEntities(`SELECTrecent_notes.*FROM@@ -18,6 +18,12 @@ async function getRecentNotes() {ORDER BYdateCreated DESCLIMIT 200`);++ for (const rn of recentNotes) {+ rn.title = noteCacheService.getNoteTitleForPath(rn.notePath.split('/'));+ }++ return recentNotes;}async function addRecentNote(req) {diff --git a/src/services/note_cache.js b/src/services/note_cache.jsindex 34223834b4..29e916a4f1 100644--- a/src/services/note_cache.js+++ b/src/services/note_cache.js@@ -161,6 +161,15 @@ function getNoteTitle(noteId, parentNoteId) {function getNoteTitleForPath(path) {const titles = [];+ if (path[0] === 'root') {+ if (path.length === 1) {+ return getNoteTitle('root');+ }+ else {+ path = path.slice(1);+ }+ }+let parentNoteId = 'root';for (const noteId of path) {@@ -279,5 +288,6 @@ sqlInit.dbReady.then(() => utils.stopWatch("Autocomplete load", load));module.exports = {findNotes,- getNotePath+ getNotePath,+ getNoteTitleForPath};\ No newline at end of file