feat: notes display criteria (#530)
* feat: notes display criteria * chore: remove unused code * chore: update names * chore: update snjs version
This commit is contained in:
@@ -259,7 +259,7 @@ export class AppState {
|
||||
async createEditor(title?: string) {
|
||||
const activeEditor = this.getActiveEditor();
|
||||
const activeTagUuid = this.selectedTag
|
||||
? this.selectedTag.isSmartTag()
|
||||
? this.selectedTag.isSmartTag
|
||||
? undefined
|
||||
: this.selectedTag.uuid
|
||||
: undefined;
|
||||
|
||||
@@ -460,7 +460,7 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
|
||||
await this.editor.insertTemplatedNote();
|
||||
}
|
||||
const selectedTag = this.appState.selectedTag;
|
||||
if (!selectedTag?.isSmartTag() && !selectedTag?.hasRelationshipWithItem(note)) {
|
||||
if (!selectedTag?.isSmartTag && !selectedTag?.hasRelationshipWithItem(note)) {
|
||||
await this.application.changeItem(
|
||||
selectedTag!.uuid,
|
||||
(mutator) => {
|
||||
@@ -1052,7 +1052,7 @@ class EditorViewCtrl extends PureViewCtrl<unknown, EditorState> {
|
||||
if (savedUuid === this.note.uuid) {
|
||||
const selectedTag = this.appState.selectedTag;
|
||||
if (
|
||||
!selectedTag?.isSmartTag() &&
|
||||
!selectedTag?.isSmartTag &&
|
||||
!selectedTag?.hasRelationshipWithItem(this.note)
|
||||
) {
|
||||
this.application.changeAndSaveItem(
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
import { SNNote } from '@standardnotes/snjs';
|
||||
|
||||
export function notePassesFilter(
|
||||
note: SNNote,
|
||||
showArchived: boolean,
|
||||
hidePinned: boolean,
|
||||
filterText: string
|
||||
): boolean {
|
||||
const canShowArchived = showArchived;
|
||||
const canShowPinned = !hidePinned;
|
||||
if ((note.archived && !canShowArchived) || (note.pinned && !canShowPinned)) {
|
||||
return false;
|
||||
}
|
||||
if (note.protected) {
|
||||
const match = noteMatchesQuery(note, filterText);
|
||||
/** Only match title to prevent leaking protected note text */
|
||||
return match === Match.Title || match === Match.TitleAndText;
|
||||
} else {
|
||||
return noteMatchesQuery(note, filterText) !== Match.None;
|
||||
}
|
||||
}
|
||||
|
||||
enum Match {
|
||||
None = 0,
|
||||
Title = 1,
|
||||
Text = 2,
|
||||
TitleAndText = Title + Text,
|
||||
Uuid = 5,
|
||||
}
|
||||
|
||||
function noteMatchesQuery(note: SNNote, query: string): Match {
|
||||
if (query.length === 0) {
|
||||
return Match.TitleAndText;
|
||||
}
|
||||
const title = note.safeTitle().toLowerCase();
|
||||
const text = note.safeText().toLowerCase();
|
||||
const lowercaseText = query.toLowerCase();
|
||||
const words = lowercaseText.split(' ');
|
||||
const quotedText = stringBetweenQuotes(lowercaseText);
|
||||
if (quotedText) {
|
||||
return (
|
||||
(title.includes(quotedText) ? Match.Title : Match.None) +
|
||||
(text.includes(quotedText) ? Match.Text : Match.None)
|
||||
);
|
||||
}
|
||||
if (stringIsUuid(lowercaseText)) {
|
||||
return note.uuid === lowercaseText ? Match.Uuid : Match.None;
|
||||
}
|
||||
const matchesTitle = words.every((word) => {
|
||||
return title.indexOf(word) >= 0;
|
||||
});
|
||||
const matchesBody = words.every((word) => {
|
||||
return text.indexOf(word) >= 0;
|
||||
});
|
||||
return (matchesTitle ? Match.Title : 0) + (matchesBody ? Match.Text : 0);
|
||||
}
|
||||
|
||||
function stringBetweenQuotes(text: string) {
|
||||
const matches = text.match(/"(.*?)"/);
|
||||
return matches ? matches[1] : null;
|
||||
}
|
||||
|
||||
function stringIsUuid(text: string) {
|
||||
const matches = text.match(
|
||||
/\b[0-9a-f]{8}\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\b[0-9a-f]{12}\b/
|
||||
);
|
||||
// eslint-disable-next-line no-unneeded-ternary
|
||||
return matches ? true : false;
|
||||
}
|
||||
@@ -9,6 +9,8 @@ import {
|
||||
PrefKey,
|
||||
findInArray,
|
||||
CollectionSort,
|
||||
UuidString,
|
||||
NotesDisplayCriteria
|
||||
} from '@standardnotes/snjs';
|
||||
import { PureViewCtrl } from '@Views/abstract/pure_view_ctrl';
|
||||
import { AppStateEvent } from '@/ui_models/app_state';
|
||||
@@ -16,10 +18,6 @@ import { KeyboardModifier, KeyboardKey } from '@/services/keyboardManager';
|
||||
import {
|
||||
PANEL_NAME_NOTES
|
||||
} from '@/views/constants';
|
||||
import {
|
||||
notePassesFilter
|
||||
} from './note_utils';
|
||||
import { UuidString } from '@standardnotes/snjs';
|
||||
|
||||
type NotesState = {
|
||||
panelTitle: string
|
||||
@@ -211,7 +209,7 @@ class NotesViewCtrl extends PureViewCtrl<unknown, NotesState> {
|
||||
*/
|
||||
private async createPlaceholderNote() {
|
||||
const selectedTag = this.selectedTag!;
|
||||
if (selectedTag.isSmartTag() && !selectedTag.isAllTag) {
|
||||
if (selectedTag.isSmartTag && !selectedTag.isAllTag) {
|
||||
return;
|
||||
}
|
||||
return this.createNewNote();
|
||||
@@ -331,19 +329,20 @@ class NotesViewCtrl extends PureViewCtrl<unknown, NotesState> {
|
||||
*/
|
||||
private reloadNotesDisplayOptions() {
|
||||
const tag = this.appState.selectedTag!;
|
||||
this.application!.setNotesDisplayOptions(
|
||||
tag,
|
||||
this.state.sortBy! as CollectionSort,
|
||||
this.state.sortReverse! ? 'asc' : 'dsc',
|
||||
(note: SNNote) => {
|
||||
return notePassesFilter(
|
||||
note,
|
||||
this.getState().showArchived! || tag?.isArchiveTag || tag?.isTrashTag,
|
||||
this.getState().hidePinned!,
|
||||
this.getState().noteFilter.text.toLowerCase()
|
||||
);
|
||||
}
|
||||
);
|
||||
const searchText = this.getState().noteFilter.text.toLowerCase();
|
||||
const searchQuery = searchText ? {
|
||||
query: searchText,
|
||||
includeProtectedNoteText: false
|
||||
} : undefined;
|
||||
const criteria = NotesDisplayCriteria.Create({
|
||||
sortProperty: this.state.sortBy! as CollectionSort,
|
||||
sortDirection: this.state.sortReverse! ? 'asc' : 'dsc',
|
||||
tags: [tag],
|
||||
includeArchived: this.getState().showArchived!,
|
||||
includePinned: !this.getState().hidePinned!,
|
||||
searchQuery: searchQuery
|
||||
});
|
||||
this.application!.setNotesDisplayCriteria(criteria);
|
||||
}
|
||||
|
||||
private get selectedTag() {
|
||||
@@ -376,7 +375,7 @@ class NotesViewCtrl extends PureViewCtrl<unknown, NotesState> {
|
||||
const selectedTag = this.appState.selectedTag;
|
||||
if (!selectedTag) {
|
||||
return [];
|
||||
} else if (selectedTag?.isSmartTag()) {
|
||||
} else if (selectedTag?.isSmartTag) {
|
||||
return notes.map((note) =>
|
||||
this.appState
|
||||
.getNoteTags(note)
|
||||
|
||||
@@ -180,7 +180,7 @@ class TagsViewCtrl extends PureViewCtrl<unknown, TagState> {
|
||||
if (tag === this.state.templateTag) {
|
||||
continue;
|
||||
}
|
||||
if (tag.isSmartTag()) {
|
||||
if (tag.isSmartTag) {
|
||||
/** Other smart tags do not contain counts */
|
||||
if (tag.isAllTag) {
|
||||
const notes = this.application.notesMatchingSmartTag(tag as SNSmartTag)
|
||||
|
||||
@@ -68,7 +68,7 @@
|
||||
"@reach/alert-dialog": "^0.13.0",
|
||||
"@reach/dialog": "^0.13.0",
|
||||
"@standardnotes/sncrypto-web": "^1.2.10",
|
||||
"@standardnotes/snjs": "^2.0.61",
|
||||
"@standardnotes/snjs": "^2.0.63",
|
||||
"mobx": "^6.1.6",
|
||||
"preact": "^10.5.12"
|
||||
}
|
||||
|
||||
@@ -1845,10 +1845,10 @@
|
||||
"@standardnotes/sncrypto-common" "^1.2.7"
|
||||
libsodium-wrappers "^0.7.8"
|
||||
|
||||
"@standardnotes/snjs@^2.0.61":
|
||||
version "2.0.61"
|
||||
resolved "https://registry.yarnpkg.com/@standardnotes/snjs/-/snjs-2.0.61.tgz#82608ef48830a80afbc9468ed2d308e59e4e9a08"
|
||||
integrity sha512-MVnzT7cX7oIak9g/xlOJKfWCfBygw8kXtuVHSofdxPhYIPIr1MwK4xkkqho/ZShVfPQEESyj3RaEsOIzKuuL4w==
|
||||
"@standardnotes/snjs@^2.0.63":
|
||||
version "2.0.63"
|
||||
resolved "https://registry.yarnpkg.com/@standardnotes/snjs/-/snjs-2.0.63.tgz#67c775daab38ad45e78548923008ee4157131ec1"
|
||||
integrity sha512-ryF2f1p6lR4aQ84s+bR4GqC7qtro+MzmY4rOIGpXPHbQoIorVcXXy3TjAbN4L4FxkFYdLe4tqU8vwJ00weK23Q==
|
||||
dependencies:
|
||||
"@standardnotes/sncrypto-common" "^1.2.9"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user