add new database api

This commit is contained in:
ammarahm-ed
2020-02-06 13:08:35 +05:00
parent 2e59886d26
commit 9f7319b6bb
20 changed files with 146 additions and 155 deletions

View File

@@ -1,4 +1,4 @@
import Storage from 'notes-core/api/database'; import Storage from 'notes-core/api/index';
import React, {useEffect, useState} from 'react'; import React, {useEffect, useState} from 'react';
import {Platform, StatusBar, View, Text} from 'react-native'; import {Platform, StatusBar, View, Text} from 'react-native';
import * as Animatable from 'react-native-animatable'; import * as Animatable from 'react-native-animatable';

View File

@@ -1207,6 +1207,8 @@
document.getElementById('titleInput').onchange = function () { document.getElementById('titleInput').onchange = function () {
editor.focus(); editor.focus();
console.log(JSON.stringify(editor.getContents()));
var titleMessage = { var titleMessage = {
type: 'title', type: 'title',
value: document.getElementById('titleInput').value value: document.getElementById('titleInput').value
@@ -1625,9 +1627,12 @@
let m = {}; let m = {};
m.delta = editor.getContents(); m.delta = editor.getContents();
m.text = editor.getText(); m.text = editor.getText();
m.html = editor.root.innerHTML; m.html = editor.root.innerHTML;
m.type = 'content'; m.type = 'content';
window.ReactNativeWebView.postMessage(JSON.stringify(m)); window.ReactNativeWebView.postMessage(JSON.stringify(m));
}); });

View File

