some cleanup

This commit is contained in:
ammarahm-ed
2020-09-14 17:10:02 +05:00
parent ed913a53c0
commit 708e2e93d8
8 changed files with 48 additions and 122 deletions

View File

@@ -27,7 +27,7 @@ import {
import {useTracked} from '../../provider'; import {useTracked} from '../../provider';
import {ACTIONS} from '../../provider/actions'; import {ACTIONS} from '../../provider/actions';
import {eSendEvent, openVault} from '../../services/eventManager'; import {eSendEvent, openVault} from '../../services/eventManager';
import {eOpenLoginDialog, refreshNotesPage} from '../../services/events'; import {eOpenLoginDialog, eOpenMoveNoteDialog, refreshNotesPage} from '../../services/events';
import NavigationService from '../../services/NavigationService'; import NavigationService from '../../services/NavigationService';
import {MMKV} from '../../utils/storage'; import {MMKV} from '../../utils/storage';
import { import {
@@ -211,8 +211,11 @@ export const ActionSheetComponent = ({
func: () => { func: () => {
dispatch({type: ACTIONS.MODAL_NAVIGATOR, enabled: true}); dispatch({type: ACTIONS.MODAL_NAVIGATOR, enabled: true});
dispatch({type: ACTIONS.SELECTED_ITEMS, item: note}); dispatch({type: ACTIONS.SELECTED_ITEMS, item: note});
close();
close('movenote'); setTimeout(() => {
eSendEvent(eOpenMoveNoteDialog);
},400)
}, },
}, },
{ {

View File

@@ -87,11 +87,13 @@ export class DialogManager extends Component {
}; };
_showMoveNote = () => { _showMoveNote = () => {
this.moveNoteDialog.open();
///this.moveNoteDialog.open();
}; };
_hideMoveNote = () => { _hideMoveNote = () => {
this.moveNoteDialog.close(); //eSendEvent(eCloseMoveNoteDialog)
// this.moveNoteDialog.close();
}; };
loadNote = i => { loadNote = i => {
@@ -189,17 +191,17 @@ export class DialogManager extends Component {
}; };
showAddNotebook = data => { showAddNotebook = data => {
/* this.setState( this.setState(
{ {
item: data.item ? data.item : {}, item: data.item ? data.item : {},
}, },
() => { () => {
this.addNotebooksDialog.open(); this.addNotebooksDialog.open();
}, },
); */ );
}; };
hideAddNotebook = () => { hideAddNotebook = () => {
//this.addNotebooksDialog.close(); this.addNotebooksDialog.close();
}; };
_showSimpleDialog = data => { _showSimpleDialog = data => {
@@ -252,7 +254,7 @@ export class DialogManager extends Component {
break; break;
} }
case 'movenote': { case 'movenote': {
moveNoteEvent(); // this._showMoveNote();
break; break;
} }
case "premium": { case "premium": {

View File

@@ -1,26 +1,26 @@
import React, { createRef, useEffect, useState } from 'react'; import React, {createRef, useEffect, useState} from 'react';
import { import {
FlatList, FlatList,
Modal, Modal,
Text, Text,
TextInput, TextInput,
TouchableOpacity, TouchableOpacity,
View View,
} from 'react-native'; } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context'; import {useSafeAreaInsets} from 'react-native-safe-area-context';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import { pv, SIZE, WEIGHT } from '../../common/common'; import {pv, SIZE, WEIGHT} from '../../common/common';
import { useTracked } from '../../provider'; import {useTracked} from '../../provider';
import { ACTIONS } from '../../provider/actions'; import {ACTIONS} from '../../provider/actions';
import { eSubscribeEvent, eUnSubscribeEvent } from '../../services/eventManager'; import {eSubscribeEvent, eUnSubscribeEvent} from '../../services/eventManager';
import { eOpenMoveNoteDialog } from '../../services/events'; import {eOpenMoveNoteDialog} from '../../services/events';
import { db, DDS, getElevation, ToastEvent } from '../../utils/utils'; import {db, DDS, getElevation, ToastEvent} from '../../utils/utils';
import { PressableButton } from '../PressableButton'; import {PressableButton} from '../PressableButton';
import { Toast } from '../Toast'; import {Toast} from '../Toast';
const MoveNoteDialog = () => { const MoveNoteDialog = () => {
const [state, dispatch] = useTracked(); const [state, dispatch] = useTracked();
const {notebooks, colors, selectedItemsList} = state; const {notebooks, colors, selectedItemsList} = state;
const [visible, setVisible] = useState(true); const [visible, setVisible] = useState(false);
const [animated, setAnimated] = useState(false); const [animated, setAnimated] = useState(false);
const [expanded, setExpanded] = useState(''); const [expanded, setExpanded] = useState('');
const [notebookInputFocused, setNotebookInputFocused] = useState(false); const [notebookInputFocused, setNotebookInputFocused] = useState(false);
@@ -40,7 +40,6 @@ const MoveNoteDialog = () => {
}; };
useEffect(() => { useEffect(() => {
console.log(notebooks);
eSubscribeEvent(eOpenMoveNoteDialog, open); eSubscribeEvent(eOpenMoveNoteDialog, open);
return () => { return () => {
eUnSubscribeEvent(eOpenMoveNoteDialog, open); eUnSubscribeEvent(eOpenMoveNoteDialog, open);

View File

@@ -25,7 +25,7 @@ export const NotebookItem = ({
<View <View
style={[ style={[
{ {
height: isTopic ? 80 : 120, height: isTopic ? 80 : 110,
justifyContent: 'space-between', justifyContent: 'space-between',
alignItems: 'center', alignItems: 'center',
flexDirection: 'row', flexDirection: 'row',
@@ -39,8 +39,8 @@ export const NotebookItem = ({
]}> ]}>
<View <View
style={{ style={{
width: hideMore ? '80%' : '90%', width: '90%',
maxWidth: hideMore ? '80%' : '90%', maxWidth: '90%',
minHeight: 50, minHeight: 50,
justifyContent: 'center', justifyContent: 'center',
}}> }}>
@@ -76,6 +76,7 @@ export const NotebookItem = ({
width: '80%', width: '80%',
maxWidth: '80%', maxWidth: '80%',
flexWrap: 'wrap', flexWrap: 'wrap',
paddingVertical: item.description ? 0 : 5,
}}> }}>
{item && item.topics ? ( {item && item.topics ? (
item.topics.slice(1, 4).map((topic) => ( item.topics.slice(1, 4).map((topic) => (
@@ -180,8 +181,7 @@ export const NotebookItem = ({
</Text> </Text>
</View> </View>
</View> </View>
{hideMore || {item.title === 'General' && item.type === 'topic' ? null : (
(item.title === 'General' && item.type === 'topic') ? null : (
<TouchableOpacity <TouchableOpacity
style={{ style={{
justifyContent: 'center', justifyContent: 'center',
@@ -205,30 +205,6 @@ export const NotebookItem = ({
<Icon name="dots-horizontal" size={SIZE.lg} color={colors.heading} /> <Icon name="dots-horizontal" size={SIZE.lg} color={colors.heading} />
</TouchableOpacity> </TouchableOpacity>
)} )}
{hideMore && isTopic ? (
<Button
width="20%"
title="Move"
onPress={async () => {
let noteIds = [];
selectedItemsList.forEach((item) => noteIds.push(item.id));
await db.notes.move(
{
topic: item.title,
id: item.notebookId,
},
...noteIds,
);
dispatch({type: ACTIONS.CLEAR_SELECTION});
moveNoteHideEvent();
ToastEvent.show(`Note moved to ${item.title}`, 'success');
}}
/>
) : null}
</View> </View>
); );
}; };

View File

@@ -49,7 +49,7 @@ export const NotebookItemWrapper = ({
dispatch({ dispatch({
type: ACTIONS.HEADER_TEXT_STATE, type: ACTIONS.HEADER_TEXT_STATE,
state: { state: {
heading: preventDefaultMargins ? 'Move to topic' : item.title, heading: item.title,
}, },
}); });
dispatch({ dispatch({
@@ -66,21 +66,11 @@ export const NotebookItemWrapper = ({
}, },
}); });
preventDefaultMargins NavigationService.navigate('Notebook', {
? navigation.navigate('Notebook', { notebook: item,
notebook: item, title: item.title,
title: preventDefaultMargins ? 'Move to topic' : item.title, root: true,
isMove: preventDefaultMargins, });
hideMore: preventDefaultMargins,
root: preventDefaultMargins ? false : true,
})
: NavigationService.navigate('Notebook', {
notebook: item,
title: preventDefaultMargins ? 'Select a topic' : item.title,
isMove: preventDefaultMargins,
hideMore: preventDefaultMargins,
root: true,
});
} }
}; };
@@ -95,7 +85,7 @@ export const NotebookItemWrapper = ({
hideMore={preventDefaultMargins} hideMore={preventDefaultMargins}
navigation={headerState.navigation} navigation={headerState.navigation}
route={headerState.route} route={headerState.route}
isTopic={item.type === "topic"} isTopic={item.type === 'topic'}
customStyle={style} customStyle={style}
noteToMove={params.note} noteToMove={params.note}
item={item} item={item}

View File

@@ -9,21 +9,12 @@ import {ACTIONS} from '../../provider/actions';
import {eSendEvent} from '../../services/eventManager'; import {eSendEvent} from '../../services/eventManager';
import {eScrollEvent} from '../../services/events'; import {eScrollEvent} from '../../services/events';
import NavigationService from '../../services/NavigationService'; import NavigationService from '../../services/NavigationService';
import { Placeholder } from '../../components/ListPlaceholders'; import {Placeholder} from '../../components/ListPlaceholders';
export const Folders = ({route, navigation}) => { export const Folders = ({route, navigation}) => {
const [state, dispatch] = useTracked(); const [state, dispatch] = useTracked();
const {notebooks} = state; const {notebooks} = state;
let isFocused = useIsFocused(); let isFocused = useIsFocused();
const handleBackPress = () => {
if (route.params.isMove) {
return true;
} else {
NavigationService.goBack();
return true;
}
};
useEffect(() => { useEffect(() => {
if (isFocused) { if (isFocused) {
dispatch({ dispatch({
@@ -35,7 +26,6 @@ export const Folders = ({route, navigation}) => {
route: route, route: route,
color: null, color: null,
navigation: navigation, navigation: navigation,
ind:!params.root
}, },
}); });
dispatch({ dispatch({
@@ -45,7 +35,6 @@ export const Folders = ({route, navigation}) => {
bottomButtonOnPress: () => AddNotebookEvent(), bottomButtonOnPress: () => AddNotebookEvent(),
color: null, color: null,
visible: true, visible: true,
ind:!params.root
}, },
}); });
dispatch({ dispatch({
@@ -56,7 +45,6 @@ export const Folders = ({route, navigation}) => {
type: ACTIONS.HEADER_TEXT_STATE, type: ACTIONS.HEADER_TEXT_STATE,
state: { state: {
heading: params.title, heading: params.title,
ind:!params.root
}, },
}); });
dispatch({type: ACTIONS.PINNED}); dispatch({type: ACTIONS.PINNED});
@@ -66,7 +54,6 @@ export const Folders = ({route, navigation}) => {
screen: 'notebooks', screen: 'notebooks',
}); });
} }
}, [isFocused]); }, [isFocused]);
useEffect(() => { useEffect(() => {
@@ -74,33 +61,16 @@ export const Folders = ({route, navigation}) => {
dispatch({ dispatch({
type: ACTIONS.SEARCH_STATE, type: ACTIONS.SEARCH_STATE,
state: { state: {
placeholder:params.root? 'Search all notebooks' : 'Select a notebook', placeholder:'Search all notebooks',
data: notebooks, data: notebooks,
noSearch: false, noSearch: false,
type: 'notebooks', type: 'notebooks',
color: null, color: null,
ind:!params.root
}, },
}); });
} }
}, [notebooks, isFocused]); }, [notebooks, isFocused]);
useEffect(() => {
eSendEvent(eScrollEvent, 0);
let backhandler;
backhandler = BackHandler.addEventListener(
'hardwareBackPress',
handleBackPress,
);
return () => {
if (!backhandler) return;
backhandler.remove();
backhandler = null;
};
}, []);
const params = route.params; const params = route.params;
return ( return (
@@ -109,9 +79,6 @@ export const Folders = ({route, navigation}) => {
type="notebooks" type="notebooks"
focused={isFocused} focused={isFocused}
RenderItem={NotebookItemWrapper} RenderItem={NotebookItemWrapper}
hideMore={params.hideMore}
isMove={params.isMove}
noteToMove={params.note}
placeholder={<Placeholder type="notebooks" />} placeholder={<Placeholder type="notebooks" />}
pinned={true} pinned={true}
placeholderText="Notebooks you add will appear here" placeholderText="Notebooks you add will appear here"

View File

@@ -39,6 +39,7 @@ export const Login = ({route, navigation}) => {
const [username, setUsername] = useState(null); const [username, setUsername] = useState(null);
const [invalidUsername, setInvalidUsername] = useState(false); const [invalidUsername, setInvalidUsername] = useState(false);
const [secureEntry, setSecureEntry] = useState(true); const [secureEntry, setSecureEntry] = useState(true);
const _email = createRef(); const _email = createRef();
const _pass = createRef(); const _pass = createRef();
const _passContainer = createRef(); const _passContainer = createRef();

View File

@@ -1,12 +1,11 @@
import {useIsFocused} from '@react-navigation/native';
import React, {useEffect, useState} from 'react'; import React, {useEffect, useState} from 'react';
import {AddTopicEvent} from '../../components/DialogManager/recievers'; import {AddTopicEvent} from '../../components/DialogManager/recievers';
import {NotebookPlaceHolder} from '../../components/ListPlaceholders';
import {NotebookItem} from '../../components/NotebookItem'; import {NotebookItem} from '../../components/NotebookItem';
import SelectionWrapper from '../../components/SelectionWrapper'; import SelectionWrapper from '../../components/SelectionWrapper';
import SimpleList from '../../components/SimpleList'; import SimpleList from '../../components/SimpleList';
import {useTracked} from '../../provider'; import {useTracked} from '../../provider';
import {ACTIONS} from '../../provider/actions'; import {ACTIONS} from '../../provider/actions';
import {useIsFocused} from '@react-navigation/native';
import { import {
eSendEvent, eSendEvent,
eSubscribeEvent, eSubscribeEvent,
@@ -16,7 +15,6 @@ import {
eMoveNoteDialogNavigateBack, eMoveNoteDialogNavigateBack,
eOnNewTopicAdded, eOnNewTopicAdded,
eScrollEvent, eScrollEvent,
eSetModalNavigator,
} from '../../services/events'; } from '../../services/events';
import {db, ToastEvent, w} from '../../utils/utils'; import {db, ToastEvent, w} from '../../utils/utils';
@@ -26,23 +24,18 @@ export const Notebook = ({route, navigation}) => {
const [refreshing, setRefreshing] = useState(false); const [refreshing, setRefreshing] = useState(false);
let params = route.params; let params = route.params;
let notebook;
let isFocused = useIsFocused(); let isFocused = useIsFocused();
const onLoad = () => { const onLoad = () => {
let allTopics; let allTopics;
allTopics = db.notebooks.notebook(route.params.notebook.id).data.topics; allTopics = db.notebooks.notebook(route.params.notebook.id).data.topics;
notebook = db.notebooks.notebook(route.params.notebook.id);
setTopics(allTopics); setTopics(allTopics);
}; };
useEffect(() => { useEffect(() => {
eSendEvent(eScrollEvent, 0); eSendEvent(eScrollEvent, 0);
params = route.params; params = route.params;
let topic = params.notebook.topics; setTopics([...params.notebook.topics]);
notebook = params.notebook;
setTopics([...topic]);
}, []); }, []);
useEffect(() => { useEffect(() => {
@@ -65,11 +58,10 @@ export const Notebook = ({route, navigation}) => {
type: 'topics', type: 'topics',
menu: false, menu: false,
canGoBack: true, canGoBack: true,
heading:params.title, heading: params.title,
route: route, route: route,
color: null, color: null,
navigation: navigation, navigation: navigation,
ind: !params.root,
}, },
}); });
dispatch({ dispatch({
@@ -82,7 +74,6 @@ export const Notebook = ({route, navigation}) => {
}, },
color: null, color: null,
bottomButtonText: 'Add new topic', bottomButtonText: 'Add new topic',
ind: !params.root
}, },
}); });
dispatch({ dispatch({
@@ -94,7 +85,6 @@ export const Notebook = ({route, navigation}) => {
type: ACTIONS.HEADER_TEXT_STATE, type: ACTIONS.HEADER_TEXT_STATE,
state: { state: {
heading: params.title, heading: params.title,
ind: !params.root
}, },
}); });
@@ -102,9 +92,6 @@ export const Notebook = ({route, navigation}) => {
type: ACTIONS.CURRENT_SCREEN, type: ACTIONS.CURRENT_SCREEN,
screen: 'notebook', screen: 'notebook',
}); });
if (!params.root) {
eSendEvent(eSetModalNavigator,true);
}
} }
}, [isFocused]); }, [isFocused]);
@@ -118,7 +105,6 @@ export const Notebook = ({route, navigation}) => {
noSearch: false, noSearch: false,
type: 'topics', type: 'topics',
color: null, color: null,
ind: !params.root
}, },
}); });
} }
@@ -165,8 +151,10 @@ export default Notebook;
const RenderItem = ({item, index}) => { const RenderItem = ({item, index}) => {
const [state, dispatch] = useTracked(); const [state, dispatch] = useTracked();
const {colors, selectionMode, preventDefaultMargins} = state; const {colors, selectionMode, preventDefaultMargins} = state;
let headerState = preventDefaultMargins? state.indHeaderState : state.headerState; let headerState = preventDefaultMargins
let params = headerState.route.params? headerState.route.params : {}; ? state.indHeaderState
: state.headerState;
let params = headerState.route.params ? headerState.route.params : {};
return ( return (
<SelectionWrapper item={item}> <SelectionWrapper item={item}>