recent notes are now keyed by note tree id which simplifies things

This commit is contained in:
azivner
2017-12-03 10:06:53 -05:00
parent 41f089b3f4
commit 15faefe8a3
10 changed files with 36 additions and 54 deletions
+5 -12
View File
@@ -8,30 +8,24 @@ const recentNotes = (function() {
const addCurrentAsChildEl = $("#recent-notes-add-current-as-child");
const addRecentAsChildEl = $("#recent-notes-add-recent-as-child");
const noteDetailEl = $('#note-detail');
// list of recent note paths
let list = [];
server.get('recent-notes').then(result => {
list = result.map(r => r.note_tree_id);
list = result.map(r => r.note_path);
});
function addRecentNote(notePath) {
function addRecentNote(noteTreeId, notePath) {
setTimeout(async () => {
// we include the note into recent list only if the user stayed on the note at least 5 seconds
if (notePath && notePath === noteTree.getCurrentNotePath()) {
const result = await server.put('recent-notes/' + encodeURIComponent(notePath));
const result = await server.put('recent-notes/' + noteTreeId + '/' + encodeURIComponent(notePath));
list = result.map(r => r.note_path);
}
}, 1500);
}
// FIXME: this should be probably just refresh upon deletion, not explicit delete
async function removeRecentNote(notePathIdToRemove) {
const result = await server.remove('recent-notes/' + encodeURIComponent(notePathIdToRemove));
list = result.map(r => r.note_path);
}
function showDialog() {
glob.activeDialog = dialogEl;
@@ -146,7 +140,6 @@ const recentNotes = (function() {
return {
showDialog,
addRecentNote,
removeRecentNote
addRecentNote
};
})();
+5 -4
View File
@@ -319,10 +319,11 @@ const noteTree = (function() {
function setCurrentNotePathToHash(node) {
const currentNotePath = treeUtils.getNotePath(node);
const currentNoteTreeId = node.data.note_tree_id;
document.location.hash = currentNotePath;
recentNotes.addRecentNote(currentNotePath);
recentNotes.addRecentNote(currentNoteTreeId, currentNotePath);
}
function initFancyTree(noteTree) {
@@ -343,13 +344,13 @@ const noteTree = (function() {
const beforeNode = node.getPrevSibling();
if (beforeNode !== null) {
treeChanges.moveBeforeNode(node, beforeNode, false);
treeChanges.moveBeforeNode(node, beforeNode);
}
},
"shift+down": node => {
let afterNode = node.getNextSibling();
if (afterNode !== null) {
treeChanges.moveAfterNode(node, afterNode, false);
treeChanges.moveAfterNode(node, afterNode);
}
},
"shift+left": node => {
@@ -625,6 +626,6 @@ const noteTree = (function() {
createNewTopLevelNote,
createNote,
setPrefix,
getNotePathTitle
};
})();
+4 -16
View File
@@ -1,28 +1,20 @@
"use strict";
const treeChanges = (function() {
async function moveBeforeNode(node, beforeNode, changeInPath = true) {
async function moveBeforeNode(node, beforeNode) {
await server.put('notes/' + node.data.note_tree_id + '/move-before/' + beforeNode.data.note_tree_id);
node.moveTo(beforeNode, 'before');
if (changeInPath) {
recentNotes.removeRecentNote(noteTree.getCurrentNotePath());
noteTree.setCurrentNotePathToHash(node);
}
noteTree.setCurrentNotePathToHash(node);
}
async function moveAfterNode(node, afterNode, changeInPath = true) {
async function moveAfterNode(node, afterNode) {
await server.put('notes/' + node.data.note_tree_id + '/move-after/' + afterNode.data.note_tree_id);
node.moveTo(afterNode, 'after');
if (changeInPath) {
recentNotes.removeRecentNote(noteTree.getCurrentNotePath());
noteTree.setCurrentNotePathToHash(node);
}
noteTree.setCurrentNotePathToHash(node);
}
// beware that first arg is noteId and second is noteTreeId!
@@ -47,8 +39,6 @@ const treeChanges = (function() {
toNode.folder = true;
toNode.renderTitle();
recentNotes.removeRecentNote(noteTree.getCurrentNotePath());
noteTree.setCurrentNotePathToHash(node);
}
@@ -75,8 +65,6 @@ const treeChanges = (function() {
node.getParent().renderTitle();
}
recentNotes.removeRecentNote(noteTree.getCurrentNotePath());
let next = node.getNextSibling();
if (!next) {
next = node.getParent();