Skip to content

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

add notes sorting

ammarahm-ed52552503f270
diff --git a/apps/mobile/src/components/DialogManager/index.js b/apps/mobile/src/components/DialogManager/index.js
index 0299cc34e..2d534ae13 100644
--- a/apps/mobile/src/components/DialogManager/index.js
+++ b/apps/mobile/src/components/DialogManager/index.js
@@ -414,7 +414,9 @@ export class DialogManager extends Component {
}
: null
}
- initialOffsetFromBottom={DDS.isTab || item.type !== 'note' ? 1 : 0.5}
+ initialOffsetFromBottom={
+ DDS.isTab || item.type !== 'note' || item.dateDeleted ? 1 : 0.5
+ }
bounceOnOpen={true}
gestureEnabled={true}
onClose={() => {
diff --git a/apps/mobile/src/components/header/index.js b/apps/mobile/src/components/header/index.js
index 9a7c56445..ad597d1ac 100644
--- a/apps/mobile/src/components/header/index.js
+++ b/apps/mobile/src/components/header/index.js
@@ -1,4 +1,4 @@
-import React from 'react';
+import React, {createRef} from 'react';
import {Platform, StatusBar, Text, TouchableOpacity, View} from 'react-native';
import * as Animatable from 'react-native-animatable';
import {DDS} from '../../../App';
@@ -10,7 +10,8 @@ import NavigationService from '../../services/NavigationService';
import {SideMenuEvent} from '../../utils/utils';
import {moveNoteHideEvent} from '../DialogManager';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
-
+import Menu, {MenuItem, MenuDivider} from 'react-native-material-menu';
+import {ACTIONS} from '../../provider/actions';
export const Header = ({
heading,
canGoBack = true,
@@ -25,7 +26,7 @@ export const Header = ({
}) => {
const [state, dispatch] = useTracked();
const {colors} = state;
-
+ const menuRef = createRef();
return (
<View
style={{
@@ -147,15 +148,69 @@ export const Header = ({
</TouchableOpacity>
</Animatable.View>
{verticalMenu ? (
- <TouchableOpacity
+ <Menu
+ ref={menuRef}
style={{
- justifyContent: 'center',
- alignItems: 'flex-end',
- height: 40,
- width: 60,
- }}>
- <Icon name="sort" size={SIZE.xl} color={colors.icon} />
- </TouchableOpacity>
+ borderRadius: 5,
+ }}
+ button={
+ <TouchableOpacity
+ onPress={() => {
+ menuRef.current?.show();
+ }}
+ style={{
+ justifyContent: 'center',
+ alignItems: 'flex-end',
+ height: 40,
+ width: 60,
+ }}>
+ <Icon name="sort" size={SIZE.xl} color={colors.icon} />
+ </TouchableOpacity>
+ }>
+ <MenuItem
+ textStyle={{
+ color: colors.icon,
+ fontSize: 12,
+ }}>
+ Sort by:
+ </MenuItem>
+ <MenuDivider />
+ <MenuItem
+ onPress={() => {
+ dispatch({type: ACTIONS.NOTES, sort: null});
+ menuRef.current?.hide();
+ }}>
+ Default
+ </MenuItem>
+ <MenuItem
+ onPress={() => {
+ dispatch({type: ACTIONS.NOTES, sort: 'abc'});
+ menuRef.current?.hide();
+ }}>
+ Alphabetical
+ </MenuItem>
+ <MenuItem
+ onPress={() => {
+ dispatch({type: ACTIONS.NOTES, sort: 'year'});
+ menuRef.current?.hide();
+ }}>
+ By year
+ </MenuItem>
+ <MenuItem
+ onPress={() => {
+ dispatch({type: ACTIONS.NOTES, sort: 'month'});
+ menuRef.current?.hide();
+ }}>
+ By month
+ </MenuItem>
+ <MenuItem
+ onPress={() => {
+ dispatch({type: ACTIONS.NOTES, sort: 'week'});
+ menuRef.current?.hide();
+ }}>
+ By week
+ </MenuItem>
+ </Menu>
) : null}
</View>
</View>
diff --git a/apps/mobile/src/provider/reducer.js b/apps/mobile/src/provider/reducer.js
index 5ddcbb3a1..dab866927 100644
--- a/apps/mobile/src/provider/reducer.js
+++ b/apps/mobile/src/provider/reducer.js
@@ -5,7 +5,12 @@ import {ACTIONS} from './actions';
export const reducer = (state, action) => {
switch (action.type) {
case ACTIONS.NOTES:
- let notes = db.notes.group();
+ let notes;
+ if (action.sort) {
+ notes = db.notes.group(action.sort);
+ } else {
+ notes = db.notes.group();
+ }
return {
...state,
diff --git a/apps/mobile/src/views/Editor/index.js b/apps/mobile/src/views/Editor/index.js
index 402a7ddae..67f8112ae 100755
--- a/apps/mobile/src/views/Editor/index.js
+++ b/apps/mobile/src/views/Editor/index.js
@@ -287,21 +287,32 @@ const Editor = ({navigation, noMenu}) => {
} else {
post('focusTitle');
post('clear');
+ wait(500).then(() => {
+ setLoading(false);
+ });
}
if (note.content.text === '' && note.content.delta === null) {
post('clear');
+ wait(500).then(() => {
+ setLoading(false);
+ });
} else if (note.content.delta) {
let delta;
- if (note.content.delta !== note.id + '_delta') {
+ if (!note.content.delta.includes('_note_delta')) {
delta = note.content.delta;
} else {
delta = await db.notes.note(id).delta();
+
+ console.log(delta, 'sending delta', note.id);
}
post(JSON.stringify(delta));
} else {
post(JSON.stringify({type: 'text', value: note.content.text}));
+ wait(2000).then(() => {
+ setLoading(false);
+ });
}
};