feature: fix smart tags filter for notes view

This commit is contained in:
Radek Czemerys
2020-06-23 22:30:14 +02:00
parent 5ea2d9dfa2
commit 7bd44e32bc
6 changed files with 120 additions and 64 deletions

View File

@@ -244,7 +244,7 @@ PODS:
- React
- react-native-mail (4.1.0):
- React
- react-native-safe-area-context (3.0.5):
- react-native-safe-area-context (3.0.6):
- React
- react-native-sodium (0.4.0):
- React
@@ -534,7 +534,7 @@ SPEC CHECKSUMS:
react-native-aes: ff31f0dd4c791eb423a631ee04570fcf3c618924
react-native-fingerprint-scanner: f0d8190ceaf0b9e1893e3379d78724375b8f6ea7
react-native-mail: a864fb211feaa5845c6c478a3266de725afdce89
react-native-safe-area-context: e768fca90207ee68924b3d0877633f2ce9cc9d68
react-native-safe-area-context: e22a8ca00f758273d2408953965cb8db67da7925
react-native-sodium: ef43e28fdf8d866e68ed06890c32f8d86a570cc7
react-native-webview: 0bacc79175bc44869e4c1a015b9bc21df8cf4feb
React-RCTActionSheet: f41ea8a811aac770e0cc6e0ad6b270c644ea8b7c

View File

@@ -43,7 +43,7 @@
"react-native-keychain": "^6.1.1",
"react-native-mail": "standardnotes/react-native-mail#9862c76",
"react-native-reanimated": "^1.9.0",
"react-native-safe-area-context": "^3.0.5",
"react-native-safe-area-context": "^3.0.6",
"react-native-screens": "^2.9.0",
"react-native-search-box": "standardnotes/react-native-search-box#f61a2b5",
"react-native-sodium": "standardnotes/react-native-sodium#c548383",
@@ -68,12 +68,12 @@
"@types/react-native": "^0.62.13",
"@types/react-native-vector-icons": "^6.4.5",
"@types/styled-components": "^5.1.0",
"@typescript-eslint/eslint-plugin": "^3.3.0",
"@typescript-eslint/parser": "^3.3.0",
"@typescript-eslint/eslint-plugin": "^3.4.0",
"@typescript-eslint/parser": "^3.4.0",
"babel-jest": "^26.0.1",
"concurrently": "^5.2.0",
"detox": "^16.5.0",
"eslint": "^7.3.0",
"eslint": "^7.3.1",
"faker": "^4.1.0",
"jest": "^26.0.1",
"jest-circus": "^26.0.1",

View File

@@ -1,3 +1,5 @@
import { SNNote, SNTag } from 'snjs';
export function isNullOrUndefined(value: unknown) {
return value === null || value === undefined;
}
@@ -23,3 +25,62 @@ export function dateFromJsonString(str: string) {
return str;
}
export function notePassesFilter(
note: SNNote,
selectedTag: SNTag,
showArchived: boolean,
hidePinned: boolean,
filterText: string
) {
let canShowArchived = showArchived;
const canShowPinned = !hidePinned;
if (!selectedTag.isTrashTag && note.trashed) {
return false;
}
const isSmartTag = selectedTag.isSmartTag();
if (isSmartTag) {
canShowArchived =
canShowArchived || selectedTag.isArchiveTag || selectedTag.isTrashTag;
}
if ((note.archived && !canShowArchived) || (note.pinned && !canShowPinned)) {
return false;
}
return noteMatchesQuery(note, filterText);
}
function noteMatchesQuery(note: SNNote, query: string) {
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) {
return title.includes(quotedText) || text.includes(quotedText);
}
if (stringIsUuid(lowercaseText)) {
return note.uuid === lowercaseText;
}
const words = lowercaseText.split(' ');
const matchesTitle = words.every(word => {
return title.indexOf(word) >= 0;
});
const matchesBody = words.every(word => {
return text.indexOf(word) >= 0;
});
return matchesTitle || matchesBody;
}
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/
);
return matches ? true : false;
}

View File

