Skip to content

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

add sorting on all screens

ammarahm-eddc5b6e716c76
diff --git a/apps/mobile/src/components/JumpToDialog/index.js b/apps/mobile/src/components/JumpToDialog/index.js
index a23c9a79a..e75502b18 100644
--- a/apps/mobile/src/components/JumpToDialog/index.js
+++ b/apps/mobile/src/components/JumpToDialog/index.js
@@ -21,10 +21,7 @@ let timeout = null;
const JumpToDialog = ({scrollRef}) => {
const [state] = useTracked();
const {colors} = state;
-
const notes = useNoteStore(state => state.notes);
- const settings = useSettingStore(state => state.settings);
-
const [visible, setVisible] = useState(false);
const [currentIndex, setCurrentIndex] = useState(null);
@@ -117,8 +114,7 @@ const JumpToDialog = ({scrollRef}) => {
style={{
alignSelf: 'center',
}}>
- {settings.sort.slice(0, 1).toUpperCase() +
- settings.sort.slice(1, settings.sort.length)}
+ Jump to
</Heading>
<Seperator />
<ScrollView
@@ -142,12 +138,11 @@ const JumpToDialog = ({scrollRef}) => {
type="shade"
customStyle={{
minWidth: '20%',
- maxWidth: '46%',
width: null,
- paddingHorizontal: 10,
+ paddingHorizontal: 12,
margin: 5,
borderRadius: 100,
- height: 22,
+ height: 25,
}}>
<Heading
size={SIZE.sm}
@@ -168,12 +163,11 @@ const JumpToDialog = ({scrollRef}) => {
type={currentIndex === index ? 'accent' : 'shade'}
customStyle={{
minWidth: '20%',
- maxWidth: '46%',
width: null,
- paddingHorizontal: 0,
+ paddingHorizontal: 12,
margin: 5,
borderRadius: 100,
- height: 22,
+ height: 25,
}}>
<Heading
size={SIZE.sm}
diff --git a/apps/mobile/src/components/LoginDialog/index.js b/apps/mobile/src/components/LoginDialog/index.js
index 3205eea7e..be1ae3e52 100644
--- a/apps/mobile/src/components/LoginDialog/index.js
+++ b/apps/mobile/src/components/LoginDialog/index.js
@@ -1,4 +1,5 @@
import React, {useEffect, useRef, useState} from 'react';
+import {UIManager} from 'react-native';
import {
ActivityIndicator,
ScrollView,
@@ -64,7 +65,7 @@ function getEmail() {
return gp2;
});
}
-
+let offsetY = 0;
const LoginDialog = () => {
const [state, dispatch] = useTracked();
const colors = state.colors;
@@ -80,7 +81,7 @@ const LoginDialog = () => {
const [error, setError] = useState(false);
const [focused, setFocused] = useState(false);
const [confirm, setConfirm] = useState(false);
-
+ const scrollViewRef = useRef();
const actionSheetRef = useRef();
const _email = useRef();
const _pass = useRef();
@@ -471,6 +472,7 @@ const LoginDialog = () => {
) : null}
<ScrollView
+ ref={scrollViewRef}
keyboardShouldPersistTaps="always"
keyboardDismissMode="none"
nestedScrollEnabled
@@ -480,7 +482,7 @@ const LoginDialog = () => {
style={{
maxHeight: DDS.isTab ? '90%' : '100%',
width: DDS.isTab ? 500 : '100%',
- minHeight:!DDS.isTab && "90%",
+ minHeight: !DDS.isTab ? '90%' : null,
height: MODES.sessionExpired === mode ? '100%' : null,
borderRadius: DDS.isTab ? 5 : 0,
backgroundColor: colors.bg,
diff --git a/apps/mobile/src/components/SimpleList/index.js b/apps/mobile/src/components/SimpleList/index.js
index 823cc5453..797f4ac51 100644
--- a/apps/mobile/src/components/SimpleList/index.js
+++ b/apps/mobile/src/components/SimpleList/index.js
@@ -179,7 +179,7 @@ const SimpleList = ({
}
/>
- <JumpToDialog scrollRef={scrollRef} />
+ <JumpToDialog screen={screen} type={screen === "Notes" ? "home" : type} scrollRef={scrollRef} />
</>
);
};
diff --git a/apps/mobile/src/components/SimpleList/sectionheader.js b/apps/mobile/src/components/SimpleList/sectionheader.js
index 253af91d6..ee6149a06 100644
--- a/apps/mobile/src/components/SimpleList/sectionheader.js
+++ b/apps/mobile/src/components/SimpleList/sectionheader.js
@@ -32,11 +32,7 @@ export const SectionHeader = ({
}}>
<TouchableOpacity
onPress={() => {
- console.log('called');
- if (jumpToDialog) {
- console.log('sending event');
- eSendEvent(eOpenJumpToDialog);
- }
+ eSendEvent(eOpenJumpToDialog);
}}
activeOpacity={0.9}
hitSlop={{top: 10, left: 10, right: 30, bottom: 15}}
@@ -55,7 +51,7 @@ export const SectionHeader = ({
{!item.title || item.title === '' ? 'Pinned' : item.title}
</Heading>
</TouchableOpacity>
- {index === 0 && sortMenuButton ? <HeaderMenu /> : null}
+ {index === 0 ? <HeaderMenu /> : null}
</View>
);
};
diff --git a/apps/mobile/src/components/SortDialog/index.js b/apps/mobile/src/components/SortDialog/index.js
index 9d9e0571f..3ccd14f37 100644
--- a/apps/mobile/src/components/SortDialog/index.js
+++ b/apps/mobile/src/components/SortDialog/index.js
@@ -1,69 +1,44 @@
-import React, {createRef} from 'react';
-import {TouchableOpacity, View} from 'react-native';
+import React, { createRef } from 'react';
+import { View } from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
-import {notesnook} from '../../../e2e/test.ids';
-import {Actions} from '../../provider/Actions';
-import {defaultState} from '../../provider/DefaultState';
-import { useNoteStore } from '../../provider/stores';
-import {eSubscribeEvent, eUnSubscribeEvent} from '../../services/EventManager';
-import SettingsService from '../../services/SettingsService';
-import {getElevation, SORT, sortSettings} from '../../utils';
-import {eCloseSortDialog, eOpenSortDialog} from '../../utils/Events';
-import {MMKV} from '../../utils/mmkv';
-import {SIZE} from '../../utils/SizeUtils';
-import {sleep} from '../../utils/TimeUtils';
+import { eSubscribeEvent, eUnSubscribeEvent } from '../../services/EventManager';
+import Navigation from '../../services/Navigation';
+import { GROUP, SORT } from '../../utils';
+import { db } from '../../utils/DB';
+import { eCloseSortDialog, eOpenSortDialog } from '../../utils/Events';
+import { SIZE } from '../../utils/SizeUtils';
+import { sleep } from '../../utils/TimeUtils';
import ActionSheetWrapper from '../ActionSheetComponent/ActionSheetWrapper';
-import {updateEvent} from '../DialogManager/recievers';
-import {PressableButton} from '../PressableButton';
+import { Button } from '../Button';
+import { PressableButton } from '../PressableButton';
import Seperator from '../Seperator';
import Heading from '../Typography/Heading';
-
-const actionSheet = createRef();
+import Paragraph from '../Typography/Paragraph';
class SortDialog extends React.Component {
constructor(props) {
super(props);
this.state = {
- settings: {
- showToolbarOnTop: false,
- showKeyboardOnOpen: false,
- fontScale: 1,
- forcePortraitOnTablet: false,
- useSystemTheme: false,
- reminder: 'off',
- encryptedBackup: false,
- homepage: 'Notes',
- sort: 'default',
- sortOrder: 'desc',
- screenshotMode: true,
- privacyScreen: false,
- appLockMode: 'none', //none or // background // launch
- },
+ groupOptions: db?.settings?.getGroupOptions(this.props.type),
visible: false,
};
+ this.actionSheet = createRef();
}
async open() {
this.setState(
{
visible: true,
+ groupOptions: db.settings.getGroupOptions(this.props.type),
},
async () => {
- actionSheet.current?.setModalVisible(true);
- await this.getSettings();
+ this.actionSheet.current?.setModalVisible(true);
},
);
}
- async getSettings() {
- let settings = await MMKV.getItem('appSettings');
- this.setState({
- settings: JSON.parse(settings),
- });
- }
-
async close() {
- actionSheet.current?.setModalVisible(false);
+ this.actionSheet.current?.setModalVisible(false);
await sleep(100);
this.setState({
visible: false,
@@ -80,13 +55,22 @@ class SortDialog extends React.Component {
eUnSubscribeEvent(eCloseSortDialog, this.close);
}
+ updateGroupOptions = async () => {
+ await db.settings.setGroupOptions(this.props.type, _groupOptions);
+ this.setState({
+ groupOptions: _groupOptions,
+ });
+ Navigation.setRoutesToUpdate([this.props.screen]);
+ };
+
render() {
const {colors} = this.props;
+ const {groupOptions, visible} = this.state;
- if (!this.state.visible) return null;
+ if (!visible) return null;
return (
- <ActionSheetWrapper fwdRef={actionSheet}>
+ <ActionSheetWrapper fwdRef={this.actionSheet}>
<View
style={{
width: '100%',
@@ -94,6 +78,7 @@ class SortDialog extends React.Component {
justifyContent: 'space-between',
borderRadius: 10,
paddingTop: 10,
+ paddingHorizontal: 12,
}}>
<View>
<View
@@ -101,7 +86,6 @@ class SortDialog extends React.Component {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
- paddingHorizontal: 12,
}}>
<Heading
size={SIZE.xl}
@@ -111,71 +95,93 @@ class SortDialog extends React.Component {
Sort by
</Heading>
- <TouchableOpacity
- testID={notesnook.ids.dialogs.sortBy.order}
- onPress={async () => {
- let value =
- this.state.settings?.sortOrder === 'asc' ? 'desc' : 'asc';
- await SettingsService.set('sortOrder', value);
- sortSettings.sortOrder = value;
- await this.getSettings();
- useNoteStore.getState().setNotes();
- }}
- activeOpacity={1}
+ <Button
+ title={
+ groupOptions.sortDirection === 'asc'
+ ? 'Ascending'
+ : 'Descending'
+ }
+ icon={
+ groupOptions.sortDirection === 'asc'
+ ? 'sort-ascending'
+ : 'sort-descending'
+ }
+ height={25}
+ iconPosition="right"
+ type="accent"
style={{
- flexDirection: 'row',
- alignItems: 'center',
- backgroundColor: colors.accent,
borderRadius: 100,
- paddingHorizontal: 8,
- height: 22,
- ...getElevation(2),
- }}>
- <Heading
- size={SIZE.sm}
+ }}
+ onPress={async () => {
+ let _groupOptions = {
+ ...groupOptions,
+ sortDirection:
+ groupOptions.sortDirection === 'asc' ? 'desc' : 'asc',
+ };
+ await this.updateGroupOptions(_groupOptions);
+ }}
+ />
+ </View>
+
+ <Seperator />
+ <View
+ style={{
+ flexDirection: 'row',
+ justifyContent: 'space-around',
+ }}>
+ {Object.keys(SORT).map((item, index) => (
+ <Button
+ type="gray"
+ title={SORT[item]}
+ height={40}
+ iconPosition="left"
+ icon="checkbox-blank-circle-outline"
+ fontSize={SIZE.sm}
style={{
- marginRight: 5,
- color: 'white',
- }}>
- {this.state.settings?.sortOrder === 'asc'
- ? 'Ascending'
- : 'Descending'}
- </Heading>
- <Icon
- color="white"
- name={
- this.state.settings?.sortOrder === 'asc'
- ? 'sort-ascending'
- : 'sort-descending'
- }
- size={SIZE.md}
+ backgroundColor: 'transparent',
+ }}
+ onPress={async () => {
+ let _groupOptions = {
+ ...groupOptions,
+ sortBy: type === 'trash' ? 'dateDeleted' : item,
+ };
+ await this.updateGroupOptions(_groupOptions);
+ }}
+ iconSize={SIZE.lg}
/>
- </TouchableOpacity>
+ ))}
+ </View>
+
+ <Seperator />
+ <View>
+ <Heading size={SIZE.xl}>Group by</Heading>
</View>
+
<Seperator />
- {Object.keys(SORT).map((item, index) => (
+ {Object.keys(GROUP).map((item, index) => (
<PressableButton
key={item}
testID={'btn-' + item}
type={this.state.settings?.sort === item ? 'shade' : 'gray'}
onPress={async () => {
- await SettingsService.set('sort', item);
- await this.getSettings();
- sortSettings.sort = item;
- useNoteStore.getState().setNotes();
+ let _groupOptions = {
+ ...groupOptions,
+ groupBy: GROUP[item],
+ };
+ this.updateGroupOptions(_groupOptions);
}}
- type="transparent"
customStyle={{
width: '100%',
height: 50,
justifyContent: 'space-between',
flexDirection: 'row',
alignItems: 'center',
- borderRadius: 0,
+ borderRadius: 5,
paddingHorizontal: 12,
+ marginBottom: 10,
}}>
- <Heading
+ <Paragraph
size={SIZE.sm}
color={
this.state.settings?.sort === item
@@ -183,19 +189,13 @@ class SortDialog extends React.Component {
: colors.pri
}>
{item.slice(0, 1).toUpperCase() + item.slice(1, item.length)}
- </Heading>
+ </Paragraph>
{this.state.settings?.sort === item ? (
<Icon color={colors.accent} name="check" size={SIZE.lg} />
) : null}
</PressableButton>
))}
</View>
-
- <View
- style={{
- height: 25,
- }}
- />
</View>
</ActionSheetWrapper>
);
diff --git a/apps/mobile/src/provider/stores.ts b/apps/mobile/src/provider/stores.ts
index e11599e47..a9aa81ce3 100644
--- a/apps/mobile/src/provider/stores.ts
+++ b/apps/mobile/src/provider/stores.ts
@@ -2,7 +2,7 @@ import { Platform } from 'react-native';
import { Dimensions } from 'react-native';
import create from 'zustand';
import PremiumService from '../services/PremiumService';
-import { history, SORT, sortSettings, SUBSCRIPTION_STATUS } from '../utils';
+import { history, SORT, GROUP, sortSettings, SUBSCRIPTION_STATUS } from '../utils';
import { db } from '../utils/DB';
import { MMKV } from '../utils/mmkv';
import {
@@ -20,7 +20,7 @@ import {
UserStore,
Announcement,
} from './interfaces';
-
+import { groupArray } from "notes-core/utils/grouping"
export const useNoteStore = create<NoteStore>((set, get) => ({
notes: [],
@@ -29,7 +29,7 @@ export const useNoteStore = create<NoteStore>((set, get) => ({
setNotes: items => {
if (!items) {
set({
- notes: db.notes.group(SORT[sortSettings.sort], sortSettings.sortOrder),
+ notes: groupArray(db.notes.all, db.settings?.getGroupOptions("home")),
});
return;
}
@@ -51,7 +51,7 @@ export const useNotebookStore = create<NotebookStore>((set, get) => ({
setNotebooks: items => {
if (!items) {
set({
- notebooks: db.notebooks.all,
+ notebooks: groupArray(db.notebooks.all, db.settings?.getGroupOptions("notebooks")),
});
return;
}
@@ -73,7 +73,7 @@ export const useFavoriteStore = create<FavoriteStore>((set, get) => ({
setFavorites: items => {
if (!items) {
set({
- favorites: db.notes.favorites,
+ favorites: groupArray(db.notes.favorites, db.settings?.getGroupOptions("favorites")),
});
return;
}
@@ -95,7 +95,7 @@ export const useTagStore = create<TagStore>((set, get) => ({
setTags: items => {
if (!items) {
set({
- tags: db.tags.all,
+ tags: groupArray(db.tags.all, db.settings?.getGroupOptions("tags")),
});
return;
}
@@ -117,7 +117,7 @@ export const useTrashStore = create<TrashStore>((set, get) => ({
setTrash: items => {
if (!items) {
set({
- trash: db.trash.all,
+ trash: groupArray(db.trash.all, db.settings?.getGroupOptions("trash")),
});
return;
}
diff --git a/apps/mobile/src/utils/index.js b/apps/mobile/src/utils/index.js
index 347ea8bd5..f4b9b750a 100755
--- a/apps/mobile/src/utils/index.js
+++ b/apps/mobile/src/utils/index.js
@@ -130,7 +130,7 @@ export const sortSettings = {
sortOrder: 'desc',
};
-export const SORT = {
+export const GROUP = {
default: null,
alphabetical: 'abc',
year: 'year',
@@ -138,6 +138,12 @@ export const SORT = {
month: 'month',
};
+export const SORT = {
+ dateEdited:"Date edited",
+ dateCreated:"Date created",
+ title:"Title",
+}
+
export const editing = {
currentlyEditing: false,
isFullscreen: false,
diff --git a/apps/mobile/src/views/Notes/index.js b/apps/mobile/src/views/Notes/index.js
index ba38b9d99..00b44fc5c 100644
--- a/apps/mobile/src/views/Notes/index.js
+++ b/apps/mobile/src/views/Notes/index.js
@@ -1,3 +1,4 @@
+import {groupArray} from 'notes-core/utils/grouping';
import React, {useCallback, useEffect, useState} from 'react';
import {Platform} from 'react-native';
import {ContainerBottomButton} from '../../components/Container/ContainerBottomButton';
@@ -57,7 +58,7 @@ export const Notes = ({route, navigation}) => {
) {
Navigation.goBack();
}
- setNotes(_notes);
+ setNotes(groupArray(_notes, 'notes'));
if (params.menu) {
navigation.setOptions({
animationEnabled: true,