Skip to content

Build your personal knowledge base with Trilium Notes

mobile interface should not create new tabs

zadam4f51f73b89b2
diff --git a/src/public/app/components/note_context.js b/src/public/app/components/note_context.js
index 47161069fb..d5ebbbcf19 100644
--- a/src/public/app/components/note_context.js
+++ b/src/public/app/components/note_context.js
@@ -24,7 +24,7 @@ class NoteContext extends Component {
this.notePath = null;
this.noteId = null;
this.parentNoteId = null;
- this.hoistedNoteId = 'root';
+ // hoisted note is kept intentionally
this.triggerEvent('noteSwitched', {
noteContext: this,
@@ -187,9 +187,13 @@ class NoteContext extends Component {
}
async setHoistedNoteId(noteIdToHoist) {
+ if (this.hoistedNoteId === noteIdToHoist) {
+ return;
+ }
+
this.hoistedNoteId = noteIdToHoist;
- if (!this.notePathArray?.includes(noteIdToHoist)) {
+ if (!this.notePathArray?.includes(noteIdToHoist) && !utils.isMobile()) {
await this.setNote(noteIdToHoist);
}
diff --git a/src/public/app/components/tab_manager.js b/src/public/app/components/tab_manager.js
index 8868000ba8..92e467a659 100644
--- a/src/public/app/components/tab_manager.js
+++ b/src/public/app/components/tab_manager.js
@@ -25,14 +25,10 @@ export default class TabManager extends Component {
return;
}
- console.log("Pre-saving", this.noteContexts);
-
const openTabs = this.noteContexts
.map(nc => nc.getTabState())
.filter(t => !!t);
- console.log("Saving", openTabs);
-
await server.put('options', {
openTabs: JSON.stringify(openTabs)
});
@@ -58,15 +54,23 @@ export default class TabManager extends Component {
let filteredTabs = [];
- console.log(document.location.hash, tabsToOpen);
+ // preload all notes at once
+ await froca.getNotes([
+ tabsToOpen.map(tab => treeService.getNoteIdFromNotePath(tab.notePath)),
+ tabsToOpen.map(tab => tab.hoistedNoteId),
+ ], true);
for (const openTab of tabsToOpen) {
- const noteId = treeService.getNoteIdFromNotePath(openTab.notePath);
-
- if (await froca.noteExists(noteId)) {
+ if (openTab.notePath && !(treeService.getNoteIdFromNotePath(openTab.notePath) in froca.notes)) {
// note doesn't exist so don't try to open tab for it
- filteredTabs.push(openTab);
+ continue;
}
+
+ if (!froca.getNoteFromCache(openTab.hoistedNoteId)) {
+ continue;
+ }
+
+ filteredTabs.push(openTab);
}
if (utils.isMobile()) {
@@ -76,9 +80,9 @@ export default class TabManager extends Component {
if (filteredTabs.length === 0) {
filteredTabs.push({
- notePath: this.isMainWindow ? 'root' : '',
+ notePath: glob.extraHoistedNoteId || 'root',
active: true,
- extraHoistedNoteId: glob.extraHoistedNoteId || 'root'
+ hoistedNoteId: glob.extraHoistedNoteId || 'root'
});
}
@@ -193,14 +197,9 @@ export default class TabManager extends Component {
}
async switchToNoteContext(ntxId, notePath) {
- console.log("Looking for " + ntxId);
- console.log("Existing", this.noteContexts);
-
const noteContext = this.noteContexts.find(nc => nc.ntxId === ntxId)
|| await this.openEmptyTab();
- console.log(noteContext);
-
await this.activateNoteContext(noteContext.ntxId);
if (notePath) {
@@ -219,9 +218,19 @@ export default class TabManager extends Component {
async openEmptyTab(ntxId = null, hoistedNoteId = 'root', mainNtxId = null) {
const noteContext = new NoteContext(ntxId, hoistedNoteId, mainNtxId);
- const existingNoteContext = this.children.find(nc => nc.ntxId === noteContext.ntxId);
+ let existingNoteContext
+
+ if (utils.isMobile()) {
+ // kind of hacky way to enforce a single tab on mobile interface - all requests to create a new one
+ // are forced to reuse the existing ab instead
+ existingNoteContext = this.getActiveContext();
+ } else {
+ existingNoteContext = this.children.find(nc => nc.ntxId === noteContext.ntxId);
+ }
if (existingNoteContext) {
+ await existingNoteContext.setHoistedNoteId(hoistedNoteId);
+
return existingNoteContext;
}
diff --git a/src/public/app/services/froca.js b/src/public/app/services/froca.js
index 34ff49c595..db40d8275c 100644
--- a/src/public/app/services/froca.js
+++ b/src/public/app/services/froca.js
@@ -226,6 +226,7 @@ class Froca {
/** @returns {Promise<NoteShort[]>} */
async getNotes(noteIds, silentNotFoundError = false) {
+ noteIds = Array.from(new Set(noteIds)); // make unique
const missingNoteIds = noteIds.filter(noteId => !this.notes[noteId]);
await this.reloadNotes(missingNoteIds);
diff --git a/src/public/app/widgets/type_widgets/editable_text.js b/src/public/app/widgets/type_widgets/editable_text.js
index 8f53e72073..2617198591 100644
--- a/src/public/app/widgets/type_widgets/editable_text.js
+++ b/src/public/app/widgets/type_widgets/editable_text.js
@@ -39,6 +39,10 @@ const TPL = `
height: 100%;
}
+ body.mobile .note-detail-editable-text {
+ padding-left: 4px;
+ }
+
.note-detail-editable-text a:hover {
cursor: pointer;
}
diff --git a/src/public/app/widgets/type_widgets/read_only_text.js b/src/public/app/widgets/type_widgets/read_only_text.js
index f8f13debdd..ff02138db3 100644
--- a/src/public/app/widgets/type_widgets/read_only_text.js
+++ b/src/public/app/widgets/type_widgets/read_only_text.js
@@ -35,6 +35,10 @@ const TPL = `
min-height: 50px;
position: relative;
}
+
+ body.mobile .note-detail-readonly-text {
+ padding-left: 10px;
+ }
.note-detail-readonly-text p:first-child, .note-detail-readonly-text::before {
margin-top: 0;