mobile: fix search to use filtered selector for notes

This commit is contained in:
Ammar Ahmed
2023-12-26 15:17:56 +05:00
committed by Abdullah Atta
parent afa4432521
commit 3ecda367f8
5 changed files with 30 additions and 22 deletions

View File

@@ -27,6 +27,7 @@ import Navigation, { NavigationProps } from "../../services/navigation";
import SettingsService from "../../services/settings";
import { useFavorites } from "../../stores/use-favorite-store";
import useNavigationStore from "../../stores/use-navigation-store";
import { db } from "../../common/database";
export const Favorites = ({
navigation,
@@ -61,9 +62,7 @@ export const Favorites = ({
type: "note",
title: route.name,
route: route.name,
ids: favorites?.ids.filter(
(id) => typeof id === "string"
) as string[]
items: db.notes.favorites
});
}}
/>

View File

@@ -149,12 +149,17 @@ const NotebookScreen = ({ route, navigation }: NavigationProps<"Notebook">) => {
canGoBack={params?.current?.canGoBack}
hasSearch={true}
onSearch={() => {
const selector = db.relations.from(
params.current.item,
"note"
).selector;
Navigation.push("Search", {
placeholder: `Type a keyword to search in ${params.current.item?.title}`,
type: "note",
title: params.current.item?.title,
route: route.name,
ids: notes?.ids.filter((id) => typeof id === "string") as string[]
items: selector
});
}}
titleHiddenOnRender
@@ -230,9 +235,7 @@ const NotebookScreen = ({ route, navigation }: NavigationProps<"Notebook">) => {
AddNotebookSheet.present(params.current.item);
}}
notebook={params.current.item}
totalNotes={
notes?.ids.filter((id) => typeof id === "string")?.length || 0
}
totalNotes={notes?.ids.length || 0}
/>
}
placeholder={{

View File

@@ -31,14 +31,14 @@ import {
eUnSubscribeEvent
} from "../../services/event-manager";
import Navigation, { NavigationProps } from "../../services/navigation";
import { resolveItems } from "../../stores/resolve-items";
import useNavigationStore, {
HeaderRightButton,
NotesScreenParams,
RouteName
} from "../../stores/use-navigation-store";
import { useNoteStore } from "../../stores/use-notes-store";
import { setOnFirstSave } from "./common";
import { resolveItems } from "../../stores/resolve-items";
import { db } from "../../common/database";
export const WARNING_DATA = {
title: "Some notes in this topic are not synced"
};
@@ -172,12 +172,17 @@ const NotesPage = ({
route.name === "Monographs" ? "Monographs" : params?.current.item?.id
}
onSearch={() => {
const selector =
route.name === "Monographs"
? db.monographs.all
: db.relations.from(params.current.item, "note").selector;
Navigation.push("Search", {
placeholder: `Type a keyword to search in ${title}`,
type: "note",
title: title,
route: route.name,
ids: notes?.ids?.filter((id) => typeof id === "string") as string[]
items: selector
});
}}
accentColor={accentColor}

View File

@@ -17,20 +17,21 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { Item, VirtualizedGrouping } from "@notesnook/core";
import { Item, Note, VirtualizedGrouping } from "@notesnook/core";
import React, { useEffect, useRef, useState } from "react";
import { db } from "../../common/database";
import List from "../../components/list";
import { NavigationProps } from "../../services/navigation";
import { SearchBar } from "./search-bar";
import SelectionHeader from "../../components/selection-header";
import { useNavigationFocus } from "../../hooks/use-navigation-focus";
import useNavigationStore from "../../stores/use-navigation-store";
import {
eSubscribeEvent,
eUnSubscribeEvent
} from "../../services/event-manager";
import { NavigationProps } from "../../services/navigation";
import useNavigationStore from "../../stores/use-navigation-store";
import { eOnRefreshSearch } from "../../utils/events";
import SelectionHeader from "../../components/selection-header";
import { SearchBar } from "./search-bar";
import { FilteredSelector } from "@notesnook/core/dist/database/sql-collection";
export const Search = ({ route, navigation }: NavigationProps<"Search">) => {
const [results, setResults] = useState<VirtualizedGrouping<Item>>();
const [loading, setLoading] = useState(false);
@@ -59,13 +60,10 @@ export const Search = ({ route, navigation }: NavigationProps<"Search">) => {
route.params.type === "trash"
? "trash"
: ((route.params?.type + "s") as keyof typeof db.lookup);
console.log(
`Searching in ${type} for ${query}`,
route.params?.ids?.length
);
console.log(`Searching in ${type} for ${query}`);
const results = await db.lookup[type](
query,
route.params?.type === "note" ? route.params?.ids : undefined
route.params.items as FilteredSelector<Note>
).sorted();
console.log(`Found ${results.ids?.length} results for ${query}`);
setResults(results);
@@ -79,7 +77,7 @@ export const Search = ({ route, navigation }: NavigationProps<"Search">) => {
console.log(e);
}
},
[route.params?.ids, route.params.type]
[route.params?.items, route.params.type]
);
useEffect(() => {

View File

@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import {
Color,
Item,
ItemType,
Note,
Notebook,
@@ -28,6 +29,8 @@ import {
} from "@notesnook/core/dist/types";
import create, { State } from "zustand";
import { ColorValues } from "../utils/colors";
import { FilteredSelector } from "@notesnook/core/dist/database/sql-collection";
import { VirtualizedGrouping } from "@notesnook/core";
export type GenericRouteParam = undefined;
@@ -69,7 +72,7 @@ export type RouteParams = {
type: ItemType;
title: string;
route: RouteName;
ids?: string[];
items?: FilteredSelector<Item>;
};
Settings: GenericRouteParam;
TaggedNotes: NotesScreenParams;