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

@@ -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) {

View File

@@ -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(