mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
mobile interface should not create new tabs
This commit is contained in:
parent
ca968a9e31
commit
4f51f73b89
@ -24,7 +24,7 @@ class NoteContext extends Component {
|
|||||||
this.notePath = null;
|
this.notePath = null;
|
||||||
this.noteId = null;
|
this.noteId = null;
|
||||||
this.parentNoteId = null;
|
this.parentNoteId = null;
|
||||||
this.hoistedNoteId = 'root';
|
// hoisted note is kept intentionally
|
||||||
|
|
||||||
this.triggerEvent('noteSwitched', {
|
this.triggerEvent('noteSwitched', {
|
||||||
noteContext: this,
|
noteContext: this,
|
||||||
@ -187,9 +187,13 @@ class NoteContext extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async setHoistedNoteId(noteIdToHoist) {
|
async setHoistedNoteId(noteIdToHoist) {
|
||||||
|
if (this.hoistedNoteId === noteIdToHoist) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.hoistedNoteId = noteIdToHoist;
|
this.hoistedNoteId = noteIdToHoist;
|
||||||
|
|
||||||
if (!this.notePathArray?.includes(noteIdToHoist)) {
|
if (!this.notePathArray?.includes(noteIdToHoist) && !utils.isMobile()) {
|
||||||
await this.setNote(noteIdToHoist);
|
await this.setNote(noteIdToHoist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,14 +25,10 @@ export default class TabManager extends Component {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("Pre-saving", this.noteContexts);
|
|
||||||
|
|
||||||
const openTabs = this.noteContexts
|
const openTabs = this.noteContexts
|
||||||
.map(nc => nc.getTabState())
|
.map(nc => nc.getTabState())
|
||||||
.filter(t => !!t);
|
.filter(t => !!t);
|
||||||
|
|
||||||
console.log("Saving", openTabs);
|
|
||||||
|
|
||||||
await server.put('options', {
|
await server.put('options', {
|
||||||
openTabs: JSON.stringify(openTabs)
|
openTabs: JSON.stringify(openTabs)
|
||||||
});
|
});
|
||||||
@ -58,15 +54,23 @@ export default class TabManager extends Component {
|
|||||||
|
|
||||||
let filteredTabs = [];
|
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) {
|
for (const openTab of tabsToOpen) {
|
||||||
const noteId = treeService.getNoteIdFromNotePath(openTab.notePath);
|
if (openTab.notePath && !(treeService.getNoteIdFromNotePath(openTab.notePath) in froca.notes)) {
|
||||||
|
|
||||||
if (await froca.noteExists(noteId)) {
|
|
||||||
// note doesn't exist so don't try to open tab for it
|
// 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()) {
|
if (utils.isMobile()) {
|
||||||
@ -76,9 +80,9 @@ export default class TabManager extends Component {
|
|||||||
|
|
||||||
if (filteredTabs.length === 0) {
|
if (filteredTabs.length === 0) {
|
||||||
filteredTabs.push({
|
filteredTabs.push({
|
||||||
notePath: this.isMainWindow ? 'root' : '',
|
notePath: glob.extraHoistedNoteId || 'root',
|
||||||
active: true,
|
active: true,
|
||||||
extraHoistedNoteId: glob.extraHoistedNoteId || 'root'
|
hoistedNoteId: glob.extraHoistedNoteId || 'root'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,14 +197,9 @@ export default class TabManager extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async switchToNoteContext(ntxId, notePath) {
|
async switchToNoteContext(ntxId, notePath) {
|
||||||
console.log("Looking for " + ntxId);
|
|
||||||
console.log("Existing", this.noteContexts);
|
|
||||||
|
|
||||||
const noteContext = this.noteContexts.find(nc => nc.ntxId === ntxId)
|
const noteContext = this.noteContexts.find(nc => nc.ntxId === ntxId)
|
||||||
|| await this.openEmptyTab();
|
|| await this.openEmptyTab();
|
||||||
|
|
||||||
console.log(noteContext);
|
|
||||||
|
|
||||||
await this.activateNoteContext(noteContext.ntxId);
|
await this.activateNoteContext(noteContext.ntxId);
|
||||||
|
|
||||||
if (notePath) {
|
if (notePath) {
|
||||||
@ -219,9 +218,19 @@ export default class TabManager extends Component {
|
|||||||
async openEmptyTab(ntxId = null, hoistedNoteId = 'root', mainNtxId = null) {
|
async openEmptyTab(ntxId = null, hoistedNoteId = 'root', mainNtxId = null) {
|
||||||
const noteContext = new NoteContext(ntxId, hoistedNoteId, mainNtxId);
|
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) {
|
if (existingNoteContext) {
|
||||||
|
await existingNoteContext.setHoistedNoteId(hoistedNoteId);
|
||||||
|
|
||||||
return existingNoteContext;
|
return existingNoteContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,6 +226,7 @@ class Froca {
|
|||||||
|
|
||||||
/** @returns {Promise<NoteShort[]>} */
|
/** @returns {Promise<NoteShort[]>} */
|
||||||
async getNotes(noteIds, silentNotFoundError = false) {
|
async getNotes(noteIds, silentNotFoundError = false) {
|
||||||
|
noteIds = Array.from(new Set(noteIds)); // make unique
|
||||||
const missingNoteIds = noteIds.filter(noteId => !this.notes[noteId]);
|
const missingNoteIds = noteIds.filter(noteId => !this.notes[noteId]);
|
||||||
|
|
||||||
await this.reloadNotes(missingNoteIds);
|
await this.reloadNotes(missingNoteIds);
|
||||||
|
@ -39,6 +39,10 @@ const TPL = `
|
|||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
body.mobile .note-detail-editable-text {
|
||||||
|
padding-left: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
.note-detail-editable-text a:hover {
|
.note-detail-editable-text a:hover {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,10 @@ const TPL = `
|
|||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
body.mobile .note-detail-readonly-text {
|
||||||
|
padding-left: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
.note-detail-readonly-text p:first-child, .note-detail-readonly-text::before {
|
.note-detail-readonly-text p:first-child, .note-detail-readonly-text::before {
|
||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user