mirror of
https://github.com/zadam/trilium.git
synced 2025-01-31 03:19:11 +08:00
mobile interface should not create new tabs
This commit is contained in:
parent
ca968a9e31
commit
4f51f73b89
5 changed files with 41 additions and 19 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue