Fixes smart tags, toggling archive, and toggling trashed
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -461,11 +461,25 @@ class EditorViewCtrl extends PureViewCtrl implements EditorViewScope {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bypassDebouncer Calling save will debounce by default. You can pass true to save
|
||||
* immediately.
|
||||
* @param isUserModified This field determines if the item will be saved as a user
|
||||
* modification, thus updating the user modified date displayed in the UI
|
||||
* @param dontUpdatePreviews Whether this change should update the note's plain and HTML
|
||||
* preview.
|
||||
* @param customMutate A custom mutator function.
|
||||
* @param closeAfterSync Whether this editor should be closed after the sync starts.
|
||||
* This allows us to make a destructive change, wait for sync to be triggered, then
|
||||
* close the editor (if we closed the editor before sync began, we'd get an exception,
|
||||
* since the debouncer will be triggered on a non-existent editor)
|
||||
*/
|
||||
async saveNote(
|
||||
bypassDebouncer = false,
|
||||
isUserModified = false,
|
||||
dontUpdatePreviews = false,
|
||||
customMutate?: (mutator: NoteMutator) => void
|
||||
customMutate?: (mutator: NoteMutator) => void,
|
||||
closeAfterSync = false
|
||||
) {
|
||||
this.performFirefoxPinnedTabFix();
|
||||
const note = this.note;
|
||||
@@ -493,7 +507,7 @@ class EditorViewCtrl extends PureViewCtrl implements EditorViewScope {
|
||||
return;
|
||||
}
|
||||
this.showSavingStatus();
|
||||
this.application.changeItem(note.uuid, (mutator) => {
|
||||
await this.application.changeItem(note.uuid, (mutator) => {
|
||||
const noteMutator = mutator as NoteMutator;
|
||||
if (customMutate) {
|
||||
customMutate(noteMutator);
|
||||
@@ -518,6 +532,9 @@ class EditorViewCtrl extends PureViewCtrl implements EditorViewScope {
|
||||
: SAVE_TIMEOUT_DEBOUNCE;
|
||||
this.saveTimeout = this.$timeout(() => {
|
||||
this.application.sync();
|
||||
if(closeAfterSync) {
|
||||
this.appState.closeEditor(this.editor);
|
||||
}
|
||||
}, syncDebouceMs);
|
||||
}
|
||||
|
||||
@@ -670,7 +687,6 @@ class EditorViewCtrl extends PureViewCtrl implements EditorViewScope {
|
||||
}
|
||||
);
|
||||
}
|
||||
this.appState.closeEditor(this.editor);
|
||||
},
|
||||
undefined,
|
||||
true,
|
||||
@@ -702,9 +718,9 @@ class EditorViewCtrl extends PureViewCtrl implements EditorViewScope {
|
||||
true,
|
||||
(mutator) => {
|
||||
mutator.trashed = false;
|
||||
}
|
||||
},
|
||||
true
|
||||
);
|
||||
this.appState.closeEditor(this.editor);
|
||||
}
|
||||
|
||||
deleteNotePermanantely() {
|
||||
@@ -790,7 +806,9 @@ class EditorViewCtrl extends PureViewCtrl implements EditorViewScope {
|
||||
true,
|
||||
(mutator) => {
|
||||
mutator.archived = !this.note.archived
|
||||
}
|
||||
},
|
||||
/** If we are unarchiving, and we are in the archived tag, close the editor */
|
||||
this.note.archived && this.appState.selectedTag?.isArchiveTag
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ export function filterAndSortNotes(
|
||||
showArchived: boolean,
|
||||
hidePinned: boolean,
|
||||
filterText: string,
|
||||
sortBy: string,
|
||||
sortBy: string,
|
||||
reverse: boolean,
|
||||
) {
|
||||
const filtered = filterNotes(
|
||||
@@ -37,12 +37,11 @@ export function filterNotes(
|
||||
showArchived: boolean,
|
||||
hidePinned: boolean,
|
||||
filterText: string
|
||||
) {
|
||||
) {
|
||||
return notes.filter((note) => {
|
||||
let canShowArchived = showArchived;
|
||||
const canShowPinned = !hidePinned;
|
||||
const isTrash = selectedTag.isTrashTag;
|
||||
if (!isTrash && note.trashed) {
|
||||
if (!selectedTag.isTrashTag && note.trashed) {
|
||||
return false;
|
||||
}
|
||||
const isSmartTag = selectedTag.isSmartTag();
|
||||
@@ -50,7 +49,7 @@ export function filterNotes(
|
||||
canShowArchived = (
|
||||
canShowArchived ||
|
||||
selectedTag.isArchiveTag ||
|
||||
isTrash
|
||||
selectedTag.isTrashTag
|
||||
);
|
||||
}
|
||||
if (
|
||||
@@ -67,18 +66,18 @@ function noteMatchesQuery(
|
||||
note: SNNote,
|
||||
query: string
|
||||
) {
|
||||
if(query.length === 0) {
|
||||
if (query.length === 0) {
|
||||
return true;
|
||||
}
|
||||
const title = note.safeTitle().toLowerCase();
|
||||
const text = note.safeText().toLowerCase();
|
||||
const lowercaseText = query.toLowerCase();
|
||||
|
||||
|
||||
const quotedText = stringBetweenQuotes(lowercaseText);
|
||||
if(quotedText) {
|
||||
if (quotedText) {
|
||||
return title.includes(quotedText) || text.includes(quotedText);
|
||||
}
|
||||
|
||||
|
||||
if (stringIsUuid(lowercaseText)) {
|
||||
return note.uuid === lowercaseText;
|
||||
}
|
||||
@@ -90,7 +89,7 @@ function noteMatchesQuery(
|
||||
const matchesBody = words.every((word) => {
|
||||
return text.indexOf(word) >= 0;
|
||||
});
|
||||
|
||||
|
||||
return matchesTitle || matchesBody;
|
||||
}
|
||||
|
||||
@@ -108,10 +107,10 @@ function stringIsUuid(text: string) {
|
||||
}
|
||||
|
||||
export function sortNotes(
|
||||
notes: SNNote[] = [],
|
||||
sortBy: string,
|
||||
notes: SNNote[] = [],
|
||||
sortBy: string,
|
||||
reverse: boolean
|
||||
) {
|
||||
) {
|
||||
const sortValueFn = (a: SNNote, b: SNNote, pinCheck = false): number => {
|
||||
if (!pinCheck) {
|
||||
if (a.pinned && b.pinned) {
|
||||
|
||||
@@ -138,7 +138,6 @@ class NotesViewCtrl extends PureViewCtrl {
|
||||
this.handleEditorChange();
|
||||
} else if (eventName === AppStateEvent.PreferencesChanged) {
|
||||
this.reloadPreferences();
|
||||
this.reloadNotes();
|
||||
} else if (eventName === AppStateEvent.EditorFocused) {
|
||||
this.setShowMenuFalse();
|
||||
}
|
||||
@@ -283,12 +282,12 @@ class NotesViewCtrl extends PureViewCtrl {
|
||||
});
|
||||
}
|
||||
|
||||
async reloadNotes() {
|
||||
private async reloadNotes() {
|
||||
this.reloadNotesPromise = this.performPeloadNotes();
|
||||
return this.reloadNotesPromise;
|
||||
}
|
||||
|
||||
async performPeloadNotes() {
|
||||
private async performPeloadNotes() {
|
||||
const tag = this.appState.selectedTag!;
|
||||
if (!tag) {
|
||||
return;
|
||||
@@ -336,7 +335,7 @@ class NotesViewCtrl extends PureViewCtrl {
|
||||
}
|
||||
}
|
||||
|
||||
reloadPreferences() {
|
||||
async reloadPreferences() {
|
||||
const viewOptions = {} as NotesState;
|
||||
const prevSortValue = this.getState().sortBy;
|
||||
let sortBy = this.application!.getPrefsService().getValue(
|
||||
@@ -372,12 +371,9 @@ class NotesViewCtrl extends PureViewCtrl {
|
||||
WebPrefKey.NotesHideTags,
|
||||
false
|
||||
);
|
||||
this.setNotesState({
|
||||
await this.setNotesState({
|
||||
...viewOptions
|
||||
});
|
||||
if (prevSortValue && prevSortValue !== sortBy) {
|
||||
this.selectFirstNote();
|
||||
}
|
||||
const width = this.application!.getPrefsService().getValue(
|
||||
WebPrefKey.NotesPanelWidth
|
||||
);
|
||||
@@ -390,6 +386,10 @@ class NotesViewCtrl extends PureViewCtrl {
|
||||
);
|
||||
}
|
||||
}
|
||||
await this.reloadNotes();
|
||||
if (prevSortValue && prevSortValue !== sortBy) {
|
||||
this.selectFirstNote();
|
||||
}
|
||||
}
|
||||
|
||||
onPanelResize(
|
||||
|
||||
@@ -183,8 +183,14 @@ class TagsViewCtrl extends PureViewCtrl {
|
||||
const noteCounts: NoteCounts = {};
|
||||
for (const tag of allTags) {
|
||||
if (tag.isSmartTag()) {
|
||||
const notes = this.application.notesMatchingSmartTag(tag as SNSmartTag);
|
||||
noteCounts[tag.uuid] = notes.length;
|
||||
/** Other smart tags do not contain counts */
|
||||
if(tag.isAllTag) {
|
||||
const notes = this.application.notesMatchingSmartTag(tag as SNSmartTag)
|
||||
.filter((note) => {
|
||||
return !note.archived && !note.trashed;
|
||||
})
|
||||
noteCounts[tag.uuid] = notes.length;
|
||||
}
|
||||
} else {
|
||||
const notes = this.application.referencesForItem(tag, ContentType.Note)
|
||||
.filter((note) => {
|
||||
|
||||
295
dist/javascripts/app.js
vendored
295
dist/javascripts/app.js
vendored
File diff suppressed because one or more lines are too long
2
dist/javascripts/app.js.map
vendored
2
dist/javascripts/app.js.map
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user