Notes/src/public/javascripts/services/hoisted_note.js

61 lines
1.4 KiB
JavaScript
Raw Normal View History

import optionsService from './options.js';
2018-12-11 21:53:56 +01:00
import server from "./server.js";
2018-12-12 20:39:56 +01:00
import tree from "./tree.js";
2019-05-11 19:27:33 +02:00
import noteDetailService from "./note_detail.js";
2018-12-11 21:53:56 +01:00
let hoistedNoteId = 'root';
2018-12-11 21:53:56 +01:00
optionsService.waitForOptions().then(options => {
hoistedNoteId = options.get('hoistedNoteId');
2018-12-11 21:53:56 +01:00
});
function getHoistedNoteNoPromise() {
return hoistedNoteId;
}
2018-12-11 21:53:56 +01:00
async function getHoistedNoteId() {
await optionsService.waitForOptions();
2018-12-11 21:53:56 +01:00
return hoistedNoteId;
}
async function setHoistedNoteId(noteId) {
2019-05-11 19:27:33 +02:00
if (noteId !== 'root') {
await noteDetailService.filterTabs(noteId);
}
hoistedNoteId = noteId;
2018-12-11 21:53:56 +01:00
await server.put('options/hoistedNoteId/' + noteId);
2018-12-12 20:39:56 +01:00
await tree.reload();
2019-05-21 22:07:08 +02:00
2020-01-12 12:30:30 +01:00
const activeTabContext = appContext.getActiveTabContext();
2019-05-21 22:07:08 +02:00
if (activeTabContext) {
await tree.activateNote(activeTabContext.notePath);
}
2018-12-11 21:53:56 +01:00
}
2018-12-15 20:29:08 +01:00
async function unhoist() {
await setHoistedNoteId('root');
}
async function isTopLevelNode(node) {
return await isRootNode(node.getParent());
}
async function isRootNode(node) {
// even though check for 'root' should not be necessary, we keep it just in case
return node.data.noteId === "root"
|| node.data.noteId === await getHoistedNoteId();
}
2018-12-11 21:53:56 +01:00
export default {
getHoistedNoteId,
getHoistedNoteNoPromise,
2018-12-15 20:29:08 +01:00
setHoistedNoteId,
unhoist,
isTopLevelNode,
isRootNode
2018-12-11 21:53:56 +01:00
}