From 0b7523c57dfd15e4355b1738a937655553247054 Mon Sep 17 00:00:00 2001 From: Artemy Date: Fri, 7 Apr 2023 13:13:20 +0300 Subject: [PATCH] fix: search by plain text --- package-lock.json | 11 +++++++++++ package.json | 1 + src/pages/notes.jsx | 23 +++++++++++++++++------ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index e654799..9e1ff37 100644 --- a/package-lock.json +++ b/package-lock.json @@ -30,6 +30,7 @@ "remark-gfm": "^3.0.1", "remark-math": "^5.1.1", "remark-stringify": "^10.0.2", + "remove-markdown": "^0.5.0", "socket.io": "^4.6.1", "socket.io-client": "^4.6.1", "unified": "^10.1.2" @@ -4695,6 +4696,11 @@ "url": "https://opencollective.com/unified" } }, + "node_modules/remove-markdown": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/remove-markdown/-/remove-markdown-0.5.0.tgz", + "integrity": "sha512-x917M80K97K5IN1L8lUvFehsfhR8cYjGQ/yAMRI9E7JIKivtl5Emo5iD13DhMr+VojzMCiYk8V2byNPwT/oapg==" + }, "node_modules/require-from-string": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", @@ -8836,6 +8842,11 @@ "unified": "^10.0.0" } }, + "remove-markdown": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/remove-markdown/-/remove-markdown-0.5.0.tgz", + "integrity": "sha512-x917M80K97K5IN1L8lUvFehsfhR8cYjGQ/yAMRI9E7JIKivtl5Emo5iD13DhMr+VojzMCiYk8V2byNPwT/oapg==" + }, "require-from-string": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", diff --git a/package.json b/package.json index 459e15b..5a81c79 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "remark-gfm": "^3.0.1", "remark-math": "^5.1.1", "remark-stringify": "^10.0.2", + "remove-markdown": "^0.5.0", "socket.io": "^4.6.1", "socket.io-client": "^4.6.1", "unified": "^10.1.2" diff --git a/src/pages/notes.jsx b/src/pages/notes.jsx index 8129cef..b15e1b6 100644 --- a/src/pages/notes.jsx +++ b/src/pages/notes.jsx @@ -5,6 +5,7 @@ import Fuse from "fuse.js"; import { inputStyle } from "../components/styles"; import { useState } from "react"; import { setSetting } from "../components/settingsInputs"; +import RemoveMarkdown from "remove-markdown"; function Notes() { if (!settings.newNotes) { @@ -21,14 +22,24 @@ function Notes() { let n = Object.values(localStorage.getObj("Notes")); - let fuse = new Fuse(n, { - includeScore: true, - useExtendedSearch: true, - keys: ["name", "text", "textTime", "tags"], - }); - let [search, setSearch] = useState(""); + let fuse; + + if (search) + fuse = new Fuse(n, { + includeScore: true, + useExtendedSearch: true, + keys: [ + "name", + "textTime", + { + name: "text", + getFn: (obj) => RemoveMarkdown(obj.text), + }, + ], + }); + let found = search === "" ? n : fuse.search(search); if (search !== "") {