saving note detail

This commit is contained in:
zadam
2020-01-19 21:40:23 +01:00
parent 562c729ed6
commit 423a70d102
9 changed files with 80 additions and 58 deletions

View File

@@ -3,6 +3,7 @@ import utils from "../services/utils.js";
import protectedSessionHolder from "../services/protected_session_holder.js";
import treeCache from "../services/tree_cache.js";
import server from "../services/server.js";
import SpacedUpdate from "../services/spaced_update.js";
const TPL = `
<div class="note-title-container">
@@ -24,43 +25,6 @@ const TPL = `
<input autocomplete="off" value="" class="note-title" tabindex="1">
</div>`;
class SpacedUpdate {
constructor(updater, updateInterval = 1000) {
this.updater = updater;
this.lastUpdated = Date.now();
this.changed = false;
this.updateInterval = updateInterval;
}
scheduleUpdate() {
this.changed = true;
setTimeout(() => this.triggerUpdate())
}
async updateNowIfNecessary() {
if (this.changed) {
this.changed = false;
await this.updater();
}
}
triggerUpdate() {
if (!this.changed) {
return;
}
if (Date.now() - this.lastUpdated > this.updateInterval) {
this.updater();
this.lastUpdated = Date.now();
this.changed = false;
}
else {
// update not triggered but changes are still pending so we need to schedule another check
this.scheduleUpdate();
}
}
}
export default class NoteTitleWidget extends TabAwareWidget {
constructor(appContext) {
super(appContext);