Fixes smart tags, toggling archive, and toggling trashed

This commit is contained in:
Mo Bitar
2020-04-17 09:28:58 -05:00
parent 4451832c9e
commit 2083ce763f
7 changed files with 255 additions and 147 deletions

View File

@@ -7,7 +7,8 @@ import {
SNNote,
SNUserPrefs,
ContentType,
SNSmartTag
SNSmartTag,
PayloadSource
} from 'snjs';
import { WebApplication } from '@/ui_models/application';
import { Editor } from '@/ui_models/editor';
@@ -155,13 +156,22 @@ export class AppState {
streamNotesAndTags() {
this.application!.streamItems(
[ContentType.Note, ContentType.Tag],
async (items) => {
/** Close any editors for deleted notes */
const notes = items.filter((candidate) => candidate.content_type === ContentType.Note) as SNNote[];
for (const note of notes) {
if (note.deleted) {
async (items, source) => {
/** Close any editors for deleted/trashed/archived notes */
if (source === PayloadSource.PreSyncSave) {
const notes = items.filter((candidate) =>
candidate.content_type === ContentType.Note
) as SNNote[];
for (const note of notes) {
const editor = this.editorForNote(note);
if (editor) {
if (!editor) {
continue;
}
if (note.deleted) {
this.closeEditor(editor);
} else if (note.trashed && !this.selectedTag?.isTrashTag) {
this.closeEditor(editor);
} else if (note.archived && !this.selectedTag?.isArchiveTag) {
this.closeEditor(editor);
}
}