Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

feat: add search

thecodrrf68d90597248
diff --git a/apps/web/src/components/icons/index.js b/apps/web/src/components/icons/index.js
index d6f17b6b8..d3307c15d 100644
--- a/apps/web/src/components/icons/index.js
+++ b/apps/web/src/components/icons/index.js
@@ -116,3 +116,5 @@ export const Edit = createIcon(Icons.mdiPencil);
export const Undo = createIcon(Icons.mdiUndoVariant);
export const Redo = createIcon(Icons.mdiRedoVariant);
+
+export const Filter = createIcon(Icons.mdiTune);
diff --git a/apps/web/src/components/progress-bar/index.js b/apps/web/src/components/progress-bar/index.js
new file mode 100644
index 000000000..f18ab8420
--- /dev/null
+++ b/apps/web/src/components/progress-bar/index.js
@@ -0,0 +1,27 @@
+import { useAnimation } from "framer-motion";
+import React, { useEffect } from "react";
+import { Flex } from "rebass";
+import Animated from "../animated";
+
+function ProgressBar(props) {
+ const { width, progress, duration = 1, onLoadingEnd, sx } = props;
+ const animation = useAnimation();
+ useEffect(() => {
+ animation.start({ width: `${progress}%`, transition: { duration } });
+ }, [animation, progress, duration]);
+
+ return (
+ <Flex overflow="hidden" width={width} sx={sx}>
+ <Animated.Box
+ height={5}
+ initial={{ width: "0%" }}
+ animate={animation}
+ bg="primary"
+ sx={{ borderRadius: "default" }}
+ onAnimationComplete={onLoadingEnd}
+ />
+ </Flex>
+ );
+}
+
+export default ProgressBar;
diff --git a/apps/web/src/components/route-container/index.js b/apps/web/src/components/route-container/index.js
index eb9d45088..1c0f2c697 100644
--- a/apps/web/src/components/route-container/index.js
+++ b/apps/web/src/components/route-container/index.js
@@ -15,7 +15,7 @@ function RouteContainer(props) {
sx={{ overflow: "hidden" }}
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
- transition={{ duration: 0.2, ease: "easeIn" }}
+ transition={{ duration: 0.3, ease: "easeIn" }}
exit={{ opacity: 0 }}
flexDirection="column"
flex="1 1 auto"
@@ -47,10 +47,10 @@ function Header(props) {
<Flex alignItems="center" justifyContent="space-between">
<Flex justifyContent="center" alignItems="center" py={2}>
{canGoBack || onlyBackButton ? (
- <Icon.ChevronLeft
- size={38}
+ <Icon.ArrowLeft
+ size={24}
onClick={() => window.history.back()}
- sx={{ flexShrink: 0 }}
+ sx={{ flexShrink: 0, mr: 2 }}
color="fontPrimary"
data-test-id="go-back"
/>
diff --git a/apps/web/src/components/search/index.js b/apps/web/src/components/search/index.js
index e6e6da4dd..407d2c8b4 100644
--- a/apps/web/src/components/search/index.js
+++ b/apps/web/src/components/search/index.js
@@ -10,16 +10,19 @@ function SearchBox(props) {
return (
<Flex
variant="rowCenter"
- px={2}
+ mx={2}
mb={2}
+ px={2}
+ bg="bgSecondary"
sx={{
position: "relative",
+ borderRadius: "default",
}}
>
<Input
id="searchInput"
name="search"
- bg="border"
+ sx={{ borderWidth: 0, px: 0 }}
placeholder={`Type your query here`}
onKeyDown={(e) => {
if (e.key === "Enter") props.onSearch(e.target.value);
@@ -28,13 +31,10 @@ function SearchBox(props) {
<Box
id="searchIcon"
sx={{
- position: "absolute",
- right: 0,
- mr: 3,
color: "hover",
}}
>
- <Icon.Search size={28} />
+ <Icon.Search size={24} />
</Box>
</Flex>
);
diff --git a/apps/web/src/theme/font/fontsize.js b/apps/web/src/theme/font/fontsize.js
index 3cce9ff8b..90924e2d1 100644
--- a/apps/web/src/theme/font/fontsize.js
+++ b/apps/web/src/theme/font/fontsize.js
@@ -1,7 +1,7 @@
class FontSizeFactory {
constructor() {
return {
- heading: "1.5rem",
+ heading: "1.2rem",
input: "0.875rem",
title: "0.875rem",
subtitle: "0.750rem",
diff --git a/apps/web/src/views/search.js b/apps/web/src/views/search.js
index 12f07d06e..8c9346f4d 100644
--- a/apps/web/src/views/search.js
+++ b/apps/web/src/views/search.js
@@ -4,7 +4,9 @@ import SearchPlaceholder from "../components/placeholders/search-placeholder";
import { useQueryParams } from "hookrouter";
import { db, notesFromContext } from "../common";
import SearchBox from "../components/search";
+import ProgressBar from "../components/progress-bar";
import { useStore as useNoteStore } from "../stores/note-store";
+import { Flex, Text } from "rebass";
function typeToItems(type, context) {
switch (type) {
@@ -27,6 +29,10 @@ function typeToItems(type, context) {
}
function Search() {
+ const [searchState, setSearchState] = useState({
+ isSearching: false,
+ totalItems: 0,
+ });
const [results, setResults] = useState([]);
const [params] = useQueryParams();
const { type } = params;
@@ -37,15 +43,44 @@ function Search() {
<SearchBox
onSearch={async (query) => {
const [lookupType, items] = typeToItems(type, context);
+
+ setResults([]);
+
+ if (items.length <= 0) return;
+
+ setSearchState({ isSearching: true, totalItems: items.length });
+
setResults(await db.lookup[lookupType](items, query));
+
+ setSearchState({ isSearching: false, totalItems: 0 });
}}
/>
- <ListContainer
- context={context}
- type={type}
- items={results}
- placeholder={SearchPlaceholder}
- />
+ {searchState.isSearching ? (
+ <Flex
+ flex="1"
+ justifyContent="center"
+ alignItems="center"
+ flexDirection="column"
+ >
+ <SearchPlaceholder />
+ <Text mt={2}>
+ Searching in {searchState.totalItems} {type}...
+ </Text>
+ <ProgressBar
+ progress={100}
+ width={"60%"}
+ duration={3}
+ sx={{ mt: 2 }}
+ />
+ </Flex>
+ ) : (
+ <ListContainer
+ context={context}
+ type={type}
+ items={results}
+ placeholder={SearchPlaceholder}
+ />
+ )}
</>
);
}
diff --git a/apps/web/src/views/splash.js b/apps/web/src/views/splash.js
index b540ea5ce..bc8b0b4e1 100644
--- a/apps/web/src/views/splash.js
+++ b/apps/web/src/views/splash.js
@@ -3,6 +3,7 @@ import { Flex, Text } from "rebass";
import ThemeProvider from "../components/theme-provider";
import Animated from "../components/animated";
import { db } from "../common";
+import ProgressBar from "../components/progress-bar";
import { getRandom } from "../utils/random";
import * as Sentry from "@sentry/react";
@@ -67,17 +68,11 @@ function Splash(props) {
</Animated.Text>
</Animated.Flex>
</Flex>
- <Flex overflow="hidden" width={300}>
- <Animated.Box
- height={5}
- initial={{ width: "0%" }}
- animate={{ width: "100%" }}
- transition={{ duration: 1 }}
- bg="primary"
- sx={{ borderRadius: "default" }}
- onAnimationComplete={() => setAnimationEnded(true)}
- />
- </Flex>
+ <ProgressBar
+ progress={100}
+ width={300}
+ onLoadingEnd={() => setAnimationEnded(true)}
+ />
<Text color="text" mt={2}>
{loadingLines[getRandom(0, loadingLines.length)]}
</Text>
diff --git a/apps/web/yarn.lock b/apps/web/yarn.lock
index 21caa19ce..f74ced777 100644
--- a/apps/web/yarn.lock
+++ b/apps/web/yarn.lock
@@ -8953,8 +8953,8 @@ normalize-url@^3.0.0, normalize-url@^3.0.1:
integrity sha512-U+JJi7duF1o+u2pynbp2zXDW2/PADgC30f0GsHZtRh+HOcXHnw137TrNlyxxRvWW5fjKd3bcLHPxofWuCjaeZg==
"notes-core@git+ssh://[email protected]:streetwriters/notesnook-core.git":
- version "2.3.2"
- resolved "git+ssh://[email protected]:streetwriters/notesnook-core.git#a5bb8c8ed34a261dfd8fee0cd64b4f38b990af59"
+ version "2.3.3"
+ resolved "git+ssh://[email protected]:streetwriters/notesnook-core.git#3b9eb3fad825edf1ba31152c92646ee1d37b6b71"
dependencies:
fast-sort "^2.0.1"
fuzzysearch "^1.0.3"