Skip to content

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

refactor

ammarahm-edae1018067c94
diff --git a/apps/mobile/src/components/NotebookItem/index.js b/apps/mobile/src/components/NotebookItem/index.js
index 89a32ee88..3b7166619 100644
--- a/apps/mobile/src/components/NotebookItem/index.js
+++ b/apps/mobile/src/components/NotebookItem/index.js
@@ -1,16 +1,11 @@
-import React, {useState} from 'react';
+import React from 'react';
import {Text, TouchableOpacity, View} from 'react-native';
import Icon from 'react-native-vector-icons/Feather';
-import {db} from '../../../App';
import {opacity, ph, pv, SIZE, WEIGHT} from '../../common/common';
import {useTracked} from '../../provider';
import NavigationService from '../../services/NavigationService';
import {ToastEvent, w} from '../../utils/utils';
-import ActionSheet from '../ActionSheet';
-import {ActionSheetComponent} from '../ActionSheetComponent';
-import {AddNotebookDialog} from '../AddNotebookDialog';
-import {AddTopicDialog} from '../AddTopicDialog';
-import {Dialog} from '../Dialog';
+import {ActionSheetEvent, moveNoteHideEvent} from '../DialogManager';
export const NotebookItem = ({
item,
@@ -25,67 +20,25 @@ export const NotebookItem = ({
isTrash,
customStyle,
onLongPress,
+ navigation,
}) => {
const [state, dispatch] = useTracked();
const {colors} = state;
- ///
- const updateDB = () => {};
-
- const [isVisible, setVisible] = useState(false);
- const [addTopic, setAddTopic] = useState(false);
- const [addNotebook, setAddNotebook] = useState(false);
- let actionSheet;
- let setMenuRef = {};
- let show = null;
- let willRefresh;
-
- const deleteItem = async () => {
- if (isTopic) {
- await db.deleteTopicFromNotebook(notebookID, item.title);
- ToastEvent.show('Topic moved to trash', 'success', 3000);
- } else {
- await db.deleteNotebooks([item]);
- ToastEvent.show('Notebook moved to trash', 'success', 3000);
- }
- setVisible(false);
- updateDB();
- };
-
const navigate = () => {
isTopic
? NavigationService.navigate('Notes', {
...item,
notebookID,
})
- : NavigationService.navigate('Notebook', {
+ : navigation.navigate('Notebook', {
notebook: item,
- note: noteToMove,
- title: hideMore ? 'Choose a topic' : item.title,
- isMove: isMove ? true : false,
- hideMore: hideMore ? true : false,
+ title: hideMore ? 'Select Topic' : item.title,
+ isMove: isMove,
+ hideMore: hideMore,
});
};
- const onMenuHide = () => {
- if (show) {
- if (show === 'delete') {
- setVisible(true);
- show = null;
- } else if (show === 'topic') {
- isTopic ? setAddTopic(true) : setAddNotebook(true);
- }
- }
- };
-
- const hideMenu = () => {
- setMenuRef[index].hide();
- };
-
- const showMenu = () => {
- setMenuRef[index].show();
- };
-
return (
<View
style={[
@@ -102,30 +55,6 @@ export const NotebookItem = ({
},
customStyle,
]}>
- <Dialog
- visible={isVisible}
- title={`Delete ${isTopic ? 'topic' : 'notebook'}`}
- icon="trash"
- paragraph={`Do you want to delete this ${
- isTopic ? 'topic' : 'notebook'
- }?`}
- positiveText="Delete"
- positivePress={deleteItem}
- close={() => setVisible(false)}
- />
- <AddTopicDialog
- visible={addTopic}
- toEdit={item}
- close={() => setAddTopic(false)}
- />
- <AddNotebookDialog
- visible={addNotebook}
- toEdit={item}
- close={() => {
- setAddNotebook(false);
- }}
- />
-
<View
style={{
flexDirection: 'row',
@@ -286,7 +215,18 @@ export const NotebookItem = ({
alignItems: 'center',
}}
onPress={() => {
- actionSheet._setModalVisible();
+ let rowItems = isTrash
+ ? ['Restore', 'Remove']
+ : [
+ item.type == 'topic' ? 'Edit Topic' : 'Edit Notebook',
+ 'Delete',
+ ];
+
+ let columnItems = ['Pin', 'Favorite'];
+
+ ActionSheetEvent(item, false, false, rowItems, columnItems, {
+ notebookID: notebookID,
+ });
}}>
<Icon name="more-horizontal" size={SIZE.lg} color={colors.icon} />
</TouchableOpacity>
@@ -296,20 +236,22 @@ export const NotebookItem = ({
<TouchableOpacity
activeOpacity={opacity}
onPress={async () => {
- if (!noteToMove.notebook.notebook) {
+ /* if (!noteToMove.notebook.notebook) {
await db.addNoteToTopic(
notebookID,
item.title,
noteToMove.dateCreated,
);
- } else if (noteToMove.notebook.notebook) {
+ } else if (selectedItemsList) {
+
await db.moveNote(noteToMove.dateCreated, noteToMove.notebook, {
notebook: notebookID,
topic: item.title,
});
- }
+ } */
+
+ moveNoteHideEvent();
- NavigationService.navigate('Home');
ToastEvent.show(
`Note moved to ${item.title}`,
'success',
@@ -341,44 +283,6 @@ export const NotebookItem = ({
</TouchableOpacity>
) : null}
</View>
-
- <ActionSheet
- ref={ref => (actionSheet = ref)}
- customStyles={{
- backgroundColor: colors.bg,
- }}
- indicatorColor={colors.shade}
- initialOffsetFromBottom={1}
- onClose={() => {
- onMenuHide();
- if (willRefresh) {
- updateDB();
- }
- }}
- children={
- <ActionSheetComponent
- item={item}
- setWillRefresh={value => {
- willRefresh = true;
- }}
- rowItems={
- isTrash
- ? ['Restore', 'Remove']
- : [
- item.type == 'topic' ? 'Edit Topic' : 'Edit Notebook',
- 'Delete',
- ]
- }
- columnItems={['Pin', 'Favorite']}
- close={value => {
- if (value) {
- show = value;
- }
- actionSheet._setModalVisible();
- }}
- />
- }
- />
</View>
);
};
diff --git a/apps/mobile/src/components/header/index.js b/apps/mobile/src/components/header/index.js
index c04878dea..4d225fd28 100644
--- a/apps/mobile/src/components/header/index.js
+++ b/apps/mobile/src/components/header/index.js
@@ -6,6 +6,7 @@ import {SIZE, WEIGHT} from '../../common/common';
import {useTracked} from '../../provider';
import NavigationService from '../../services/NavigationService';
import {SideMenuEvent} from '../../utils/utils';
+import {moveNoteHideEvent} from '../DialogManager';
let isOpen = false;
export const Header = ({
heading,
@@ -15,6 +16,8 @@ export const Header = ({
menu,
verticalMenu = false,
sendHeight = e => {},
+ preventDefaultMargins,
+ navigation = null,
}) => {
const [state, dispatch] = useTracked();
const {colors} = state;
@@ -27,7 +30,12 @@ export const Header = ({
flexDirection: 'row',
zIndex: 10,
height: 50,
- marginTop: Platform.OS === 'ios' ? 0 : StatusBar.currentHeight,
+ marginTop:
+ Platform.OS === 'ios'
+ ? 0
+ : preventDefaultMargins
+ ? 0
+ : StatusBar.currentHeight,
marginBottom: 10,
justifyContent: 'space-between',
alignItems: 'center',
@@ -44,7 +52,15 @@ export const Header = ({
<TouchableOpacity
hitSlop={{top: 20, bottom: 20, left: 50, right: 40}}
onPress={() => {
- NavigationService.goBack();
+ if (navigation && preventDefaultMargins) {
+ if (navigation.state.routeName === 'Folders') {
+ moveNoteHideEvent();
+ } else {
+ navigation.goBack();
+ }
+ } else {
+ NavigationService.goBack();
+ }
}}
style={{
justifyContent: 'center',
diff --git a/apps/mobile/src/provider/index.js b/apps/mobile/src/provider/index.js
index b4438d40a..19080be62 100644
--- a/apps/mobile/src/provider/index.js
+++ b/apps/mobile/src/provider/index.js
@@ -33,6 +33,7 @@ const defaultState = {
warningBg: '#FEEFB3',
warningText: '#9F6000',
},
+ preventDefaultMargins: false,
};
export const ACTIONS = {
@@ -45,6 +46,8 @@ export const ACTIONS = {
SELECTION_MODE: 'selectionMode',
SELECTED_ITEMS: 'selectedItemsList',
THEME: 'theme',
+ MODAL_NAVIGATOR: 'modalNavigator',
+ CLEAR_SELECTION: 'clearSelection',
};
const reducer = (state, action) => {
@@ -108,11 +111,24 @@ const reducer = (state, action) => {
} else {
selectedItems.push(action.item);
}
+ console.log(action.item, selectedItems);
return {
...state,
selectedItemsList: selectedItems,
};
}
+ case ACTIONS.CLEAR_SELECTION: {
+ return {
+ ...state,
+ selectedItemsList: [],
+ };
+ }
+ case ACTIONS.MODAL_NAVIGATOR: {
+ return {
+ ...state,
+ preventDefaultMargins: action.enabled,
+ };
+ }
default:
throw new Error('unknown action type');
}