@@ -87,8 +87,10 @@ export const ActionSheetComponent = ({
text: '', text: '',
}); });
await db.addTag(note.dateCreated, tag); await db.notes.note(note.id).tag(tag);
setNote({...db.getNote(note.dateCreated)});
setNote({...db.notes.note(note.id).data});
tagToAdd = ''; tagToAdd = '';
}; };
@@ -106,12 +108,11 @@ export const ActionSheetComponent = ({
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); //oldProps.tags.splice(oldProps.tags.length - 1);
await db.removeTag( await db.notes
note.dateCreated, .note(note.id)
oldProps.tags[oldProps.tags.length - 1], .untag(oldProps.tags[oldProps.tags.length - 1]);
);
setNote({...db.getNote(note.dateCreated)}); setNote({...db.notes.note(note.id).data});
tagsInputRef.setNativeProps({ tagsInputRef.setNativeProps({
text: tagInputValue, text: tagInputValue,
@@ -125,25 +126,25 @@ export const ActionSheetComponent = ({
}; };
const localRefresh = (type, nodispatch = false) => { const localRefresh = (type, nodispatch = false) => {
if (!note || !note.dateCreated) return; if (!note || !note.id) return;
let toAdd; let toAdd;
switch (type) { switch (type) {
case 'note': { case 'note': {
toAdd = db.getNote(note.dateCreated); toAdd = db.notes.note(note.id).data;
break; break;
} }
case 'notebook': { case 'notebook': {
toAdd = db.getNotebook(note.dateCreated); toAdd = db.notebooks.notebook(note.id).data;
break; break;
} }
case 'topic': { case 'topic': {
toAdd = db.getTopic(note.notebookId, note.title); toAdd = db.notebooks.notebook(note.notebookId).topics.topic(note.title);
break; break;
} }
} }
if (!toAdd || !toAdd.dateCreated) return; if (!toAdd || !toAdd.id) return;
if (!nodispatch) { if (!nodispatch) {
dispatch({type: type}); dispatch({type: type});
@@ -258,11 +259,11 @@ export const ActionSheetComponent = ({
name: 'Pin', name: 'Pin',
icon: 'tag', icon: 'tag',
func: async () => { func: async () => {
if (!note.dateCreated) return; if (!note.id) return;
if (note.type === 'note') { if (note.type === 'note') {
await db.pinNote(note.dateCreated); await db.notes.note(note.id).pin();
} else { } else {
await db.pinNotebook(note.dateCreated); await db.notebooks.notebook(note.id).pin();
} }
dispatch({type: ACTIONS.PINNED}); dispatch({type: ACTIONS.PINNED});
localRefresh(item.type); localRefresh(item.type);
@@ -275,11 +276,11 @@ export const ActionSheetComponent = ({
name: 'Favorite', name: 'Favorite',
icon: 'star', icon: 'star',
func: async () => { func: async () => {
if (!note.dateCreated) return; if (!note.id) return;
if (note.type === 'note') { if (note.type === 'note') {
await db.favoriteNotes([note.dateCreated]); await db.notes.note(note.id).favorite();
} else { } else {
await db.favoriteNotebooks([note.dateCreated]); await db.notebooks.notebook(note.id).favorite();
} }
dispatch({type: ACTIONS.FAVORITES}); dispatch({type: ACTIONS.FAVORITES});
localRefresh(item.type); localRefresh(item.type);
@@ -292,7 +293,7 @@ export const ActionSheetComponent = ({
name: 'Add to Vault', name: 'Add to Vault',
icon: 'lock', icon: 'lock',
func: () => { func: () => {
if (!note.dateCreated) return; if (!note.id) return;
note.locked ? close('unlock') : close('lock'); note.locked ? close('unlock') : close('lock');
}, },
close: true, close: true,
@@ -307,11 +308,7 @@ export const ActionSheetComponent = ({
onPress={async () => { onPress={async () => {
let oldProps = {...note}; let oldProps = {...note};
oldProps.tags.splice(oldProps.tags.indexOf(tag), 1); await db.notes.note(note.id).untag(oldProps.tags.indexOf(tag));
await db.addNote({
dateCreated: note.dateCreated,
tags: oldProps.tags,
});
localRefresh(item.type); localRefresh(item.type);
}} }}
style={{ style={{
@@ -350,13 +347,13 @@ export const ActionSheetComponent = ({
} else { } else {
noteColors.push(color); noteColors.push(color);
} }
// TODO
db.addNote({ /* db.addNote({
dateCreated: note.dateCreated, dateCreated: note.dateCreated,
colors: noteColors, colors: noteColors,
content: note.content, content: note.content,
title: note.title, title: note.title,
}); }); */
localRefresh(item.type); localRefresh(item.type);
}} }}
style={{ style={{
@@ -418,7 +415,7 @@ export const ActionSheetComponent = ({
) : null; ) : null;
const _renderColumnItem = item => const _renderColumnItem = item =>
(note.dateCreated && columnItems.includes(item.name)) || (note.id && columnItems.includes(item.name)) ||
(item.name === 'Dark Mode' && columnItems.includes(item.name)) ? ( (item.name === 'Dark Mode' && columnItems.includes(item.name)) ? (
<TouchableOpacity <TouchableOpacity
key={item.name} key={item.name}
@@ -499,7 +496,7 @@ export const ActionSheetComponent = ({
width: '100%', width: '100%',
paddingHorizontal: 0, paddingHorizontal: 0,
}}> }}>
{!note.dateCreated ? ( {!note.id ? (
<Text <Text
style={{ style={{
width: '100%', width: '100%',
@@ -556,7 +553,7 @@ export const ActionSheetComponent = ({
marginTop: 2.5, marginTop: 2.5,
}}> }}>
{note.type === 'note' {note.type === 'note'
? 'Last edited on ' + timeConverter(note.dateEditted) ? 'Last edited on ' + timeConverter(note.dateEdited)
: null} : null}
{note.type !== 'note' && !note.dateDeleted {note.type !== 'note' && !note.dateDeleted
? 'Created on ' + timeConverter(note.dateCreated) ? 'Created on ' + timeConverter(note.dateCreated)
@@ -624,7 +621,7 @@ export const ActionSheetComponent = ({
</View> </View>
)} )}
{note.dateCreated ? ( {note.id ? (
<View <View
style={{ style={{
width: '100%', width: '100%',
@@ -638,7 +635,7 @@ export const ActionSheetComponent = ({
</View> </View>
) : null} ) : null}
{hasColors && note.dateCreated ? ( {hasColors && note.id ? (
<View <View
style={{ style={{
flexDirection: 'row', flexDirection: 'row',
@@ -655,7 +652,7 @@ export const ActionSheetComponent = ({
</View> </View>
) : null} ) : null}
{hasTags && note.dateCreated ? ( {hasTags && note.id ? (
<View <View
style={{ style={{
marginHorizontal: 12, marginHorizontal: 12,

View File

@@ -35,7 +35,7 @@ export class AddNotebookDialog extends React.Component {
this.prevItem = null; this.prevItem = null;
this.prevIndex = null; this.prevIndex = null;
this.currentSelectedInput = null; this.currentSelectedInput = null;
this.timestamp = null; this.id = null;
this.backPressCount = 0; this.backPressCount = 0;
this.currentInputValue = null; this.currentInputValue = null;
this.titleRef; this.titleRef;
@@ -53,7 +53,7 @@ export class AddNotebookDialog extends React.Component {
topicsList.push(item.title); topicsList.push(item.title);
} }
}); });
this.timestamp = toEdit.dateCreated; this.id = toEdit.id;
this.title = toEdit.title; this.title = toEdit.title;
this.description = toEdit.description; this.description = toEdit.description;
@@ -76,7 +76,7 @@ export class AddNotebookDialog extends React.Component {
this.currentSelectedInput = null; this.currentSelectedInput = null;
this.title = null; this.title = null;
this.description = null; this.description = null;
this.timestamp = null; this.id = null;
this.setState({ this.setState({
visible: false, visible: false,
topics: [], topics: [],
@@ -110,14 +110,16 @@ export class AddNotebookDialog extends React.Component {
if (!this.title) if (!this.title)
return ToastEvent.show('Title is required', 'error', 3000, () => {}, ''); return ToastEvent.show('Title is required', 'error', 3000, () => {}, '');
let dateCreated = toEdit && toEdit.dateCreated ? toEdit.dateCreated : null; let id = toEdit && toEdit.id ? toEdit.id : null;
await db.addNotebook({ // TODO
await db.notebooks.add({
title: this.title, title: this.title,
description: this.description, description: this.description,
topics, topics,
dateCreated: dateCreated, id: id,
}); });
updateEvent({type: ACTIONS.NOTEBOOKS}); updateEvent({type: ACTIONS.NOTEBOOKS});
this.close(); this.close();
ToastEvent.show('New notebook added', 'success', 3000, () => {}, ''); ToastEvent.show('New notebook added', 'success', 3000, () => {}, '');

View File

@@ -24,7 +24,8 @@ export class AddTopicDialog extends React.Component {
if (!this.title) if (!this.title)
return ToastEvent.show('Title is required', 'error', 3000, () => {}, ''); return ToastEvent.show('Title is required', 'error', 3000, () => {}, '');
db.addTopicToNotebook(this.props.notebookID, this.title); await db.notebooks.notebook(this.props.notebookID).topics.add(this.title);
eSendEvent(eOnNewTopicAdded); eSendEvent(eOnNewTopicAdded);
ToastEvent.show('New topic added', 'success', 3000, () => {}, ''); ToastEvent.show('New topic added', 'success', 3000, () => {}, '');
this.close(); this.close();

View File

@@ -30,16 +30,18 @@ export class Dialog extends Component {
switch (template.action) { switch (template.action) {
case dialogActions.ACTION_DELETE: { case dialogActions.ACTION_DELETE: {
if (item.type === 'note') { if (item.type === 'note') {
await db.deleteNotes(item.dateCreated); await db.notes.delete(item.id);
ToastEvent.show('Note moved to trash', 'error', 3000); ToastEvent.show('Note moved to trash', 'error', 3000);
updateEvent({type: item.type}); updateEvent({type: item.type});
} else if (item.type === 'topic') { } else if (item.type === 'topic') {
await db.deleteTopicFromNotebook(notebookID, item.title); //TODO
//db.notebooks.notebook(notebookID).topic
//await db.deleteTopicFromNotebook(notebookID, item.title);
updateEvent({type: 'notebook'}); updateEvent({type: 'notebook'});
ToastEvent.show('Topic deleted', 'error', 3000); ToastEvent.show('Topic deleted', 'error', 3000);
} else if (item.type === 'notebook') { } else if (item.type === 'notebook') {
await db.deleteNotebooks(item.dateCreated); await db.notebooks.delete(item.id);
updateEvent({type: item.type}); updateEvent({type: item.type});
ToastEvent.show('Notebook moved to trash', 'error', 3000); ToastEvent.show('Notebook moved to trash', 'error', 3000);
} }
@@ -58,7 +60,9 @@ export class Dialog extends Component {
break; break;
} }
case dialogActions.ACTION_EMPTY_TRASH: { case dialogActions.ACTION_EMPTY_TRASH: {
await db.clearTrash(); // TODO
//await db.clearTrash();
updateEvent({type: ACTIONS.TRASH}); updateEvent({type: ACTIONS.TRASH});
ToastEvent.show('Trash cleared', 'error', 1000, () => {}, ''); ToastEvent.show('Trash cleared', 'error', 1000, () => {}, '');
this.setState({ this.setState({
@@ -75,7 +79,8 @@ export class Dialog extends Component {
}); });
} }
case dialogActions.ACTION_TRASH: { case dialogActions.ACTION_TRASH: {
db.restoreItem(item.dateCreated); // TODO
//db.restoreItem(item.dateCreated);
ToastEvent.show( ToastEvent.show(
item.type.slice(0, 1).toUpperCase() + item.type.slice(0, 1).toUpperCase() +
item.type.slice(1) + item.type.slice(1) +

View File

@@ -456,7 +456,7 @@ export class DialogManager extends Component {
notebookID={ notebookID={
actionSheetData.extraData actionSheetData.extraData
? actionSheetData.extraData.notebookID ? actionSheetData.extraData.notebookID
: item.dateCreated : item.id
} }
colors={colors} colors={colors}
/> />

View File

@@ -1,23 +1,17 @@
import React from 'react'; import React from 'react';
import { import {Dimensions, Text, TouchableOpacity, View} from 'react-native';
Dimensions,
Text,
TouchableOpacity,
View,
DeviceEventEmitter,
} from 'react-native';
import Icon from 'react-native-vector-icons/Feather'; import Icon from 'react-native-vector-icons/Feather';
import {DDS} from '../../../App'; import {DDS} from '../../../App';
import {ph, pv, SIZE, WEIGHT} from '../../common/common'; import {ph, pv, SIZE, WEIGHT} from '../../common/common';
import {eSendEvent} from '../../services/eventManager';
import {eOnLoadNote} from '../../services/events';
import NavigationService from '../../services/NavigationService'; import NavigationService from '../../services/NavigationService';
import {getElevation, timeSince} from '../../utils/utils'; import {getElevation, timeSince} from '../../utils/utils';
import { import {
ActionSheetEvent, ActionSheetEvent,
TEMPLATE_TRASH,
simpleDialogEvent, simpleDialogEvent,
TEMPLATE_TRASH,
} from '../DialogManager'; } from '../DialogManager';
import {eSendEvent} from '../../services/eventManager';
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;
@@ -66,7 +60,7 @@ export default class NoteItem extends React.Component {
pinned, pinned,
index, index,
} = this.props; } = this.props;
console.log('rerendering', index, item.content.text.length);
return ( return (
<View <View
style={[ style={[

View File

@@ -241,30 +241,16 @@ export const NotebookItem = ({
<TouchableOpacity <TouchableOpacity
activeOpacity={opacity} activeOpacity={opacity}
onPress={async () => { onPress={async () => {
/* let noteIds = []; let noteIds = [];
selectedItemsList.forEach(item => noteIds.push(item.dateCreated)); selectedItemsList.forEach(item => noteIds.push(item.id));
if (!noteToMove.notebook.notebook) {
await db.moveNotes(null, { db.notes.move(
{
topic: item.title, topic: item.title,
id: item.notebookId, id: item.notebookID,
}); },
await db.addNoteToTopic( noteIds,
notebookID,
item.title,
noteToMove.dateCreated,
); );
} else if (selectedItemsList) {
await db.moveNotes(null, {
topic: item.title,
id: item.notebookId,
});
await db.moveNote(noteToMove.dateCreated, noteToMove.notebook, {
notebook: notebookID,
topic: item.title,
});
}*/
moveNoteHideEvent(); moveNoteHideEvent();

View File

@@ -34,7 +34,7 @@ export const NotesList = ({isGrouped = false}) => {
<SelectionWrapper <SelectionWrapper
index={index} index={index}
currentEditingNote={ currentEditingNote={
currentEditingNote === item.dateCreated ? currentEditingNote : null currentEditingNote === item.id ? currentEditingNote : null
} }
item={item}> item={item}>
<NoteItem <NoteItem
@@ -44,7 +44,7 @@ export const NotesList = ({isGrouped = false}) => {
marginHorizontal: 0, marginHorizontal: 0,
}} }}
currentEditingNote={ currentEditingNote={
currentEditingNote === item.dateCreated ? currentEditingNote : null currentEditingNote === item.id ? currentEditingNote : null
} }
onLongPress={() => { onLongPress={() => {
dispatch({type: ACTIONS.SELECTION_MODE, enabled: !selectionMode}); dispatch({type: ACTIONS.SELECTION_MODE, enabled: !selectionMode});
@@ -167,7 +167,7 @@ export const NotesList = ({isGrouped = false}) => {
}}></View> }}></View>
); );
const _listKeyExtractor = (item, index) => item.dateCreated.toString(); const _listKeyExtractor = (item, index) => item.id.toString();
return isGrouped && searchResults.length === 0 ? ( return isGrouped && searchResults.length === 0 ? (
<SectionList <SectionList
@@ -237,7 +237,7 @@ const PinnedItems = () => {
<> <>
<FlatList <FlatList
data={pinned} data={pinned}
keyExtractor={(item, index) => item.dateCreated.toString()} keyExtractor={(item, index) => item.id.toString()}
renderItem={({item, index}) => renderItem={({item, index}) =>
item.type === 'note' ? ( item.type === 'note' ? (
<NoteItem <NoteItem

View File

@@ -1,6 +1,5 @@
import React, {useEffect, useState} from 'react'; import React, {useEffect, useState} from 'react';
import {TouchableWithoutFeedback, View} from 'react-native'; import {TouchableWithoutFeedback, View} from 'react-native';
import * as Animatable from 'react-native-animatable';
import Icon from 'react-native-vector-icons/Feather'; import Icon from 'react-native-vector-icons/Feather';
import {SIZE} from '../../common/common'; import {SIZE} from '../../common/common';
import {useTracked} from '../../provider'; import {useTracked} from '../../provider';
@@ -26,11 +25,7 @@ const SelectionWrapper = ({children, item, currentEditingNote, index}) => {
}, [selectedItemsList]); }, [selectedItemsList]);
return ( return (
<Animatable.View <View
animation="fadeIn"
useNativeDriver={true}
duration={300 * index + 1}
delay={index * 300}
style={{ style={{
flexDirection: 'row', flexDirection: 'row',
justifyContent: 'space-between', justifyContent: 'space-between',
@@ -78,7 +73,7 @@ const SelectionWrapper = ({children, item, currentEditingNote, index}) => {
</TouchableWithoutFeedback> </TouchableWithoutFeedback>
</View> </View>
{children} {children}
</Animatable.View> </View>
); );
}; };

View File

@@ -50,7 +50,7 @@ export class VaultDialog extends Component {
let item; let item;
if (n.content.cipher) { if (n.content.cipher) {
try { try {
item = await db.unlockNote(n.dateCreated, password, this.props.perm); item = await db.notes.note(n.id).unlock(password, this.props.perm);
} catch (error) {} } catch (error) {}
} else { } else {
item = n; item = n;
@@ -63,7 +63,7 @@ export class VaultDialog extends Component {
this.close(this.props.shareAfterUnlock, item); this.close(this.props.shareAfterUnlock, item);
} else { } else {
await db.lockNote(this.props.note.dateCreated, 'password'); await db.notes.note(this.props.note.id).lock('password');
this.close(); this.close();
} }
}; };

View File

@@ -5,7 +5,8 @@ import {ACTIONS} from './actions';
export const reducer = (state, action) => { export const reducer = (state, action) => {
switch (action.type) { switch (action.type) {
case ACTIONS.NOTES: case ACTIONS.NOTES:
let notes = db.groupNotes(); let notes = db.notes.group();
return { return {
...state, ...state,
notes: [...notes], notes: [...notes],
@@ -18,36 +19,36 @@ export const reducer = (state, action) => {
}; };
} }
case ACTIONS.NOTEBOOKS: { case ACTIONS.NOTEBOOKS: {
let notebooks = [...db.getNotebooks()]; let notebooks = [...db.notebooks.all];
return { return {
...state, ...state,
notebooks: notebooks, notebooks: notebooks,
}; };
} }
case ACTIONS.TRASH: { case ACTIONS.TRASH: {
let trash = [...db.getTrash()]; let trash = [];
// TODO
return { return {
...state, ...state,
trash: trash, trash: trash,
}; };
} }
case ACTIONS.PINNED: { case ACTIONS.PINNED: {
let pinned = [...db.getPinned()]; let pinned = [...db.notes.pinned];
return { return {
...state, ...state,
pinned: pinned, pinned: pinned,
}; };
} }
case ACTIONS.TAGS: { case ACTIONS.TAGS: {
let tagList = db.getTags(); let tagList = db.notes.tags;
return { return {
...state, ...state,
tags: [...tagList], tags: [...tagList],
}; };
} }
case ACTIONS.FAVORITES: { case ACTIONS.FAVORITES: {
let favorites = [...db.getFavorites()]; let favorites = [...db.notes.favorites];
return { return {
...state, ...state,
@@ -74,7 +75,7 @@ export const reducer = (state, action) => {
} else { } else {
selectedItems.push(action.item); selectedItems.push(action.item);
} }
console.log(action.item, selectedItems);
return { return {
...state, ...state,
selectedItemsList: selectedItems, selectedItemsList: selectedItems,
@@ -101,7 +102,7 @@ export const reducer = (state, action) => {
case ACTIONS.CURRENT_EDITING_NOTE: { case ACTIONS.CURRENT_EDITING_NOTE: {
return { return {
...state, ...state,
currentEditingNote: action.dateCreated, currentEditingNote: action.id,
}; };
} }
default: default:

View File

@@ -3,11 +3,13 @@ import FastStorage from 'react-native-fast-storage';
var Aes = NativeModules.Aes; var Aes = NativeModules.Aes;
async function read(key) { async function read(key) {
return await FastStorage.getItem(key); let json = await FastStorage.getItem(key);
return JSON.parse(json);
} }
async function write(key, data) { async function write(key, data) {
return await FastStorage.setItem(key, data); let json = JSON.stringify(data);
return await FastStorage.setItem(key, json);
} }
function remove(key) { function remove(key) {

View File

@@ -39,7 +39,7 @@ import {AnimatedSafeAreaView} from '../Home';
let EditorWebView; let EditorWebView;
let note = {}; let note = {};
let timestamp = null; let id = null;
let dateEdited = null; let dateEdited = null;
var content = null; var content = null;
var title = null; var title = null;
@@ -65,7 +65,7 @@ const Editor = ({navigation, noMenu}) => {
}, []); }, []);
const loadNote = item => { const loadNote = item => {
if (note && note.dateCreated) { if (note && note.id) {
saveNote(true).then(() => { saveNote(true).then(() => {
dispatch({type: ACTIONS.NOTES}); dispatch({type: ACTIONS.NOTES});
if (item && item.type === 'new') { if (item && item.type === 'new') {
@@ -75,7 +75,7 @@ const Editor = ({navigation, noMenu}) => {
if (DDS.isTab) { if (DDS.isTab) {
dispatch({ dispatch({
type: ACTIONS.CURRENT_EDITING_NOTE, type: ACTIONS.CURRENT_EDITING_NOTE,
dateCreated: item.dateCreated, id: item.id,
}); });
} }
@@ -91,7 +91,7 @@ const Editor = ({navigation, noMenu}) => {
if (DDS.isTab) { if (DDS.isTab) {
dispatch({ dispatch({
type: ACTIONS.CURRENT_EDITING_NOTE, type: ACTIONS.CURRENT_EDITING_NOTE,
dateCreated: item.dateCreated, id: item.id,
}); });
} }
updateEditor(); updateEditor();
@@ -100,7 +100,7 @@ const Editor = ({navigation, noMenu}) => {
}; };
const clearEditor = () => { const clearEditor = () => {
timestamp = null; id = null;
title = null; title = null;
content = null; content = null;
note = {}; note = {};
@@ -163,24 +163,24 @@ const Editor = ({navigation, noMenu}) => {
}; };
} }
let dateCreated = await db.addNote({ let rId = await db.notes.add({
title, title,
content: { content: {
text: content.text, text: content.text,
delta: content.delta, delta: content.delta,
}, },
dateCreated: timestamp, id: id,
}); });
if (timestamp !== dateCreated) { if (id !== rId) {
timestamp = dateCreated; id = rId;
note = db.getNote(timestamp); note = db.notes.note(id);
if (DDS.isTab) { if (DDS.isTab) {
dispatch({ dispatch({
type: ACTIONS.CURRENT_EDITING_NOTE, type: ACTIONS.CURRENT_EDITING_NOTE,
dateCreated: timestamp, id: id,
}); });
} }
} }
@@ -191,10 +191,11 @@ const Editor = ({navigation, noMenu}) => {
}); });
} }
saveCounter++; saveCounter++;
if (timestamp) { if (id) {
let lockednote = db.getNote(timestamp); let lockednote = db.notes.note(id);
if (lockNote && lockednote.locked) { if (lockNote && lockednote.locked) {
await db.lockNote(timestamp, 'password'); // TODO
await db.notes.note(id).lock('password');
} }
} }
}; };
@@ -238,7 +239,7 @@ const Editor = ({navigation, noMenu}) => {
if (navigation && navigation.state.params && navigation.state.params.note) { if (navigation && navigation.state.params && navigation.state.params.note) {
note = navigation.state.params.note; note = navigation.state.params.note;
updateEditor(); updateEditor();
} else if (note && note.dateCreated) { } else if (note && note.id) {
updateEditor(); updateEditor();
} else { } else {
post('focusTitle'); post('focusTitle');
@@ -258,9 +259,9 @@ const Editor = ({navigation, noMenu}) => {
}, timeout); }, timeout);
}); });
const updateEditor = () => { const updateEditor = async () => {
title = note.title; title = note.title;
timestamp = note.dateCreated; id = note.id;
dateEdited = note.dateEditted; dateEdited = note.dateEditted;
content = note.content; content = note.content;
saveCounter = 0; saveCounter = 0;
@@ -279,7 +280,9 @@ const Editor = ({navigation, noMenu}) => {
if (note.content.text === '' && note.content.delta === null) { if (note.content.text === '' && note.content.delta === null) {
post('clear'); post('clear');
} else if (note.content.delta) { } else if (note.content.delta) {
post(JSON.stringify(note.content.delta)); let delta = await db.notes.note(id).delta();
post(JSON.stringify(delta));
} else { } else {
post(JSON.stringify({type: 'text', value: note.content.text})); post(JSON.stringify({type: 'text', value: note.content.text}));
} }
@@ -420,7 +423,7 @@ const Editor = ({navigation, noMenu}) => {
}}> }}>
<Text <Text
onPress={() => { onPress={() => {
simpleDialogEvent(TEMPLATE_INFO(timestamp)); simpleDialogEvent(TEMPLATE_INFO(note.dateCreated));
}} }}
style={{ style={{
color: colors.icon, color: colors.icon,
@@ -505,7 +508,7 @@ const Editor = ({navigation, noMenu}) => {
} }
title = null; title = null;
content = null; content = null;
timestamp = null; id = null;
timer = null; timer = null;
}; };
}, [noMenu]); }, [noMenu]);

View File

@@ -120,7 +120,7 @@ export const Folders = ({navigation}) => {
<> <>
<FlatList <FlatList
data={pinned} data={pinned}
keyExtractor={(item, index) => item.dateCreated.toString()} keyExtractor={(item, index) => item.id.toString()}
renderItem={({item, index}) => renderItem={({item, index}) =>
item.type === 'notebook' ? ( item.type === 'notebook' ? (
<SelectionWrapper item={item}> <SelectionWrapper item={item}>
@@ -213,7 +213,7 @@ export const Folders = ({navigation}) => {
</View> </View>
} }
data={notebooks} data={notebooks}
keyExtractor={(item, index) => item.dateCreated.toString()} keyExtractor={(item, index) => item.id.toString()}
renderItem={({item, index}) => ( renderItem={({item, index}) => (
<SelectionWrapper item={item}> <SelectionWrapper item={item}>
<NotebookItem <NotebookItem

View File

@@ -11,7 +11,7 @@ import {ACTIONS} from '../../provider/actions';
import {eSendEvent} from '../../services/eventManager'; import {eSendEvent} from '../../services/eventManager';
import NavigationService from '../../services/NavigationService'; import NavigationService from '../../services/NavigationService';
import {SideMenuEvent} from '../../utils/utils'; import {SideMenuEvent} from '../../utils/utils';
let count = 0;
export const AnimatedSafeAreaView = Animatable.createAnimatableComponent( export const AnimatedSafeAreaView = Animatable.createAnimatableComponent(
SafeAreaView, SafeAreaView,
); );

View File

@@ -1,9 +1,12 @@
import React, {useEffect, useState} from 'react'; import React, {useEffect, useState} from 'react';
import {FlatList, Platform, Text, View, RefreshControl} from 'react-native'; import {FlatList, Platform, RefreshControl, Text, View} from 'react-native';
import {useIsFocused} from 'react-navigation-hooks'; import {useIsFocused} from 'react-navigation-hooks';
import {db} from '../../../App';
import {SIZE, WEIGHT} from '../../common/common'; import {SIZE, WEIGHT} from '../../common/common';
import Container from '../../components/Container'; import Container from '../../components/Container';
import {AddTopicEvent} from '../../components/DialogManager';
import {NotebookItem} from '../../components/NotebookItem'; import {NotebookItem} from '../../components/NotebookItem';
import SelectionWrapper from '../../components/SelectionWrapper';
import {useTracked} from '../../provider'; import {useTracked} from '../../provider';
import { import {
eSendEvent, eSendEvent,
@@ -12,13 +15,9 @@ import {
} from '../../services/eventManager'; } from '../../services/eventManager';
import { import {
eMoveNoteDialogNavigateBack, eMoveNoteDialogNavigateBack,
eScrollEvent,
eOnNewTopicAdded, eOnNewTopicAdded,
eScrollEvent,
} from '../../services/events'; } from '../../services/events';
import SelectionHeader from '../../components/SelectionHeader';
import SelectionWrapper from '../../components/SelectionWrapper';
import {AddTopicEvent} from '../../components/DialogManager';
import {db} from '../../../App';
export const Notebook = ({navigation}) => { export const Notebook = ({navigation}) => {
const [state, dispatch] = useTracked(); const [state, dispatch] = useTracked();
@@ -29,24 +28,27 @@ export const Notebook = ({navigation}) => {
let notebook; let notebook;
let isFocused = useIsFocused(); let isFocused = useIsFocused();
const onLoad = () => {
topics = db.notebooks.notebook(navigation.state.params.notebook.dateCreated)
.topics;
notebook = db.notebooks.notebook(
navigation.state.params.notebook.dateCreated,
);
setTopics([...topics]);
};
useEffect(() => { useEffect(() => {
params = navigation.state.params; params = navigation.state.params;
let topic = params.notebook.topics; let topic = params.notebook.topics;
notebook = params.notebook; notebook = params.notebook;
console.log(navigation);
setTopics([...topic]); setTopics([...topic]);
}, []); }, []);
useEffect(() => { useEffect(() => {
eSubscribeEvent(eOnNewTopicAdded, () => { eSubscribeEvent(eOnNewTopicAdded, onLoad);
notebook = db.getNotebook(navigation.state.params.notebook.dateCreated);
setTopics([...notebook.topics]);
});
return () => { return () => {
eUnSubscribeEvent(eOnNewTopicAdded, () => { eUnSubscribeEvent(eOnNewTopicAdded, onLoad);
notebook = db.getNotebook(navigation.state.params.notebook.dateCreated);
setTopics([...notebook.topics]);
});
}; };
}, []); }, []);
@@ -89,7 +91,7 @@ export const Notebook = ({navigation}) => {
}); });
}} }}
noteToMove={params.note} noteToMove={params.note}
notebookID={params.notebook.dateCreated} notebookID={params.notebook.id}
isMove={params.isMove} isMove={params.isMove}
refresh={() => {}} refresh={() => {}}
item={item} item={item}
@@ -143,7 +145,6 @@ export const Notebook = ({navigation}) => {
canGoBack={true} canGoBack={true}
data={topics} data={topics}
bottomButtonOnPress={() => { bottomButtonOnPress={() => {
console.log(navigation.state.params.notebook);
let n = navigation.state.params.notebook; let n = navigation.state.params.notebook;
AddTopicEvent(n); AddTopicEvent(n);
}}> }}>

View File

@@ -26,10 +26,12 @@ export const Notes = ({navigation}) => {
useEffect(() => { useEffect(() => {
if (params.type === 'tag') { if (params.type === 'tag') {
let notesInTag = db.getTag(params.tag.title); let notesInTag = db.notes.tagged(params.tag.title);
setNotes([...notesInTag]); setNotes([...notesInTag]);
} else { } else {
let allNotes = db.getTopic(params.notebookID, params.title); let allNotes = db.notebooks
.notebook(params.notebookID)
.topics.topic(params.title);
if (allNotes && allNotes.length > 0) { if (allNotes && allNotes.length > 0) {
setNotes(allNotes); setNotes(allNotes);
} }

View File

@@ -2,21 +2,18 @@ import React, {useEffect, useState} from 'react';
import { import {
Dimensions, Dimensions,
FlatList, FlatList,
SafeAreaView,
Text,
View,
TouchableOpacity,
RefreshControl,
Platform, Platform,
RefreshControl,
Text,
TouchableOpacity,
View,
} from 'react-native'; } from 'react-native';
import {pv, SIZE, WEIGHT} from '../../common/common'; import {pv, SIZE, WEIGHT} from '../../common/common';
import {Header} from '../../components/header'; import Container from '../../components/Container';
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 NavigationService from '../../services/NavigationService'; import NavigationService from '../../services/NavigationService';
import Container from '../../components/Container';
const w = Dimensions.get('window').width; const w = Dimensions.get('window').width;
const h = Dimensions.get('window').height; const h = Dimensions.get('window').height;