bug fixes

This commit is contained in:
ammarahm-ed
2020-02-02 16:18:52 +05:00
parent 884aa56d08
commit 096cc89694
11 changed files with 224 additions and 77 deletions

View File

@@ -81,22 +81,11 @@ export const ActionSheetComponent = ({
if (tag.includes(' ')) { if (tag.includes(' ')) {
tag = tag.replace(' ', '_'); tag = tag.replace(' ', '_');
} }
let oldProps = {...note};
if (oldProps.tags.includes(tag)) {
return;
} else {
oldProps.tags.push(tag);
}
tagsInputRef.setNativeProps({ tagsInputRef.setNativeProps({
text: '', text: '',
}); });
await db.addNote({ await db.addTag(note.dateCreated, tag);
dateCreated: note.dateCreated,
tags: oldProps.tags,
});
setNote({...db.getNote(note.dateCreated)}); setNote({...db.getNote(note.dateCreated)});
tagToAdd = ''; tagToAdd = '';
}; };
@@ -114,13 +103,12 @@ export const ActionSheetComponent = ({
let tagInputValue = note.tags[note.tags.length - 1]; let tagInputValue = note.tags[note.tags.length - 1];
let oldProps = {...note}; let oldProps = {...note};
if (oldProps.tags.length === 0) return; if (oldProps.tags.length === 0) return;
//oldProps.tags.splice(oldProps.tags.length - 1);
await db.removeTag(
note.dateCreated,
oldProps.tags[oldProps.tags.length - 1],
);
oldProps.tags.splice(oldProps.tags.length - 1);
await db.addNote({
dateCreated: note.dateCreated,
tags: oldProps.tags,
});
setNote({...db.getNote(note.dateCreated)}); setNote({...db.getNote(note.dateCreated)});
tagsInputRef.setNativeProps({ tagsInputRef.setNativeProps({
@@ -262,9 +250,13 @@ export const ActionSheetComponent = ({
icon: 'tag', icon: 'tag',
func: async () => { func: async () => {
if (!note.dateCreated) return; if (!note.dateCreated) return;
await db.pinItem(note.type, note.dateCreated); if (note.type === 'note') {
localRefresh(item.type); await db.pinNote(note.dateCreated);
} else {
await db.pinNotebook(note.dateCreated);
}
dispatch({type: ACTIONS.PINNED}); dispatch({type: ACTIONS.PINNED});
localRefresh(item.type);
}, },
close: false, close: false,
check: true, check: true,
@@ -275,9 +267,13 @@ export const ActionSheetComponent = ({
icon: 'star', icon: 'star',
func: async () => { func: async () => {
if (!note.dateCreated) return; if (!note.dateCreated) return;
await db.favoriteItem(note.type, note.dateCreated); if (note.type === 'note') {
localRefresh(item.type); await db.favoriteNotes([note.dateCreated]);
} else {
await db.favoriteNotebooks([note.dateCreated]);
}
dispatch({type: ACTIONS.FAVORITES}); dispatch({type: ACTIONS.FAVORITES});
localRefresh(item.type);
}, },
close: false, close: false,
check: true, check: true,
@@ -484,7 +480,10 @@ export const ActionSheetComponent = ({
return ( return (
<View <View
onLayout={() => { onLayout={() => {
localRefresh(item.type, true); if (!item.dateDeleted) {
localRefresh(item.type, true);
}
console.log(note.dateCreated, 'here');
}} }}
style={{ style={{
paddingBottom: 15, paddingBottom: 15,

View File

@@ -31,7 +31,6 @@ export class AddNotebookDialog extends React.Component {
}; };
this.title = null; this.title = null;
this.description = null; this.description = null;
this.listRef; this.listRef;
this.prevItem = null; this.prevItem = null;
this.prevIndex = null; this.prevIndex = null;
@@ -123,6 +122,7 @@ export class AddNotebookDialog extends React.Component {
}; };
onSubmit = () => { onSubmit = () => {
let {topics} = this.state;
if ( if (
!this.currentInputValue || !this.currentInputValue ||
this.currentInputValue === '' || this.currentInputValue === '' ||

View File

@@ -74,10 +74,20 @@ export class Dialog extends Component {
visible: false, visible: false,
}); });
} }
case dialogActions.ACTION_TRASH: {
db.restoreItem(item.dateCreated);
updateEvent({type: ACTIONS.TRASH});
this.hide();
}
} }
}; };
_onClose = () => { _onClose = () => {
let {template, item} = this.props;
if (dialogActions.ACTION_TRASH === template.action) {
// delete item forever.
console.log('deleted forever');
}
this.setState({ this.setState({
visible: false, visible: false,
}); });
@@ -172,6 +182,27 @@ export class Dialog extends Component {
flexDirection: 'row', flexDirection: 'row',
marginTop: 20, marginTop: 20,
}}> }}>
<TouchableOpacity
activeOpacity={opacity}
onPress={this._onClose}
style={{
paddingVertical: pv,
paddingHorizontal: ph,
borderRadius: 5,
width: '48%',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: colors.nav,
}}>
<Text
style={{
fontFamily: WEIGHT.medium,
color: colors.icon,
fontSize: SIZE.sm,
}}>
{negativeText}
</Text>
</TouchableOpacity>
<TouchableOpacity <TouchableOpacity
activeOpacity={opacity} activeOpacity={opacity}
onPress={this._onPress} onPress={this._onPress}
@@ -195,28 +226,6 @@ export class Dialog extends Component {
{positiveText} {positiveText}
</Text> </Text>
</TouchableOpacity> </TouchableOpacity>
<TouchableOpacity
activeOpacity={opacity}
onPress={this._onClose}
style={{
paddingVertical: pv,
paddingHorizontal: ph,
borderRadius: 5,
width: '48%',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: colors.nav,
}}>
<Text
style={{
fontFamily: WEIGHT.medium,
color: colors.icon,
fontSize: SIZE.sm,
}}>
{negativeText}
</Text>
</TouchableOpacity>
</View> </View>
</View> </View>
</View> </View>

View File

@@ -35,6 +35,7 @@ export const dialogActions = {
ACTION_EXIT: 512, ACTION_EXIT: 512,
ACTION_EMPTY_TRASH: 513, ACTION_EMPTY_TRASH: 513,
ACTION_EXIT_FULLSCREEN: 514, ACTION_EXIT_FULLSCREEN: 514,
ACTION_TRASH: 515,
}; };
export const ActionSheetEvent = ( export const ActionSheetEvent = (
@@ -101,6 +102,17 @@ export const TEMPLATE_DELETE = type => {
}; };
}; };
export const TEMPLATE_TRASH = type => {
return {
title: `Delete ${type}`,
paragraph: `Restore or delete ${type} forever`,
positiveText: 'Restore',
negativeText: 'Delete',
action: dialogActions.ACTION_TRASH,
icon: 'trash',
};
};
export const TEMPLATE_EXIT_FULLSCREEN = () => { export const TEMPLATE_EXIT_FULLSCREEN = () => {
return { return {
title: `Exit fullscreen editor?`, title: `Exit fullscreen editor?`,

View File

@@ -159,7 +159,7 @@ class MoveNoteDialog extends React.Component {
height: DDS.isTab ? '90%' : '100%', height: DDS.isTab ? '90%' : '100%',
borderRadius: DDS.isTab ? 5 : 0, borderRadius: DDS.isTab ? 5 : 0,
backgroundColor: colors.bg, backgroundColor: colors.bg,
padding: 8, padding: DDS.isTab ? 8 : 0,
zIndex: 10, zIndex: 10,
}}> }}>
<Navigator <Navigator

View File

@@ -11,9 +11,13 @@ import {DDS} from '../../../App';
import {ph, pv, SIZE, WEIGHT} from '../../common/common'; import {ph, pv, SIZE, WEIGHT} from '../../common/common';
import NavigationService from '../../services/NavigationService'; import NavigationService from '../../services/NavigationService';
import {getElevation, timeSince} from '../../utils/utils'; import {getElevation, timeSince} from '../../utils/utils';
import {ActionSheetEvent} from '../DialogManager'; import {
ActionSheetEvent,
TEMPLATE_TRASH,
simpleDialogEvent,
} from '../DialogManager';
import {eSendEvent} from '../../services/eventManager'; import {eSendEvent} from '../../services/eventManager';
import {eOnLoadNote} from '../../services/events'; import {eOnLoadNote, eOpenSimpleDialog} from '../../services/events';
const w = Dimensions.get('window').width; const w = Dimensions.get('window').width;
const h = Dimensions.get('window').height; const h = Dimensions.get('window').height;
@@ -117,6 +121,8 @@ export default class NoteItem extends React.Component {
} else { } else {
DDS.isTab DDS.isTab
? eSendEvent(eOnLoadNote, item) ? eSendEvent(eOnLoadNote, item)
: isTrash
? simpleDialogEvent(TEMPLATE_TRASH(item.type))
: NavigationService.navigate('Editor', { : NavigationService.navigate('Editor', {
note: item, note: item,
}); });
@@ -267,10 +273,12 @@ export default class NoteItem extends React.Component {
onPress={() => { onPress={() => {
ActionSheetEvent( ActionSheetEvent(
item, item,
true, isTrash ? false : true,
true, isTrash ? false : true,
['Add to', 'Share', 'Export', 'Delete'], isTrash
['Add to Vault', 'Pin', 'Favorite'], ? ['Remove', 'Restore']
: ['Add to', 'Share', 'Export', 'Delete'],
[],
); );
}}> }}>
<Icon name="more-horizontal" size={SIZE.lg} color={colors.icon} /> <Icon name="more-horizontal" size={SIZE.lg} color={colors.icon} />

View File

@@ -23,7 +23,7 @@ export const NotebookItem = ({
navigation, navigation,
}) => { }) => {
const [state, dispatch] = useTracked(); const [state, dispatch] = useTracked();
const {colors} = state; const {colors, selectedItemsList} = state;
const navigate = () => { const navigate = () => {
isTopic isTopic
@@ -100,8 +100,9 @@ export const NotebookItem = ({
flexDirection: 'row', flexDirection: 'row',
alignItems: 'center', alignItems: 'center',
marginTop: 5, marginTop: 5,
width: '80%', width: '95%',
maxWidth: '80%', maxWidth: '95%',
flexWrap: 'wrap',
}}> }}>
{item && item.topics {item && item.topics
? item.topics.slice(1, 4).map(topic => ( ? item.topics.slice(1, 4).map(topic => (
@@ -113,6 +114,7 @@ export const NotebookItem = ({
paddingHorizontal: ph / 1.5, paddingHorizontal: ph / 1.5,
paddingVertical: pv / 4, paddingVertical: pv / 4,
marginRight: 10, marginRight: 10,
marginVertical: 4,
}}> }}>
<Text <Text
numberOfLines={1} numberOfLines={1}
@@ -233,6 +235,7 @@ export const NotebookItem = ({
<TouchableOpacity <TouchableOpacity
activeOpacity={opacity} activeOpacity={opacity}
onPress={async () => { onPress={async () => {
console.log(selectedItemsList, item);
/* if (!noteToMove.notebook.notebook) { /* if (!noteToMove.notebook.notebook) {
await db.addNoteToTopic( await db.addNoteToTopic(
notebookID, notebookID,
@@ -247,7 +250,7 @@ export const NotebookItem = ({
}); });
} */ } */
moveNoteHideEvent(); // moveNoteHideEvent();
ToastEvent.show( ToastEvent.show(
`Note moved to ${item.title}`, `Note moved to ${item.title}`,

View File

@@ -34,6 +34,7 @@ export const Folders = ({navigation}) => {
useEffect(() => { useEffect(() => {
dispatch({type: ACTIONS.NOTEBOOKS}); dispatch({type: ACTIONS.NOTEBOOKS});
console.log(notebooks);
let backhandler; let backhandler;
if (isFocused) { if (isFocused) {
backhandler = BackHandler.addEventListener( backhandler = BackHandler.addEventListener(

View File

@@ -1,4 +1,4 @@
import React, {useEffect} from 'react'; import React, {useEffect, useState} from 'react';
import {FlatList, Platform, Text, View} from 'react-native'; import {FlatList, Platform, Text, View} from 'react-native';
import {useIsFocused} from 'react-navigation-hooks'; import {useIsFocused} from 'react-navigation-hooks';
import {SIZE, WEIGHT} from '../../common/common'; import {SIZE, WEIGHT} from '../../common/common';
@@ -15,11 +15,17 @@ import {eMoveNoteDialogNavigateBack, eScrollEvent} from '../../services/events';
export const Notebook = ({navigation}) => { export const Notebook = ({navigation}) => {
const [state, dispatch] = useTracked(); const [state, dispatch] = useTracked();
const {colors, selectionMode, preventDefaultMargins} = state; const {colors, selectionMode, preventDefaultMargins} = state;
const [topics, setTopics] = useState([]);
const params = navigation.state.params; let params = navigation.state.params;
let isFocused = useIsFocused(); let isFocused = useIsFocused();
useEffect(() => {
let topic = params.notebook.topics;
setTopics([...topic]);
}, []);
const handleBackPress = () => { const handleBackPress = () => {
navigation.goBack(); navigation.goBack();
}; };
@@ -50,11 +56,11 @@ export const Notebook = ({navigation}) => {
item={item} item={item}
index={index} index={index}
colors={colors} colors={colors}
data={params.notebooks.topics} data={topics}
/> />
); );
ListFooterComponent = ( const ListFooterComponent = (
<View <View
style={{ style={{
height: 150, height: 150,
@@ -72,15 +78,15 @@ export const Notebook = ({navigation}) => {
</View> </View>
); );
ListHeaderComponent = ( const ListHeaderComponent = (
<View <View
style={{ style={{
marginTop: marginTop:
Platform.OS == 'ios' Platform.OS == 'ios'
? params.notebook.topics[0] && !selectionMode ? topics[0] && !selectionMode
? 135 ? 135
: 135 - 60 : 135 - 60
: params.notebook.topics[0] && !selectionMode : topics[0] && !selectionMode
? 155 ? 155
: 155 - 60, : 155 - 60,
}} }}
@@ -95,6 +101,7 @@ export const Notebook = ({navigation}) => {
placeholder={`Search in ${params.title}`} placeholder={`Search in ${params.title}`}
heading={params.title} heading={params.title}
canGoBack={true} canGoBack={true}
data={params.notebook.topics}
bottomButtonOnPress={() => { bottomButtonOnPress={() => {
//setAddTopic(true); //setAddTopic(true);
}}> }}>
@@ -102,7 +109,7 @@ export const Notebook = ({navigation}) => {
style={{ style={{
width: '100%', width: '100%',
}} }}
data={params.notebook.topics} data={topics}
onScroll={onScroll} onScroll={onScroll}
ListHeaderComponent={ListHeaderComponent} ListHeaderComponent={ListHeaderComponent}
ListFooterComponent={ListFooterComponent} ListFooterComponent={ListFooterComponent}

View File

@@ -1,12 +1,17 @@
import React, {useEffect, useState} from 'react'; import React, {useEffect, useState} from 'react';
import {FlatList, Text, View, Platform} from 'react-native';
import {db} from '../../../App'; import {db} from '../../../App';
import Container from '../../components/Container'; import Container from '../../components/Container';
import {NotesList} from '../../components/NotesList'; import NoteItem from '../../components/NoteItem';
import SelectionWrapper from '../../components/SelectionWrapper';
import {useTracked} from '../../provider'; import {useTracked} from '../../provider';
import {SIZE, WEIGHT} from '../../common/common';
import {ACTIONS} from '../../provider/actions';
export const Notes = ({navigation}) => { export const Notes = ({navigation}) => {
const [state, dispatch] = useTracked(); const [state, dispatch] = useTracked();
const {colors, selectionMode, currentEditingNote} = state;
const allNotes = state.notes;
const [notes, setNotes] = useState([]); const [notes, setNotes] = useState([]);
let params = navigation.state ? navigation.state.params : null; let params = navigation.state ? navigation.state.params : null;
@@ -14,17 +19,90 @@ export const Notes = ({navigation}) => {
useEffect(() => { useEffect(() => {
if (!params) { if (!params) {
params = { params = {
heading: 'Notes', title: 'Notes',
}; };
} }
}, []); }, []);
useEffect(() => { useEffect(() => {
let allNotes = db.getTopic(params.notebookID, params.title); if (params.type === 'tag') {
if (allNotes && allNotes.length > 0) { let notesInTag = db.getTag(params.tag.title);
setNotes(allNotes); setNotes([...notesInTag]);
} else {
let allNotes = db.getTopic(params.notebookID, params.title);
if (allNotes && allNotes.length > 0) {
setNotes(allNotes);
}
} }
}, []); }, [allNotes]);
const _renderItem = ({item, index}) => (
<SelectionWrapper
index={index}
currentEditingNote={
currentEditingNote === item.dateCreated ? currentEditingNote : null
}
item={item}>
<NoteItem
colors={colors}
customStyle={{
width: selectionMode ? '90%' : '100%',
marginHorizontal: 0,
}}
currentEditingNote={
currentEditingNote === item.dateCreated ? currentEditingNote : null
}
onLongPress={() => {
dispatch({type: ACTIONS.SELECTION_MODE, enabled: !selectionMode});
dispatch({type: ACTIONS.SELECTED_ITEMS, item: item});
}}
update={() => {}}
item={item}
index={index}
/>
</SelectionWrapper>
);
const _onScroll = event => {
if (!event) return;
let y = event.nativeEvent.contentOffset.y;
eSendEvent(eScrollEvent, y);
};
const _ListFooterComponent = notes[0] ? (
<View
style={{
height: 150,
alignItems: 'center',
justifyContent: 'center',
}}>
<Text
style={{
color: colors.navbg,
fontSize: SIZE.sm,
fontFamily: WEIGHT.regular,
}}>
- End -
</Text>
</View>
) : null;
const _ListHeaderComponent_S = (
<View
style={{
marginTop:
Platform.OS == 'ios'
? notes[0]
? 135
: 135 - 60
: notes[0]
? 155
: 155 - 60,
}}></View>
);
const _listKeyExtractor = (item, index) => item.dateCreated.toString();
return ( return (
<Container <Container
@@ -35,7 +113,22 @@ export const Notes = ({navigation}) => {
data={notes} data={notes}
placeholder={`Search in ${params.title}`} placeholder={`Search in ${params.title}`}
bottomButtonOnPress={() => {}}> bottomButtonOnPress={() => {}}>
<NotesList isSearch={false} notes={notes} keyword={null} /> <FlatList
data={notes}
keyExtractor={_listKeyExtractor}
ListFooterComponent={_ListFooterComponent}
onScroll={_onScroll}
ListHeaderComponent={_ListHeaderComponent_S}
contentContainerStyle={{
width: '100%',
alignSelf: 'center',
minHeight: '100%',
}}
style={{
height: '100%',
}}
renderItem={_renderItem}
/>
</Container> </Container>
); );
}; };

View File

@@ -1,11 +1,19 @@
import React, {useEffect} from 'react'; import React, {useEffect} from 'react';
import {Dimensions, FlatList, SafeAreaView, Text, View} from 'react-native'; import {
Dimensions,
FlatList,
SafeAreaView,
Text,
View,
TouchableOpacity,
} from 'react-native';
import {pv, SIZE, WEIGHT} from '../../common/common'; import {pv, SIZE, WEIGHT} from '../../common/common';
import {Header} from '../../components/header'; import {Header} from '../../components/header';
import {TagsPlaceHolder} from '../../components/ListPlaceholders'; import {TagsPlaceHolder} from '../../components/ListPlaceholders';
import {useTracked} from '../../provider'; import {useTracked} from '../../provider';
import {ACTIONS} from '../../provider/actions'; import {ACTIONS} from '../../provider/actions';
import {db} from '../../../App'; import {db} from '../../../App';
import NavigationService from '../../services/NavigationService';
const w = Dimensions.get('window').width; const w = Dimensions.get('window').width;
const h = Dimensions.get('window').height; const h = Dimensions.get('window').height;
@@ -69,7 +77,14 @@ export const Tags = ({navigation}) => {
</View> </View>
} }
renderItem={({item, index}) => ( renderItem={({item, index}) => (
<View <TouchableOpacity
onPress={() => {
NavigationService.navigate('Notes', {
type: 'tag',
title: item.title,
tag: item,
});
}}
style={{ style={{
flexDirection: 'row', flexDirection: 'row',
justifyContent: 'flex-start', justifyContent: 'flex-start',
@@ -101,7 +116,7 @@ export const Tags = ({navigation}) => {
{item.count} note {item.count} note
</Text> </Text>
</Text> </Text>
</View> </TouchableOpacity>
)} )}
/> />
</View> </View>