added "hoistedInbox" label

This commit is contained in:
zadam
2021-03-12 21:29:50 +01:00
parent 584fea1992
commit 98f02c3c9a
3 changed files with 49 additions and 17 deletions

View File

@@ -9,8 +9,27 @@ const cls = require('../../services/cls');
const repository = require('../../services/repository');
function getInboxNote(req) {
return attributeService.getNoteWithLabel('inbox')
|| dateNoteService.getDateNote(req.params.date);
const hoistedNote = getHoistedNote();
let inbox;
if (hoistedNote) {
([inbox] = hoistedNote.getDescendantNotesWithLabel('hoistedInbox'));
if (!inbox) {
([inbox] = hoistedNote.getDescendantNotesWithLabel('inbox'));
}
if (!inbox) {
inbox = hoistedNote;
}
}
else {
inbox = attributeService.getNoteWithLabel('inbox')
|| dateNoteService.getDateNote(req.params.date);
}
return inbox;
}
function getDateNote(req) {
@@ -66,27 +85,18 @@ function createSearchNote(req) {
const searchString = params.searchString || "";
let ancestorNoteId = params.ancestorNoteId;
const hoistedNote = cls.getHoistedNoteId() && cls.getHoistedNoteId() !== 'root'
? repository.getNote(cls.getHoistedNoteId())
: null;
const hoistedNote = getHoistedNote();
let searchHome;
if (hoistedNote) {
([searchHome] = hoistedNote.getDescendantNotesWithLabel('hoistedSearchHome'));
}
if (!searchHome) {
const today = dateUtils.localNowDate();
if (!searchHome) {
([searchHome] = hoistedNote.getDescendantNotesWithLabel('searchHome'));
}
searchHome = attributeService.getNoteWithLabel('searchHome')
|| dateNoteService.getDateNote(today);
}
if (hoistedNote) {
if (!hoistedNote.getDescendantNoteIds().includes(searchHome.noteId)) {
// otherwise the note would be saved outside of the hoisted context which is weird
if (!searchHome) {
searchHome = hoistedNote;
}
@@ -94,6 +104,12 @@ function createSearchNote(req) {
ancestorNoteId = hoistedNote.noteId;
}
}
else {
const today = dateUtils.localNowDate();
searchHome = attributeService.getNoteWithLabel('searchHome')
|| dateNoteService.getDateNote(today);
}
const {note} = noteService.createNewNote({
parentNoteId: searchHome.noteId,
@@ -112,6 +128,12 @@ function createSearchNote(req) {
return note;
}
function getHoistedNote() {
return cls.getHoistedNoteId() && cls.getHoistedNoteId() !== 'root'
? repository.getNote(cls.getHoistedNoteId())
: null;
}
module.exports = {
getInboxNote,
getDateNote,