This commit is contained in:
Mo Bitar
2020-04-01 09:53:19 -05:00
parent 822d8553b7
commit 8835fd6ebf
7 changed files with 188 additions and 107 deletions

View File

@@ -143,6 +143,21 @@ class EditorCtrl extends PureCtrl {
}
}
/**
* Because note.locked accesses note.content.appData,
* we do not want to expose the template to direct access to note.locked,
* otherwise an exception will occur when trying to access note.locked if the note
* is deleted. There is potential for race conditions to occur with setState, where a
* previous setState call may have queued a digest cycle, and the digest cycle triggers
* on a deleted note.
*/
get noteLocked() {
if(!this.state.note || this.state.note.deleted) {
return false;
}
return this.state.note.locked;
}
streamItems() {
this.application.streamItems({
contentType: ContentTypes.Note,
@@ -150,7 +165,14 @@ class EditorCtrl extends PureCtrl {
if (!this.state.note) {
return;
}
if (this.state.note.deleted || this.state.note.content.trashed) {
if (this.state.note.deleted) {
await this.setState({
note: null,
noteReady: false
});
return;
}
if (this.state.note.content.trashed) {
return;
}
if (!isPayloadSourceRetrieved(source)) {
@@ -187,7 +209,7 @@ class EditorCtrl extends PureCtrl {
this.application.streamItems({
contentType: ContentTypes.Component,
stream: async ({ items, source }) => {
stream: async ({ items }) => {
if (!this.state.note) {
return;
}
@@ -213,6 +235,8 @@ class EditorCtrl extends PureCtrl {
}
async handleNoteSelectionChange(note, previousNote) {
console.log("SN: handleNoteSelectionChange -> note", note);
console.log(this.application.itemsKeyManager.allItemsKeys);
this.setState({
note: this.application.getAppState().getSelectedNote(),
showExtensions: false,

View File

@@ -171,6 +171,9 @@ class NotesCtrl extends PureCtrl {
/** Note has changed values, reset its flags */
const notes = items.filter((item) => item.content_type === ContentTypes.Note);
for (const note of notes) {
if(note.deleted) {
continue;
}
this.loadFlagsForNote(note);
note.cachedCreatedAtString = note.createdAtString();
note.cachedUpdatedAtString = note.updatedAtString();
@@ -180,7 +183,7 @@ class NotesCtrl extends PureCtrl {
}
async selectNote(note) {
this.application.getAppState().setSelectedNote(note);
return this.application.getAppState().setSelectedNote(note);
}
async createNewNote() {

View File

@@ -3,12 +3,12 @@ import { SNAlertService } from 'snjs';
import { SKAlert } from 'sn-stylekit';
export class AlertService extends SNAlertService {
async alert({
async alert(
title,
text,
closeButtonText = "OK",
onClose
} = {}) {
) {
return new Promise((resolve) => {
const buttons = [
{
@@ -27,7 +27,7 @@ export class AlertService extends SNAlertService {
});
}
async confirm({
async confirm(
title,
text,
confirmButtonText = "Confirm",
@@ -35,7 +35,7 @@ export class AlertService extends SNAlertService {
onConfirm,
onCancel,
destructive = false
} = {}) {
) {
return new Promise((resolve, reject) => {
const buttons = [
{

View File

@@ -40,7 +40,7 @@ export class AppState {
this.unsubApp();
this.unsubApp = null;
this.observers.length = 0;
if(this.rootScopeCleanup1) {
if (this.rootScopeCleanup1) {
this.rootScopeCleanup1();
this.rootScopeCleanup2();
this.rootScopeCleanup1 = null;
@@ -78,7 +78,7 @@ export class AppState {
document.addEventListener('visibilitychange', this.onVisibilityChange);
}
}
onVisibilityChange() {
const visible = document.visibilityState === "visible";
const event = visible
@@ -138,12 +138,16 @@ export class AppState {
await this.application.application.privilegesService.actionRequiresPrivilege(
ProtectedActions.ViewProtectedNotes
)) {
this.application.presentPrivilegesModal(
ProtectedActions.ViewProtectedNotes,
run
);
return new Promise((resolve) => {
this.application.presentPrivilegesModal(
ProtectedActions.ViewProtectedNotes,
() => {
run().then(resolve);
}
);
});
} else {
run();
return run();
}
}