A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
mobile: support sorting search results
Ammar Ahmedde48cea9ebdd
diff --git a/apps/mobile/app/components/list-items/headers/section-header.tsx b/apps/mobile/app/components/list-items/headers/section-header.tsxindex a069ef04b..4ef97c94e 100644--- a/apps/mobile/app/components/list-items/headers/section-header.tsx+++ b/apps/mobile/app/components/list-items/headers/section-header.tsx@@ -133,7 +133,9 @@ export const SectionHeader = React.memo<<Sortscreen={screen}type={dataType}- hideGroupOptions={screen === "Reminders"}+ hideGroupOptions={+ screen === "Reminders" || screen === "Search"+ }/>)});diff --git a/apps/mobile/app/components/sheets/sort/index.tsx b/apps/mobile/app/components/sheets/sort/index.tsxindex b959be06a..a1f4a4e24 100644--- a/apps/mobile/app/components/sheets/sort/index.tsx+++ b/apps/mobile/app/components/sheets/sort/index.tsx@@ -52,24 +52,42 @@ const Sort = ({hideGroupOptions?: boolean;}) => {const { colors } = useThemeColors();++ const groupType =+ screen === "Archive"+ ? "archive"+ : screen === "Search"+ ? "search"+ : screen === "Notes"+ ? "home"+ : screen === "Trash" || type === "trash"+ ? "trash"+ : ((type + "s") as GroupingKey);+const [groupOptions, setGroupOptions] = useState(- db.settings.getGroupOptions(- screen === "Notes"- ? "home"- : screen === "Trash" || type === "trash"- ? "trash"- : ((type + "s") as GroupingKey)- )+ db.settings.getGroupOptions(groupType));++ const getSortButtonTitle = () => {+ const { sortDirection, groupBy, sortBy } = groupOptions || {};+ const isAlphabetical = groupBy === "abc" || sortBy === "title";+ const isDueDate = sortBy === "dueDate";+ const isRelevance = sortBy === "relevance";++ if (sortDirection === "asc") {+ if (isAlphabetical) return strings.aToZ();+ if (isDueDate) return strings.earliestFirst();+ if (isRelevance) return strings.leastRelevantFirst();+ return strings.oldNew();+ } else {+ if (isAlphabetical) return strings.zToA();+ if (isDueDate) return strings.latestFirst();+ if (isRelevance) return strings.mostRelevantFirst();+ return strings.newOld();+ }+ };+const updateGroupOptions = async (_groupOptions: GroupOptions) => {- const groupType =- screen === "Notes"- ? "home"- : screen === "Trash" || type === "trash"- ? "trash"- : screen === "Favorites"- ? "favorites"- : ((type + "s") as GroupingKey);await db.settings.setGroupOptions(groupType, _groupOptions);setGroupOptions(_groupOptions);setTimeout(() => {@@ -110,31 +128,10 @@ const Sort = ({paddingHorizontal: DefaultAppStyles.GAP}}>- <Heading- size={AppFontSize.lg}- style={{- alignSelf: "center"- }}- >- {strings.sortBy()}- </Heading>+ <Heading size={AppFontSize.lg}>{strings.sortBy()}</Heading><Button- title={- groupOptions?.sortDirection === "asc"- ? groupOptions?.groupBy === "abc" ||- groupOptions?.sortBy === "title"- ? strings.aToZ()- : groupOptions?.sortBy === "dueDate"- ? strings.earliestFirst()- : strings.oldNew()- : groupOptions?.groupBy === "abc" ||- groupOptions?.sortBy === "title"- ? strings.zToA()- : groupOptions?.sortBy === "dueDate"- ? strings.latestFirst()- : strings.newOld()- }+ title={getSortButtonTitle()}icon={groupOptions?.sortDirection === "asc"? "sort-ascending"@@ -158,13 +155,24 @@ const Sort = ({borderBottomColor: colors.primary.border}}>- {Object.keys(SORT).map((item) =>- (item === "dueDate" && screen !== "Reminders") ||- (screen !== "Tags" &&- screen !== "Reminders" &&- item === "dateModified") ||- ((screen === "Tags" || screen === "Reminders") &&- item === "dateEdited") ? null : (+ {Object.keys(SORT).map((item) => {+ const sortOptionVisibility = {+ relevance: screen === "Search",+ dueDate: screen === "Reminders",+ dateModified: screen === "Tags" || screen === "Reminders",+ dateEdited: screen !== "Tags" && screen !== "Reminders"+ };++ // Check if this sort option should be skipped for the current screen+ const shouldSkip =+ item in sortOptionVisibility &&+ !sortOptionVisibility[item as keyof typeof sortOptionVisibility];++ if (shouldSkip) {+ return null;+ }++ return (<Pressablekey={item}type={groupOptions?.sortBy === item ? "selected" : "plain"}@@ -202,8 +210,8 @@ const Sort = ({/>) : null}</Pressable>- )- )}+ );+ })}</View>{!hideGroupOptions ? (diff --git a/apps/mobile/app/screens/search/index.tsx b/apps/mobile/app/screens/search/index.tsxindex b114adeba..8075accd3 100644--- a/apps/mobile/app/screens/search/index.tsx+++ b/apps/mobile/app/screens/search/index.tsx@@ -23,14 +23,10 @@ import { DatabaseLogger, db } from "../../common/database";import List from "../../components/list";import SelectionHeader from "../../components/selection-header";import { useNavigationFocus } from "../../hooks/use-navigation-focus";-import {- ToastManager,- eSubscribeEvent,- eUnSubscribeEvent-} from "../../services/event-manager";+import { ToastManager, eSubscribeEvent } from "../../services/event-manager";import { NavigationProps } from "../../services/navigation";import useNavigationStore from "../../stores/use-navigation-store";-import { eOnRefreshSearch } from "../../utils/events";+import { eGroupOptionsUpdated, eOnRefreshSearch } from "../../utils/events";import { SearchBar } from "./search-bar";import { FilteredSelector } from "@notesnook/core";import { strings } from "@notesnook/intl";@@ -60,27 +56,28 @@ export const Search = ({ route, navigation }: NavigationProps<"Search">) => {try {setLoading(true);let results: VirtualizedGrouping<Item> | undefined;+ const groupOptions = db.settings.getGroupOptions("search");switch (route.params.type) {case "note":results = await db.lookup.notes(query, route.params.items as FilteredSelector<Note>)- .sorted();+ .sorted(groupOptions);break;case "notebook":- results = await db.lookup.notebooks(query).sorted();+ results = await db.lookup.notebooks(query).sorted(groupOptions);break;case "tag":- results = await db.lookup.tags(query).sorted();+ results = await db.lookup.tags(query).sorted(groupOptions);break;case "reminder":- results = await db.lookup.reminders(query).sorted();+ results = await db.lookup.reminders(query).sorted(groupOptions);break;case "trash":- results = await db.lookup.trash(query).sorted();+ results = await db.lookup.trash(query).sorted(groupOptions);break;case "attachment":- results = await db.lookup.attachments(query).sorted();+ results = await db.lookup.attachments(query).sorted(groupOptions);break;default:results = undefined;@@ -118,9 +115,18 @@ export const Search = ({ route, navigation }: NavigationProps<"Search">) => {onSearch(currentQuery.current);}};- eSubscribeEvent(eOnRefreshSearch, onRefreshSearch);++ const subs = [+ eSubscribeEvent(eGroupOptionsUpdated, (groupType) => {+ if (groupType === "search") {+ onSearch(currentQuery.current);+ }+ }),+ eSubscribeEvent(eOnRefreshSearch, onRefreshSearch)+ ];+return () => {- eUnSubscribeEvent(eOnRefreshSearch, onRefreshSearch);+ subs.forEach((sub) => sub?.unsubscribe());};}, [onSearch, route.params?.type]);diff --git a/apps/mobile/app/utils/constants.ts b/apps/mobile/app/utils/constants.tsindex 2b948b7da..d44589c54 100644--- a/apps/mobile/app/utils/constants.ts+++ b/apps/mobile/app/utils/constants.ts@@ -45,7 +45,8 @@ export const SORT = {dateEdited: "Date edited",dateCreated: "Date created",title: "Title",- dueDate: "Due date"+ dueDate: "Due date",+ relevance: "Relevance"};export const itemSkus = [