@@ -3,7 +3,6 @@ import React, {
useEffect,
useCallback,
useState,
createRef,
useRef,
} from 'react';
import { ApplicationContext } from '@Root/ApplicationContext';

View File

@@ -24,27 +24,21 @@ type Props = {
};
export const Notes: React.FC<Props> = props => {
// Context
const application = useContext(ApplicationContext);
const theme = useContext(ThemeContext);
const [sortBy, setSortBy] = useState<string>();
const [sortReverse, setSortReverse] = useState<string>();
const [notes, setNotes] = useState<SNNote[]>([]);
const addNote = async () => {
console.log('testing');
const item = await application!.createManagedItem(ContentType.Note, {
title: 'fdsfsfss & Tags',
text: 'tests asdad',
references: [],
});
application?.saveItem(item.uuid);
};
// State
const [sortBy] = useState<CollectionSort>(CollectionSort.UpdatedAt);
const [sortReverse] = useState<string>();
const [notes, setNotes] = useState<SNNote[]>([]);
const reloadNotes = useCallback(() => {
const tag = application!.getAppState().selectedTag;
if (!tag) {
return;
}
setNotes(application!.getDisplayableItems(ContentType.Note) as SNNote[]);
}, [application]);
@@ -63,6 +57,7 @@ export const Notes: React.FC<Props> = props => {
const matchesTag = tag.isSmartTag()
? note.satisfiesPredicate((tag as SNSmartTag).predicate)
: tag.hasRelationshipWithItem(note);
return matchesTag;
// notePassesFilter(
// note,

View File

@@ -2,7 +2,7 @@
# yarn lockfile v1
"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.10.1", "@babel/code-frame@^7.10.3":
"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.10.3":
version "7.10.3"
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.10.3.tgz#324bcfd8d35cd3d47dae18cde63d752086435e9a"
integrity sha512-fDx9eNW0qz0WkUeqL6tXEXzVlPh6Y5aCDEZesl0xBGA8ndRukX91Uk44ZqnkECp01NAZUdCAl+aiQNGi0k88Eg==
@@ -31,7 +31,7 @@
semver "^5.4.1"
source-map "^0.5.0"
"@babel/generator@^7.10.1", "@babel/generator@^7.10.2", "@babel/generator@^7.10.3", "@babel/generator@^7.5.0":
"@babel/generator@^7.10.3", "@babel/generator@^7.5.0":
version "7.10.3"
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.10.3.tgz#32b9a0d963a71d7a54f5f6c15659c3dbc2a523a5"
integrity sha512-drt8MUHbEqRzNR0xnF8nMehbY11b1SDkRw03PSNH/3Rb2Z35oxkddVSi3rcaak0YJQ86PCuE7Qx1jSFhbLNBMA==
@@ -111,7 +111,7 @@
"@babel/traverse" "^7.8.3"
"@babel/types" "^7.8.3"
"@babel/helper-function-name@^7.10.1", "@babel/helper-function-name@^7.10.3", "@babel/helper-function-name@^7.8.3", "@babel/helper-function-name@^7.9.5":
"@babel/helper-function-name@^7.10.3", "@babel/helper-function-name@^7.8.3", "@babel/helper-function-name@^7.9.5":
version "7.10.3"
resolved "https://registry.yarnpkg.com/@babel/helper-function-name/-/helper-function-name-7.10.3.tgz#79316cd75a9fa25ba9787ff54544307ed444f197"
integrity sha512-FvSj2aiOd8zbeqijjgqdMDSyxsGHaMt5Tr0XjQsGKHD3/1FP3wksjnLAWzxw7lvXiej8W1Jt47SKTZ6upQNiRw==
@@ -120,7 +120,7 @@
"@babel/template" "^7.10.3"
"@babel/types" "^7.10.3"
"@babel/helper-get-function-arity@^7.10.1", "@babel/helper-get-function-arity@^7.10.3", "@babel/helper-get-function-arity@^7.8.3":
"@babel/helper-get-function-arity@^7.10.3", "@babel/helper-get-function-arity@^7.8.3":
version "7.10.3"
resolved "https://registry.yarnpkg.com/@babel/helper-get-function-arity/-/helper-get-function-arity-7.10.3.tgz#3a28f7b28ccc7719eacd9223b659fdf162e4c45e"
integrity sha512-iUD/gFsR+M6uiy69JA6fzM5seno8oE85IYZdbVVEuQaZlEzMO2MXblh+KSPJgsZAUx0EEbWXU0yJaW7C9CdAVg==
@@ -209,7 +209,7 @@
dependencies:
"@babel/types" "^7.10.1"
"@babel/helper-validator-identifier@^7.10.1", "@babel/helper-validator-identifier@^7.10.3":
"@babel/helper-validator-identifier@^7.10.3":
version "7.10.3"
resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.10.3.tgz#60d9847f98c4cea1b279e005fdb7c28be5412d15"
integrity sha512-bU8JvtlYpJSBPuj1VUmKpFGaDZuLxASky3LhaKj3bmpSTY6VWooSM8msk+Z0CZoErFye2tlABF6yDkT3FOPAXw==
@@ -233,7 +233,7 @@
"@babel/traverse" "^7.10.1"
"@babel/types" "^7.10.1"
"@babel/highlight@^7.10.1", "@babel/highlight@^7.10.3":
"@babel/highlight@^7.10.3":
version "7.10.3"
resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.10.3.tgz#c633bb34adf07c5c13156692f5922c81ec53f28d"
integrity sha512-Ih9B/u7AtgEnySE2L2F0Xm0GaM729XqqLfHkalTsbjXGyqmf/6M0Cu0WpvqueUlW+xk88BHw9Nkpj49naU+vWw==
@@ -242,7 +242,7 @@
chalk "^2.0.0"
js-tokens "^4.0.0"
"@babel/parser@^7.0.0", "@babel/parser@^7.1.0", "@babel/parser@^7.10.1", "@babel/parser@^7.10.2", "@babel/parser@^7.10.3", "@babel/parser@^7.7.0", "@babel/parser@^7.7.5":
"@babel/parser@^7.0.0", "@babel/parser@^7.1.0", "@babel/parser@^7.10.3", "@babel/parser@^7.7.0", "@babel/parser@^7.7.5":
version "7.10.3"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.10.3.tgz#7e71d892b0d6e7d04a1af4c3c79d72c1f10f5315"
integrity sha512-oJtNJCMFdIMwXGmx+KxuaD7i3b8uS7TTFYW/FNG2BT8m+fmGHoiPYoH0Pe3gya07WuFmM5FCDIr1x0irkD/hyA==
@@ -699,7 +699,7 @@
globals "^11.1.0"
lodash "^4.17.13"
"@babel/types@^7.0.0", "@babel/types@^7.10.1", "@babel/types@^7.10.2", "@babel/types@^7.10.3", "@babel/types@^7.3.0", "@babel/types@^7.3.3", "@babel/types@^7.7.0", "@babel/types@^7.8.3", "@babel/types@^7.9.0", "@babel/types@^7.9.5":
"@babel/types@^7.0.0", "@babel/types@^7.10.1", "@babel/types@^7.10.3", "@babel/types@^7.3.0", "@babel/types@^7.3.3", "@babel/types@^7.7.0", "@babel/types@^7.8.3", "@babel/types@^7.9.0", "@babel/types@^7.9.5":
version "7.10.3"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.10.3.tgz#6535e3b79fea86a6b09e012ea8528f935099de8e"
integrity sha512-nZxaJhBXBQ8HVoIcGsf9qWep3Oh3jCENK54V4mRF7qaJabVsAYdbTtmSD8WmAp1R6ytPiu5apMwSXyxB1WlaBA==
@@ -1411,27 +1411,18 @@
dependencies:
"@types/yargs-parser" "*"
"@typescript-eslint/eslint-plugin@^3.1.0", "@typescript-eslint/eslint-plugin@^3.3.0":
version "3.3.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-3.3.0.tgz#89518e5c5209a349bde161c3489b0ec187ae5d37"
integrity sha512-Ybx/wU75Tazz6nU2d7nN6ll0B98odoiYLXwcuwS5WSttGzK46t0n7TPRQ4ozwcTv82UY6TQoIvI+sJfTzqK9dQ==
"@typescript-eslint/eslint-plugin@^3.1.0", "@typescript-eslint/eslint-plugin@^3.4.0":
version "3.4.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-3.4.0.tgz#8378062e6be8a1d049259bdbcf27ce5dfbeee62b"
integrity sha512-wfkpiqaEVhZIuQRmudDszc01jC/YR7gMSxa6ulhggAe/Hs0KVIuo9wzvFiDbG3JD5pRFQoqnf4m7REDsUvBnMQ==
dependencies:
"@typescript-eslint/experimental-utils" "3.3.0"
"@typescript-eslint/experimental-utils" "3.4.0"
debug "^4.1.1"
functional-red-black-tree "^1.0.1"
regexpp "^3.0.0"
semver "^7.3.2"
tsutils "^3.17.1"
"@typescript-eslint/experimental-utils@3.2.0":
version "3.2.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-3.2.0.tgz#4dab8fc9f44f059ec073470a81bb4d7d7d51e6c5"
integrity sha512-UbJBsk+xO9dIFKtj16+m42EvUvsjZbbgQ2O5xSTSfVT1Z3yGkL90DVu0Hd3029FZ5/uBgl+F3Vo8FAcEcqc6aQ==
dependencies:
"@types/json-schema" "^7.0.3"
"@typescript-eslint/typescript-estree" "3.2.0"
eslint-scope "^5.0.0"
eslint-utils "^2.0.0"
"@typescript-eslint/experimental-utils@3.3.0":
version "3.3.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-3.3.0.tgz#d72a946e056a83d4edf97f3411cceb639b0b8c87"
@@ -1442,20 +1433,30 @@
eslint-scope "^5.0.0"
eslint-utils "^2.0.0"
"@typescript-eslint/parser@^3.1.0", "@typescript-eslint/parser@^3.3.0":
version "3.3.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-3.3.0.tgz#fcae40012ded822aa8b2739a1a03a4e3c5bbb7bb"
integrity sha512-a7S0Sqn/+RpOOWTcaLw6RD4obsharzxmgMfdK24l364VxuBODXjuJM7ImCkSXEN7oz52aiZbXSbc76+2EsE91w==
"@typescript-eslint/experimental-utils@3.4.0":
version "3.4.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-3.4.0.tgz#8a44dfc6fb7f1d071937b390fe27608ebda122b8"
integrity sha512-rHPOjL43lOH1Opte4+dhC0a/+ks+8gOBwxXnyrZ/K4OTAChpSjP76fbI8Cglj7V5GouwVAGaK+xVwzqTyE/TPw==
dependencies:
"@types/json-schema" "^7.0.3"
"@typescript-eslint/typescript-estree" "3.4.0"
eslint-scope "^5.0.0"
eslint-utils "^2.0.0"
"@typescript-eslint/parser@^3.1.0", "@typescript-eslint/parser@^3.4.0":
version "3.4.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-3.4.0.tgz#fe52b68c5cb3bba3f5d875bd17adb70420d49d8d"
integrity sha512-ZUGI/de44L5x87uX5zM14UYcbn79HSXUR+kzcqU42gH0AgpdB/TjuJy3m4ezI7Q/jk3wTQd755mxSDLhQP79KA==
dependencies:
"@types/eslint-visitor-keys" "^1.0.0"
"@typescript-eslint/experimental-utils" "3.3.0"
"@typescript-eslint/typescript-estree" "3.3.0"
"@typescript-eslint/experimental-utils" "3.4.0"
"@typescript-eslint/typescript-estree" "3.4.0"
eslint-visitor-keys "^1.1.0"
"@typescript-eslint/typescript-estree@3.2.0":
version "3.2.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-3.2.0.tgz#c735f1ca6b4d3cd671f30de8c9bde30843e7ead8"
integrity sha512-uh+Y2QO7dxNrdLw7mVnjUqkwO/InxEqwN0wF+Za6eo3coxls9aH9kQ/5rSvW2GcNanebRTmsT5w1/92lAOb1bA==
"@typescript-eslint/typescript-estree@3.3.0":
version "3.3.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-3.3.0.tgz#841ffed25c29b0049ebffb4c2071268a34558a2a"
integrity sha512-3SqxylENltEvJsjjMSDCUx/edZNSC7wAqifUU1Ywp//0OWEZwMZJfecJud9XxJ/40rAKEbJMKBOQzeOjrLJFzQ==
dependencies:
debug "^4.1.1"
eslint-visitor-keys "^1.1.0"
@@ -1465,10 +1466,10 @@
semver "^7.3.2"
tsutils "^3.17.1"
"@typescript-eslint/typescript-estree@3.3.0":
version "3.3.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-3.3.0.tgz#841ffed25c29b0049ebffb4c2071268a34558a2a"
integrity sha512-3SqxylENltEvJsjjMSDCUx/edZNSC7wAqifUU1Ywp//0OWEZwMZJfecJud9XxJ/40rAKEbJMKBOQzeOjrLJFzQ==
"@typescript-eslint/typescript-estree@3.4.0":
version "3.4.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-3.4.0.tgz#6a787eb70b48969e4cd1ea67b057083f96dfee29"
integrity sha512-zKwLiybtt4uJb4mkG5q2t6+W7BuYx2IISiDNV+IY68VfoGwErDx/RfVI7SWL4gnZ2t1A1ytQQwZ+YOJbHHJ2rw==
dependencies:
debug "^4.1.1"
eslint-visitor-keys "^1.1.0"
@@ -2949,10 +2950,10 @@ eslint-visitor-keys@^1.0.0, eslint-visitor-keys@^1.1.0, eslint-visitor-keys@^1.2
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.2.0.tgz#74415ac884874495f78ec2a97349525344c981fa"
integrity sha512-WFb4ihckKil6hu3Dp798xdzSfddwKKU3+nGniKF6HfeW6OLd2OUDEPP7TcHtB5+QXOKg2s6B2DaMPE1Nn/kxKQ==
eslint@^7.3.0:
version "7.3.0"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-7.3.0.tgz#f9f1fc3dc1227985d0db88769f2bbac7b4b875d7"
integrity sha512-dJMVXwfU5PT1cj2Nv2VPPrKahKTGdX+5Dh0Q3YuKt+Y2UhdL2YbzsVaBMyG9HC0tBismlv/r1+eZqs6SMIV38Q==
eslint@^7.3.1:
version "7.3.1"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-7.3.1.tgz#76392bd7e44468d046149ba128d1566c59acbe19"
integrity sha512-cQC/xj9bhWUcyi/RuMbRtC3I0eW8MH0jhRELSvpKYkWep3C6YZ2OkvcvJVUeO6gcunABmzptbXBuDoXsjHmfTA==
dependencies:
"@babel/code-frame" "^7.0.0"
ajv "^6.10.0"
@@ -6125,10 +6126,10 @@ react-native-reanimated@^1.9.0:
dependencies:
fbjs "^1.0.0"
react-native-safe-area-context@^3.0.5:
version "3.0.5"
resolved "https://registry.yarnpkg.com/react-native-safe-area-context/-/react-native-safe-area-context-3.0.5.tgz#3dd9bf2fea3b51f894b9849f11108ac303bbefe5"
integrity sha512-cLZtHvzm/tdCTCOCgNRUsnl9ma8MozE9vtxHQVftuY6hRt+esCBdXA5jXcuCaCj+yUe4Akw+c5BPFNUF5vOTjQ==
react-native-safe-area-context@^3.0.6:
version "3.0.6"
resolved "https://registry.yarnpkg.com/react-native-safe-area-context/-/react-native-safe-area-context-3.0.6.tgz#ee180f53f9f40f8302923b9c09d821cf8ada01eb"
integrity sha512-/McWHgRG3CjXo/1ctlxH3mjW2psjf/QYAt9kWUTEtHu4b6z1y4hfUIGuYEJ02asaS1ixPsYrkqVqwzTv4olUMQ==
react-native-screens@^2.9.0:
version "2.9.0"