mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 23:19:40 +01:00
bug fixes
This commit is contained in:
@@ -81,22 +81,11 @@ export const ActionSheetComponent = ({
|
||||
if (tag.includes(' ')) {
|
||||
tag = tag.replace(' ', '_');
|
||||
}
|
||||
let oldProps = {...note};
|
||||
|
||||
if (oldProps.tags.includes(tag)) {
|
||||
return;
|
||||
} else {
|
||||
oldProps.tags.push(tag);
|
||||
}
|
||||
|
||||
tagsInputRef.setNativeProps({
|
||||
text: '',
|
||||
});
|
||||
|
||||
await db.addNote({
|
||||
dateCreated: note.dateCreated,
|
||||
tags: oldProps.tags,
|
||||
});
|
||||
await db.addTag(note.dateCreated, tag);
|
||||
setNote({...db.getNote(note.dateCreated)});
|
||||
tagToAdd = '';
|
||||
};
|
||||
@@ -114,13 +103,12 @@ export const ActionSheetComponent = ({
|
||||
let tagInputValue = note.tags[note.tags.length - 1];
|
||||
let oldProps = {...note};
|
||||
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)});
|
||||
|
||||
tagsInputRef.setNativeProps({
|
||||
@@ -262,9 +250,13 @@ export const ActionSheetComponent = ({
|
||||
icon: 'tag',
|
||||
func: async () => {
|
||||
if (!note.dateCreated) return;
|
||||
await db.pinItem(note.type, note.dateCreated);
|
||||
localRefresh(item.type);
|
||||
if (note.type === 'note') {
|
||||
await db.pinNote(note.dateCreated);
|
||||
} else {
|
||||
await db.pinNotebook(note.dateCreated);
|
||||
}
|
||||
dispatch({type: ACTIONS.PINNED});
|
||||
localRefresh(item.type);
|
||||
},
|
||||
close: false,
|
||||
check: true,
|
||||
@@ -275,9 +267,13 @@ export const ActionSheetComponent = ({
|
||||
icon: 'star',
|
||||
func: async () => {
|
||||
if (!note.dateCreated) return;
|
||||
await db.favoriteItem(note.type, note.dateCreated);
|
||||
localRefresh(item.type);
|
||||
if (note.type === 'note') {
|
||||
await db.favoriteNotes([note.dateCreated]);
|
||||
} else {
|
||||
await db.favoriteNotebooks([note.dateCreated]);
|
||||
}
|
||||
dispatch({type: ACTIONS.FAVORITES});
|
||||
localRefresh(item.type);
|
||||
},
|
||||
close: false,
|
||||
check: true,
|
||||
@@ -484,7 +480,10 @@ export const ActionSheetComponent = ({
|
||||
return (
|
||||
<View
|
||||
onLayout={() => {
|
||||
if (!item.dateDeleted) {
|
||||
localRefresh(item.type, true);
|
||||
}
|
||||
console.log(note.dateCreated, 'here');
|
||||
}}
|
||||
style={{
|
||||
paddingBottom: 15,
|
||||
|
||||
@@ -31,7 +31,6 @@ export class AddNotebookDialog extends React.Component {
|
||||
};
|
||||
this.title = null;
|
||||
this.description = null;
|
||||
|
||||
this.listRef;
|
||||
this.prevItem = null;
|
||||
this.prevIndex = null;
|
||||
@@ -123,6 +122,7 @@ export class AddNotebookDialog extends React.Component {
|
||||
};
|
||||
|
||||
onSubmit = () => {
|
||||
let {topics} = this.state;
|
||||
if (
|
||||
!this.currentInputValue ||
|
||||
this.currentInputValue === '' ||
|
||||
|
||||
@@ -74,10 +74,20 @@ export class Dialog extends Component {
|
||||
visible: false,
|
||||
});
|
||||
}
|
||||
case dialogActions.ACTION_TRASH: {
|
||||
db.restoreItem(item.dateCreated);
|
||||
updateEvent({type: ACTIONS.TRASH});
|
||||
this.hide();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_onClose = () => {
|
||||
let {template, item} = this.props;
|
||||
if (dialogActions.ACTION_TRASH === template.action) {
|
||||
// delete item forever.
|
||||
console.log('deleted forever');
|
||||
}
|
||||
this.setState({
|
||||
visible: false,
|
||||
});
|
||||
@@ -172,6 +182,27 @@ export class Dialog extends Component {
|
||||
flexDirection: 'row',
|
||||
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
|
||||
activeOpacity={opacity}
|
||||
onPress={this._onPress}
|
||||
@@ -195,28 +226,6 @@ export class Dialog extends Component {
|
||||
{positiveText}
|
||||
</Text>
|
||||
</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>
|
||||
|
||||
@@ -35,6 +35,7 @@ export const dialogActions = {
|
||||
ACTION_EXIT: 512,
|
||||
ACTION_EMPTY_TRASH: 513,
|
||||
ACTION_EXIT_FULLSCREEN: 514,
|
||||
ACTION_TRASH: 515,
|
||||
};
|
||||
|
||||
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 = () => {
|
||||
return {
|
||||
title: `Exit fullscreen editor?`,
|
||||
|
||||
@@ -159,7 +159,7 @@ class MoveNoteDialog extends React.Component {
|
||||
height: DDS.isTab ? '90%' : '100%',
|
||||
borderRadius: DDS.isTab ? 5 : 0,
|
||||
backgroundColor: colors.bg,
|
||||
padding: 8,
|
||||
padding: DDS.isTab ? 8 : 0,
|
||||
zIndex: 10,
|
||||
}}>
|
||||
<Navigator
|
||||
|
||||
@@ -11,9 +11,13 @@ import {DDS} from '../../../App';
|
||||
import {ph, pv, SIZE, WEIGHT} from '../../common/common';
|
||||
import NavigationService from '../../services/NavigationService';
|
||||
import {getElevation, timeSince} from '../../utils/utils';
|
||||
import {ActionSheetEvent} from '../DialogManager';
|
||||
import {
|
||||
ActionSheetEvent,
|
||||
TEMPLATE_TRASH,
|
||||
simpleDialogEvent,
|
||||
} from '../DialogManager';
|
||||
import {eSendEvent} from '../../services/eventManager';
|
||||
import {eOnLoadNote} from '../../services/events';
|
||||
import {eOnLoadNote, eOpenSimpleDialog} from '../../services/events';
|
||||
|
||||
const w = Dimensions.get('window').width;
|
||||
const h = Dimensions.get('window').height;
|
||||
@@ -117,6 +121,8 @@ export default class NoteItem extends React.Component {
|
||||
} else {
|
||||
DDS.isTab
|
||||
? eSendEvent(eOnLoadNote, item)
|
||||
: isTrash
|
||||
? simpleDialogEvent(TEMPLATE_TRASH(item.type))
|
||||
: NavigationService.navigate('Editor', {
|
||||
note: item,
|
||||
});
|
||||
@@ -267,10 +273,12 @@ export default class NoteItem extends React.Component {
|
||||
onPress={() => {
|
||||
ActionSheetEvent(
|
||||
item,
|
||||
true,
|
||||
true,
|
||||
['Add to', 'Share', 'Export', 'Delete'],
|
||||
['Add to Vault', 'Pin', 'Favorite'],
|
||||
isTrash ? false : true,
|
||||
isTrash ? false : true,
|
||||
isTrash
|
||||
? ['Remove', 'Restore']
|
||||
: ['Add to', 'Share', 'Export', 'Delete'],
|
||||
[],
|
||||
);
|
||||
}}>
|
||||
<Icon name="more-horizontal" size={SIZE.lg} color={colors.icon} />
|
||||
|
||||
@@ -23,7 +23,7 @@ export const NotebookItem = ({
|
||||
navigation,
|
||||
}) => {
|
||||
const [state, dispatch] = useTracked();
|
||||
const {colors} = state;
|
||||
const {colors, selectedItemsList} = state;
|
||||
|
||||
const navigate = () => {
|
||||
isTopic
|
||||
@@ -100,8 +100,9 @@ export const NotebookItem = ({
|
||||
flexDirection: 'row',
|
||||
alignItems: 'center',
|
||||
marginTop: 5,
|
||||
width: '80%',
|
||||
maxWidth: '80%',
|
||||
width: '95%',
|
||||
maxWidth: '95%',
|
||||
flexWrap: 'wrap',
|
||||
}}>
|
||||
{item && item.topics
|
||||
? item.topics.slice(1, 4).map(topic => (
|
||||
@@ -113,6 +114,7 @@ export const NotebookItem = ({
|
||||
paddingHorizontal: ph / 1.5,
|
||||
paddingVertical: pv / 4,
|
||||
marginRight: 10,
|
||||
marginVertical: 4,
|
||||
}}>
|
||||
<Text
|
||||
numberOfLines={1}
|
||||
@@ -233,6 +235,7 @@ export const NotebookItem = ({
|
||||
<TouchableOpacity
|
||||
activeOpacity={opacity}
|
||||
onPress={async () => {
|
||||
console.log(selectedItemsList, item);
|
||||
/* if (!noteToMove.notebook.notebook) {
|
||||
await db.addNoteToTopic(
|
||||
notebookID,
|
||||
@@ -247,7 +250,7 @@ export const NotebookItem = ({
|
||||
});
|
||||
} */
|
||||
|
||||
moveNoteHideEvent();
|
||||
// moveNoteHideEvent();
|
||||
|
||||
ToastEvent.show(
|
||||
`Note moved to ${item.title}`,
|
||||
|
||||
@@ -34,6 +34,7 @@ export const Folders = ({navigation}) => {
|
||||
|
||||
useEffect(() => {
|
||||
dispatch({type: ACTIONS.NOTEBOOKS});
|
||||
console.log(notebooks);
|
||||
let backhandler;
|
||||
if (isFocused) {
|
||||
backhandler = BackHandler.addEventListener(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, {useEffect} from 'react';
|
||||
import React, {useEffect, useState} from 'react';
|
||||
import {FlatList, Platform, Text, View} from 'react-native';
|
||||
import {useIsFocused} from 'react-navigation-hooks';
|
||||
import {SIZE, WEIGHT} from '../../common/common';
|
||||
@@ -15,11 +15,17 @@ import {eMoveNoteDialogNavigateBack, eScrollEvent} from '../../services/events';
|
||||
export const Notebook = ({navigation}) => {
|
||||
const [state, dispatch] = useTracked();
|
||||
const {colors, selectionMode, preventDefaultMargins} = state;
|
||||
|
||||
const params = navigation.state.params;
|
||||
const [topics, setTopics] = useState([]);
|
||||
let params = navigation.state.params;
|
||||
|
||||
let isFocused = useIsFocused();
|
||||
|
||||
useEffect(() => {
|
||||
let topic = params.notebook.topics;
|
||||
|
||||
setTopics([...topic]);
|
||||
}, []);
|
||||
|
||||
const handleBackPress = () => {
|
||||
navigation.goBack();
|
||||
};
|
||||
@@ -50,11 +56,11 @@ export const Notebook = ({navigation}) => {
|
||||
item={item}
|
||||
index={index}
|
||||
colors={colors}
|
||||
data={params.notebooks.topics}
|
||||
data={topics}
|
||||
/>
|
||||
);
|
||||
|
||||
ListFooterComponent = (
|
||||
const ListFooterComponent = (
|
||||
<View
|
||||
style={{
|
||||
height: 150,
|
||||
@@ -72,15 +78,15 @@ export const Notebook = ({navigation}) => {
|
||||
</View>
|
||||
);
|
||||
|
||||
ListHeaderComponent = (
|
||||
const ListHeaderComponent = (
|
||||
<View
|
||||
style={{
|
||||
marginTop:
|
||||
Platform.OS == 'ios'
|
||||
? params.notebook.topics[0] && !selectionMode
|
||||
? topics[0] && !selectionMode
|
||||
? 135
|
||||
: 135 - 60
|
||||
: params.notebook.topics[0] && !selectionMode
|
||||
: topics[0] && !selectionMode
|
||||
? 155
|
||||
: 155 - 60,
|
||||
}}
|
||||
@@ -95,6 +101,7 @@ export const Notebook = ({navigation}) => {
|
||||
placeholder={`Search in ${params.title}`}
|
||||
heading={params.title}
|
||||
canGoBack={true}
|
||||
data={params.notebook.topics}
|
||||
bottomButtonOnPress={() => {
|
||||
//setAddTopic(true);
|
||||
}}>
|
||||
@@ -102,7 +109,7 @@ export const Notebook = ({navigation}) => {
|
||||
style={{
|
||||
width: '100%',
|
||||
}}
|
||||
data={params.notebook.topics}
|
||||
data={topics}
|
||||
onScroll={onScroll}
|
||||
ListHeaderComponent={ListHeaderComponent}
|
||||
ListFooterComponent={ListFooterComponent}
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
import React, {useEffect, useState} from 'react';
|
||||
import {FlatList, Text, View, Platform} from 'react-native';
|
||||
import {db} from '../../../App';
|
||||
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 {SIZE, WEIGHT} from '../../common/common';
|
||||
import {ACTIONS} from '../../provider/actions';
|
||||
|
||||
export const Notes = ({navigation}) => {
|
||||
const [state, dispatch] = useTracked();
|
||||
|
||||
const {colors, selectionMode, currentEditingNote} = state;
|
||||
const allNotes = state.notes;
|
||||
const [notes, setNotes] = useState([]);
|
||||
|
||||
let params = navigation.state ? navigation.state.params : null;
|
||||
@@ -14,17 +19,90 @@ export const Notes = ({navigation}) => {
|
||||
useEffect(() => {
|
||||
if (!params) {
|
||||
params = {
|
||||
heading: 'Notes',
|
||||
title: 'Notes',
|
||||
};
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (params.type === 'tag') {
|
||||
let notesInTag = db.getTag(params.tag.title);
|
||||
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 (
|
||||
<Container
|
||||
@@ -35,7 +113,22 @@ export const Notes = ({navigation}) => {
|
||||
data={notes}
|
||||
placeholder={`Search in ${params.title}`}
|
||||
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>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,11 +1,19 @@
|
||||
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 {Header} from '../../components/header';
|
||||
import {TagsPlaceHolder} from '../../components/ListPlaceholders';
|
||||
import {useTracked} from '../../provider';
|
||||
import {ACTIONS} from '../../provider/actions';
|
||||
import {db} from '../../../App';
|
||||
import NavigationService from '../../services/NavigationService';
|
||||
const w = Dimensions.get('window').width;
|
||||
const h = Dimensions.get('window').height;
|
||||
|
||||
@@ -69,7 +77,14 @@ export const Tags = ({navigation}) => {
|
||||
</View>
|
||||
}
|
||||
renderItem={({item, index}) => (
|
||||
<View
|
||||
<TouchableOpacity
|
||||
onPress={() => {
|
||||
NavigationService.navigate('Notes', {
|
||||
type: 'tag',
|
||||
title: item.title,
|
||||
tag: item,
|
||||
});
|
||||
}}
|
||||
style={{
|
||||
flexDirection: 'row',
|
||||
justifyContent: 'flex-start',
|
||||
@@ -101,7 +116,7 @@ export const Tags = ({navigation}) => {
|
||||
{item.count} note
|
||||
</Text>
|
||||
</Text>
|
||||
</View>
|
||||
</TouchableOpacity>
|
||||
)}
|
||||
/>
|
||||
</View>
|
||||
|
||||
Reference in New Issue
Block a user