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
fix: sorting and jump to
ammarahm-edc6ddf4d860f1
diff --git a/apps/mobile/src/components/Header/HeaderMenu.js b/apps/mobile/src/components/Header/HeaderMenu.jsdeleted file mode 100644index 5a61dc291..000000000--- a/apps/mobile/src/components/Header/HeaderMenu.js+++ /dev/null@@ -1,56 +0,0 @@-import React from 'react';-import { TouchableOpacity } from 'react-native';-import Icon from 'react-native-vector-icons/MaterialCommunityIcons';-import { useTracked } from '../../provider';-import { useSettingStore } from '../../provider/stores';-import { eSendEvent } from '../../services/EventManager';-import { getElevation } from '../../utils';-import { eOpenSortDialog } from '../../utils/Events';-import { SIZE } from '../../utils/SizeUtils';-import Heading from '../Typography/Heading';--export const HeaderMenu = () => {- const [state] = useTracked();- const {colors} = state;- const settings = useSettingStore(state => state.settings);-- return (- <TouchableOpacity- onPress={() => {- eSendEvent(eOpenSortDialog);- }}- hitSlop={{top: 15, right: 10, left: 30, bottom: 15}}- activeOpacity={1}- style={{- flexDirection: 'row',- alignItems: 'center',- zIndex: 10,- height: 25,- backgroundColor: colors.accent,- paddingHorizontal: 12,- borderRadius: 100,- ...getElevation(2)- }}>- <Heading- color={colors.light}- size={SIZE.sm}- style={{- marginRight: 5,- textAlignVertical: 'center',- }}>- {settings.sort.slice(0, 1).toUpperCase() +- settings.sort.slice(1, settings.sort.length)}- </Heading>- <Icon- color={colors.light}- name={- settings.sortOrder === 'asc' ? 'sort-ascending' : 'sort-descending'- }- style={{- textAlignVertical: 'center',- }}- size={SIZE.md}- />- </TouchableOpacity>- );-};diff --git a/apps/mobile/src/components/JumpToDialog/index.js b/apps/mobile/src/components/JumpToDialog/index.jsindex e75502b18..96ac59ac7 100644--- a/apps/mobile/src/components/JumpToDialog/index.js+++ b/apps/mobile/src/components/JumpToDialog/index.js@@ -4,7 +4,11 @@ import BaseDialog from '../../components/Dialog/base-dialog';import {PressableButton} from '../../components/PressableButton';import Seperator from '../../components/Seperator';import {useTracked} from '../../provider';-import {useNoteStore, useSettingStore} from '../../provider/stores';+import {+ useMessageStore,+ useNoteStore,+ useSettingStore,+} from '../../provider/stores';import {DDS} from '../../services/DeviceDetection';import {eSubscribeEvent, eUnSubscribeEvent} from '../../services/EventManager';import {getElevation} from '../../utils';@@ -18,10 +22,10 @@ import Heading from '../Typography/Heading';const offsets = [];let timeout = null;-const JumpToDialog = ({scrollRef}) => {+const JumpToDialog = ({scrollRef, data, type, screen}) => {const [state] = useTracked();const {colors} = state;- const notes = useNoteStore(state => state.notes);+ const notes = data;const [visible, setVisible] = useState(false);const [currentIndex, setCurrentIndex] = useState(null);@@ -30,9 +34,12 @@ const JumpToDialog = ({scrollRef}) => {let ind = notes.findIndex(i => i.title === item.title && i.type === 'header',);+ let messageState = useMessageStore.getState().message;+ let msgOffset = messageState?.visible ? 60 : 10;ind = ind + 1;ind = ind - (index + 1);- offset = offset + ind * 100 + 200;+ offset = offset + ind * 100 + msgOffset;+ console.log(scrollRef.current?.scrollToOffset);scrollRef.current?.scrollToOffset({offset: offset,animated: true,@@ -63,7 +70,8 @@ const JumpToDialog = ({scrollRef}) => {}, 200);};- const open = () => {+ const open = _type => {+ if (_type !== type) return;setVisible(true);};@@ -83,9 +91,11 @@ const JumpToDialog = ({scrollRef}) => {let ind = notes.findIndex(i => i.title === item.title && i.type === 'header',);+ let messageState = useMessageStore.getState().message;+ let msgOffset = messageState?.visible ? 60 : 10;ind = ind + 1;ind = ind - (index + 1);- offset = offset + ind * 100 + 190;+ offset = offset + ind * 100 + msgOffset;offsets.push(offset);});};diff --git a/apps/mobile/src/components/SimpleList/index.js b/apps/mobile/src/components/SimpleList/index.jsindex 0412d8d3e..bf7536748 100644--- a/apps/mobile/src/components/SimpleList/index.js+++ b/apps/mobile/src/components/SimpleList/index.js@@ -74,9 +74,7 @@ const SimpleList = ({<SectionHeaderitem={item}index={index}- headerProps={headerProps}- jumpToDialog={jumpToDialog}- sortMenuButton={sortMenuButton}+ type={screen === 'Notes' ? 'home' : type}/>) : (<RenderItem item={item} index={index} />@@ -166,6 +164,7 @@ const SimpleList = ({/><JumpToDialogscreen={screen}+ data={listData}type={screen === 'Notes' ? 'home' : type}scrollRef={scrollRef}/>diff --git a/apps/mobile/src/components/SimpleList/sectionheader.js b/apps/mobile/src/components/SimpleList/sectionheader.jsindex 786a029da..ef9d9d4fc 100644--- a/apps/mobile/src/components/SimpleList/sectionheader.js+++ b/apps/mobile/src/components/SimpleList/sectionheader.js@@ -1,22 +1,41 @@-import React from 'react';+import React, {useEffect, useState} from 'react';import {TouchableOpacity, useWindowDimensions, View} from 'react-native';import {useTracked} from '../../provider';-import {eSendEvent} from '../../services/EventManager';-import {eOpenJumpToDialog} from '../../utils/Events';+import {+ eSendEvent,+ eSubscribeEvent,+ eUnSubscribeEvent,+} from '../../services/EventManager';+import {SORT} from '../../utils';+import {db} from '../../utils/DB';+import {eOpenJumpToDialog, eOpenSortDialog} from '../../utils/Events';import {SIZE} from '../../utils/SizeUtils';-import {HeaderMenu} from '../Header/HeaderMenu';+import {Button} from '../Button';import Heading from '../Typography/Heading';-export const SectionHeader = ({- item,- index,- headerProps,- jumpToDialog,- sortMenuButton,-}) => {+export const SectionHeader = ({item, index, type}) => {const [state] = useTracked();const {colors} = state;const {fontScale} = useWindowDimensions();+ const [groupOptions, setGroupOptions] = useState(+ db.settings?.getGroupOptions(type),+ );+ let groupBy = Object.keys(SORT).find(+ key => SORT[key] === groupOptions.groupBy,+ );+ groupBy = !groupBy+ ? 'Default'+ : groupBy.slice(0, 1).toUpperCase() + groupBy.slice(1, groupBy.length);++ const onUpdate = () => {+ setGroupOptions({...db.settings?.getGroupOptions(type)});+ };+ useEffect(() => {+ eSubscribeEvent('groupOptionsUpdate', onUpdate);+ return () => {+ eUnSubscribeEvent('groupOptionsUpdate', onUpdate);+ };+ }, []);return (<View@@ -27,11 +46,13 @@ export const SectionHeader = ({justifyContent: 'space-between',paddingHorizontal: 12,height: 35 * fontScale,- backgroundColor:colors.nav,+ backgroundColor: index === 0 ? 'transparent' : colors.nav,+ borderBottomWidth: 1,+ borderBottomColor: index !== 0 ? 'transparent' : colors.accent,}}><TouchableOpacityonPress={() => {- eSendEvent(eOpenJumpToDialog);+ eSendEvent(eOpenJumpToDialog,type);}}activeOpacity={0.9}hitSlop={{top: 10, left: 10, right: 30, bottom: 15}}@@ -50,7 +71,26 @@ export const SectionHeader = ({{!item.title || item.title === '' ? 'Pinned' : item.title}</Heading></TouchableOpacity>- {index === 0 ? <HeaderMenu /> : null}++ {index === 0 ? (+ <Button+ onPress={() => {+ eSendEvent(eOpenSortDialog,type);+ }}+ title={groupBy}+ icon={+ groupOptions.sortDirection === 'asc'+ ? 'sort-ascending'+ : 'sort-descending'+ }+ height={25}+ style={{+ borderRadius: 100,+ }}+ type="grayBg"+ iconPosition="right"+ />+ ) : null}</View>);};diff --git a/apps/mobile/src/components/SortDialog/index.js b/apps/mobile/src/components/SortDialog/index.jsindex 6debf7426..4af30f80a 100644--- a/apps/mobile/src/components/SortDialog/index.js+++ b/apps/mobile/src/components/SortDialog/index.js@@ -1,7 +1,7 @@import React, { createRef } from 'react';import { View } from 'react-native';import Icon from 'react-native-vector-icons/MaterialCommunityIcons';-import { eSubscribeEvent, eUnSubscribeEvent } from '../../services/EventManager';+import { eSendEvent, eSubscribeEvent, eUnSubscribeEvent } from '../../services/EventManager';import Navigation from '../../services/Navigation';import { GROUP, SORT } from '../../utils';import { db } from '../../utils/DB';@@ -13,7 +13,6 @@ import { Button } from '../Button';import { PressableButton } from '../PressableButton';import Seperator from '../Seperator';import Heading from '../Typography/Heading';-import Paragraph from '../Typography/Paragraph';class SortDialog extends React.Component {constructor(props) {@@ -25,7 +24,8 @@ class SortDialog extends React.Component {this.actionSheet = createRef();}- async open() {+ async open(type) {+ if (type !== this.props.type) return;this.setState({visible: true,@@ -61,6 +61,7 @@ class SortDialog extends React.Component {groupOptions: _groupOptions,});Navigation.setRoutesToUpdate([this.props.screen]);+ eSendEvent('groupOptionsUpdate')};render() {diff --git a/apps/mobile/src/utils/Storage.js b/apps/mobile/src/utils/Storage.jsindex 35ee8df93..98d98bfe5 100644--- a/apps/mobile/src/utils/Storage.js+++ b/apps/mobile/src/utils/Storage.js@@ -8,7 +8,9 @@ import * as Keychain from 'react-native-keychain';let RNFetchBlob;async function read(key) {+ if (!key) return null;let data = await MMKV.getItem(key);+if (!data) return null;try {return JSON.parse(data);