mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-22 22:49:45 +01:00
add new database api
This commit is contained in:
@@ -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 {Platform, StatusBar, View, Text} from 'react-native';
|
||||
import * as Animatable from 'react-native-animatable';
|
||||
|
||||
@@ -1207,6 +1207,8 @@
|
||||
document.getElementById('titleInput').onchange = function () {
|
||||
editor.focus();
|
||||
|
||||
console.log(JSON.stringify(editor.getContents()));
|
||||
|
||||
var titleMessage = {
|
||||
type: 'title',
|
||||
value: document.getElementById('titleInput').value
|
||||
@@ -1625,9 +1627,12 @@
|
||||
|
||||
let m = {};
|
||||
m.delta = editor.getContents();
|
||||
|
||||
m.text = editor.getText();
|
||||
|
||||
m.html = editor.root.innerHTML;
|
||||
m.type = 'content';
|
||||
|
||||
window.ReactNativeWebView.postMessage(JSON.stringify(m));
|
||||
});
|
||||
|
||||
|
||||
@@ -87,8 +87,10 @@ export const ActionSheetComponent = ({
|
||||
text: '',
|
||||
});
|
||||
|
||||
await db.addTag(note.dateCreated, tag);
|
||||
setNote({...db.getNote(note.dateCreated)});
|
||||
await db.notes.note(note.id).tag(tag);
|
||||
|
||||
setNote({...db.notes.note(note.id).data});
|
||||
|
||||
tagToAdd = '';
|
||||
};
|
||||
|
||||
@@ -106,12 +108,11 @@ export const ActionSheetComponent = ({
|
||||
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],
|
||||
);
|
||||
await db.notes
|
||||
.note(note.id)
|
||||
.untag(oldProps.tags[oldProps.tags.length - 1]);
|
||||
|
||||
setNote({...db.getNote(note.dateCreated)});
|
||||
setNote({...db.notes.note(note.id).data});
|
||||
|
||||
tagsInputRef.setNativeProps({
|
||||
text: tagInputValue,
|
||||
@@ -125,25 +126,25 @@ export const ActionSheetComponent = ({
|
||||
};
|
||||
|
||||
const localRefresh = (type, nodispatch = false) => {
|
||||
if (!note || !note.dateCreated) return;
|
||||
if (!note || !note.id) return;
|
||||
let toAdd;
|
||||
|
||||
switch (type) {
|
||||
case 'note': {
|
||||
toAdd = db.getNote(note.dateCreated);
|
||||
toAdd = db.notes.note(note.id).data;
|
||||
break;
|
||||
}
|
||||
case 'notebook': {
|
||||
toAdd = db.getNotebook(note.dateCreated);
|
||||
toAdd = db.notebooks.notebook(note.id).data;
|
||||
break;
|
||||
}
|
||||
case 'topic': {
|
||||
toAdd = db.getTopic(note.notebookId, note.title);
|
||||
toAdd = db.notebooks.notebook(note.notebookId).topics.topic(note.title);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!toAdd || !toAdd.dateCreated) return;
|
||||
if (!toAdd || !toAdd.id) return;
|
||||
|
||||
if (!nodispatch) {
|
||||
dispatch({type: type});
|
||||
@@ -258,11 +259,11 @@ export const ActionSheetComponent = ({
|
||||
name: 'Pin',
|
||||
icon: 'tag',
|
||||
func: async () => {
|
||||
if (!note.dateCreated) return;
|
||||
if (!note.id) return;
|
||||
if (note.type === 'note') {
|
||||
await db.pinNote(note.dateCreated);
|
||||
await db.notes.note(note.id).pin();
|
||||
} else {
|
||||
await db.pinNotebook(note.dateCreated);
|
||||
await db.notebooks.notebook(note.id).pin();
|
||||
}
|
||||
dispatch({type: ACTIONS.PINNED});
|
||||
localRefresh(item.type);
|
||||
@@ -275,11 +276,11 @@ export const ActionSheetComponent = ({
|
||||
name: 'Favorite',
|
||||
icon: 'star',
|
||||
func: async () => {
|
||||
if (!note.dateCreated) return;
|
||||
if (!note.id) return;
|
||||
if (note.type === 'note') {
|
||||
await db.favoriteNotes([note.dateCreated]);
|
||||
await db.notes.note(note.id).favorite();
|
||||
} else {
|
||||
await db.favoriteNotebooks([note.dateCreated]);
|
||||
await db.notebooks.notebook(note.id).favorite();
|
||||
}
|
||||
dispatch({type: ACTIONS.FAVORITES});
|
||||
localRefresh(item.type);
|
||||
@@ -292,7 +293,7 @@ export const ActionSheetComponent = ({
|
||||
name: 'Add to Vault',
|
||||
icon: 'lock',
|
||||
func: () => {
|
||||
if (!note.dateCreated) return;
|
||||
if (!note.id) return;
|
||||
note.locked ? close('unlock') : close('lock');
|
||||
},
|
||||
close: true,
|
||||
@@ -307,11 +308,7 @@ export const ActionSheetComponent = ({
|
||||
onPress={async () => {
|
||||
let oldProps = {...note};
|
||||
|
||||
oldProps.tags.splice(oldProps.tags.indexOf(tag), 1);
|
||||
await db.addNote({
|
||||
dateCreated: note.dateCreated,
|
||||
tags: oldProps.tags,
|
||||
});
|
||||
await db.notes.note(note.id).untag(oldProps.tags.indexOf(tag));
|
||||
localRefresh(item.type);
|
||||
}}
|
||||
style={{
|
||||
@@ -350,13 +347,13 @@ export const ActionSheetComponent = ({
|
||||
} else {
|
||||
noteColors.push(color);
|
||||
}
|
||||
|
||||
db.addNote({
|
||||
// TODO
|
||||
/* db.addNote({
|
||||
dateCreated: note.dateCreated,
|
||||
colors: noteColors,
|
||||
content: note.content,
|
||||
title: note.title,
|
||||
});
|
||||
}); */
|
||||
localRefresh(item.type);
|
||||
}}
|
||||
style={{
|
||||
@@ -418,7 +415,7 @@ export const ActionSheetComponent = ({
|
||||
) : null;
|
||||
|
||||
const _renderColumnItem = item =>
|
||||
(note.dateCreated && columnItems.includes(item.name)) ||
|
||||
(note.id && columnItems.includes(item.name)) ||
|
||||
(item.name === 'Dark Mode' && columnItems.includes(item.name)) ? (
|
||||
<TouchableOpacity
|
||||
key={item.name}
|
||||
@@ -499,7 +496,7 @@ export const ActionSheetComponent = ({
|
||||
width: '100%',
|
||||
paddingHorizontal: 0,
|
||||
}}>
|
||||
{!note.dateCreated ? (
|
||||
{!note.id ? (
|
||||
<Text
|
||||
style={{
|
||||
width: '100%',
|
||||
@@ -556,7 +553,7 @@ export const ActionSheetComponent = ({
|
||||
marginTop: 2.5,
|
||||
}}>
|
||||
{note.type === 'note'
|
||||
? 'Last edited on ' + timeConverter(note.dateEditted)
|
||||
? 'Last edited on ' + timeConverter(note.dateEdited)
|
||||
: null}
|
||||
{note.type !== 'note' && !note.dateDeleted
|
||||
? 'Created on ' + timeConverter(note.dateCreated)
|
||||
@@ -624,7 +621,7 @@ export const ActionSheetComponent = ({
|
||||
</View>
|
||||
)}
|
||||
|
||||
{note.dateCreated ? (
|
||||
{note.id ? (
|
||||
<View
|
||||
style={{
|
||||
width: '100%',
|
||||
@@ -638,7 +635,7 @@ export const ActionSheetComponent = ({
|
||||
</View>
|
||||
) : null}
|
||||
|
||||
{hasColors && note.dateCreated ? (
|
||||
{hasColors && note.id ? (
|
||||
<View
|
||||
style={{
|
||||
flexDirection: 'row',
|
||||
@@ -655,7 +652,7 @@ export const ActionSheetComponent = ({
|
||||
</View>
|
||||
) : null}
|
||||
|
||||
{hasTags && note.dateCreated ? (
|
||||
{hasTags && note.id ? (
|
||||
<View
|
||||
style={{
|
||||
marginHorizontal: 12,
|
||||
|
||||
@@ -35,7 +35,7 @@ export class AddNotebookDialog extends React.Component {
|
||||
this.prevItem = null;
|
||||
this.prevIndex = null;
|
||||
this.currentSelectedInput = null;
|
||||
this.timestamp = null;
|
||||
this.id = null;
|
||||
this.backPressCount = 0;
|
||||
this.currentInputValue = null;
|
||||
this.titleRef;
|
||||
@@ -53,7 +53,7 @@ export class AddNotebookDialog extends React.Component {
|
||||
topicsList.push(item.title);
|
||||
}
|
||||
});
|
||||
this.timestamp = toEdit.dateCreated;
|
||||
this.id = toEdit.id;
|
||||
this.title = toEdit.title;
|
||||
this.description = toEdit.description;
|
||||
|
||||
@@ -76,7 +76,7 @@ export class AddNotebookDialog extends React.Component {
|
||||
this.currentSelectedInput = null;
|
||||
this.title = null;
|
||||
this.description = null;
|
||||
this.timestamp = null;
|
||||
this.id = null;
|
||||
this.setState({
|
||||
visible: false,
|
||||
topics: [],
|
||||
@@ -110,14 +110,16 @@ export class AddNotebookDialog extends React.Component {
|
||||
if (!this.title)
|
||||
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,
|
||||
description: this.description,
|
||||
topics,
|
||||
dateCreated: dateCreated,
|
||||
id: id,
|
||||
});
|
||||
|
||||
updateEvent({type: ACTIONS.NOTEBOOKS});
|
||||
this.close();
|
||||
ToastEvent.show('New notebook added', 'success', 3000, () => {}, '');
|
||||
|
||||
@@ -24,7 +24,8 @@ export class AddTopicDialog extends React.Component {
|
||||
if (!this.title)
|
||||
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);
|
||||
ToastEvent.show('New topic added', 'success', 3000, () => {}, '');
|
||||
this.close();
|
||||
|
||||
@@ -30,16 +30,18 @@ export class Dialog extends Component {
|
||||
switch (template.action) {
|
||||
case dialogActions.ACTION_DELETE: {
|
||||
if (item.type === 'note') {
|
||||
await db.deleteNotes(item.dateCreated);
|
||||
await db.notes.delete(item.id);
|
||||
|
||||
ToastEvent.show('Note moved to trash', 'error', 3000);
|
||||
updateEvent({type: item.type});
|
||||
} 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'});
|
||||
ToastEvent.show('Topic deleted', 'error', 3000);
|
||||
} else if (item.type === 'notebook') {
|
||||
await db.deleteNotebooks(item.dateCreated);
|
||||
await db.notebooks.delete(item.id);
|
||||
updateEvent({type: item.type});
|
||||
ToastEvent.show('Notebook moved to trash', 'error', 3000);
|
||||
}
|
||||
@@ -58,7 +60,9 @@ export class Dialog extends Component {
|
||||
break;
|
||||
}
|
||||
case dialogActions.ACTION_EMPTY_TRASH: {
|
||||
await db.clearTrash();
|
||||
// TODO
|
||||
//await db.clearTrash();
|
||||
|
||||
updateEvent({type: ACTIONS.TRASH});
|
||||
ToastEvent.show('Trash cleared', 'error', 1000, () => {}, '');
|
||||
this.setState({
|
||||
@@ -75,7 +79,8 @@ export class Dialog extends Component {
|
||||
});
|
||||
}
|
||||
case dialogActions.ACTION_TRASH: {
|
||||
db.restoreItem(item.dateCreated);
|
||||
// TODO
|
||||
//db.restoreItem(item.dateCreated);
|
||||
ToastEvent.show(
|
||||
item.type.slice(0, 1).toUpperCase() +
|
||||
item.type.slice(1) +
|
||||
|
||||
@@ -456,7 +456,7 @@ export class DialogManager extends Component {
|
||||
notebookID={
|
||||
actionSheetData.extraData
|
||||
? actionSheetData.extraData.notebookID
|
||||
: item.dateCreated
|
||||
: item.id
|
||||
}
|
||||
colors={colors}
|
||||
/>
|
||||
|
||||
@@ -1,23 +1,17 @@
|
||||
import React from 'react';
|
||||
import {
|
||||
Dimensions,
|
||||
Text,
|
||||
TouchableOpacity,
|
||||
View,
|
||||
DeviceEventEmitter,
|
||||
} from 'react-native';
|
||||
import {Dimensions, Text, TouchableOpacity, View} from 'react-native';
|
||||
import Icon from 'react-native-vector-icons/Feather';
|
||||
import {DDS} from '../../../App';
|
||||
import {ph, pv, SIZE, WEIGHT} from '../../common/common';
|
||||
import {eSendEvent} from '../../services/eventManager';
|
||||
import {eOnLoadNote} from '../../services/events';
|
||||
import NavigationService from '../../services/NavigationService';
|
||||
import {getElevation, timeSince} from '../../utils/utils';
|
||||
import {
|
||||
ActionSheetEvent,
|
||||
TEMPLATE_TRASH,
|
||||
simpleDialogEvent,
|
||||
TEMPLATE_TRASH,
|
||||
} from '../DialogManager';
|
||||
import {eSendEvent} from '../../services/eventManager';
|
||||
import {eOnLoadNote, eOpenSimpleDialog} from '../../services/events';
|
||||
|
||||
const w = Dimensions.get('window').width;
|
||||
const h = Dimensions.get('window').height;
|
||||
@@ -66,7 +60,7 @@ export default class NoteItem extends React.Component {
|
||||
pinned,
|
||||
index,
|
||||
} = this.props;
|
||||
|
||||
console.log('rerendering', index, item.content.text.length);
|
||||
return (
|
||||
<View
|
||||
style={[
|
||||
|
||||
@@ -241,30 +241,16 @@ export const NotebookItem = ({
|
||||
<TouchableOpacity
|
||||
activeOpacity={opacity}
|
||||
onPress={async () => {
|
||||
/* let noteIds = [];
|
||||
selectedItemsList.forEach(item => noteIds.push(item.dateCreated));
|
||||
if (!noteToMove.notebook.notebook) {
|
||||
await db.moveNotes(null, {
|
||||
let noteIds = [];
|
||||
selectedItemsList.forEach(item => noteIds.push(item.id));
|
||||
|
||||
db.notes.move(
|
||||
{
|
||||
topic: item.title,
|
||||
id: item.notebookId,
|
||||
});
|
||||
await db.addNoteToTopic(
|
||||
notebookID,
|
||||
item.title,
|
||||
noteToMove.dateCreated,
|
||||
id: item.notebookID,
|
||||
},
|
||||
noteIds,
|
||||
);
|
||||
} 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();
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ export const NotesList = ({isGrouped = false}) => {
|
||||
<SelectionWrapper
|
||||
index={index}
|
||||
currentEditingNote={
|
||||
currentEditingNote === item.dateCreated ? currentEditingNote : null
|
||||
currentEditingNote === item.id ? currentEditingNote : null
|
||||
}
|
||||
item={item}>
|
||||
<NoteItem
|
||||
@@ -44,7 +44,7 @@ export const NotesList = ({isGrouped = false}) => {
|
||||
marginHorizontal: 0,
|
||||
}}
|
||||
currentEditingNote={
|
||||
currentEditingNote === item.dateCreated ? currentEditingNote : null
|
||||
currentEditingNote === item.id ? currentEditingNote : null
|
||||
}
|
||||
onLongPress={() => {
|
||||
dispatch({type: ACTIONS.SELECTION_MODE, enabled: !selectionMode});
|
||||
@@ -167,7 +167,7 @@ export const NotesList = ({isGrouped = false}) => {
|
||||
}}></View>
|
||||
);
|
||||
|
||||
const _listKeyExtractor = (item, index) => item.dateCreated.toString();
|
||||
const _listKeyExtractor = (item, index) => item.id.toString();
|
||||
|
||||
return isGrouped && searchResults.length === 0 ? (
|
||||
<SectionList
|
||||
@@ -237,7 +237,7 @@ const PinnedItems = () => {
|
||||
<>
|
||||
<FlatList
|
||||
data={pinned}
|
||||
keyExtractor={(item, index) => item.dateCreated.toString()}
|
||||
keyExtractor={(item, index) => item.id.toString()}
|
||||
renderItem={({item, index}) =>
|
||||
item.type === 'note' ? (
|
||||
<NoteItem
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import React, {useEffect, useState} from 'react';
|
||||
import {TouchableWithoutFeedback, View} from 'react-native';
|
||||
import * as Animatable from 'react-native-animatable';
|
||||
import Icon from 'react-native-vector-icons/Feather';
|
||||
import {SIZE} from '../../common/common';
|
||||
import {useTracked} from '../../provider';
|
||||
@@ -26,11 +25,7 @@ const SelectionWrapper = ({children, item, currentEditingNote, index}) => {
|
||||
}, [selectedItemsList]);
|
||||
|
||||
return (
|
||||
<Animatable.View
|
||||
animation="fadeIn"
|
||||
useNativeDriver={true}
|
||||
duration={300 * index + 1}
|
||||
delay={index * 300}
|
||||
<View
|
||||
style={{
|
||||
flexDirection: 'row',
|
||||
justifyContent: 'space-between',
|
||||
@@ -78,7 +73,7 @@ const SelectionWrapper = ({children, item, currentEditingNote, index}) => {
|
||||
</TouchableWithoutFeedback>
|
||||
</View>
|
||||
{children}
|
||||
</Animatable.View>
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ export class VaultDialog extends Component {
|
||||
let item;
|
||||
if (n.content.cipher) {
|
||||
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) {}
|
||||
} else {
|
||||
item = n;
|
||||
@@ -63,7 +63,7 @@ export class VaultDialog extends Component {
|
||||
|
||||
this.close(this.props.shareAfterUnlock, item);
|
||||
} else {
|
||||
await db.lockNote(this.props.note.dateCreated, 'password');
|
||||
await db.notes.note(this.props.note.id).lock('password');
|
||||
this.close();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -5,7 +5,8 @@ import {ACTIONS} from './actions';
|
||||
export const reducer = (state, action) => {
|
||||
switch (action.type) {
|
||||
case ACTIONS.NOTES:
|
||||
let notes = db.groupNotes();
|
||||
let notes = db.notes.group();
|
||||
|
||||
return {
|
||||
...state,
|
||||
notes: [...notes],
|
||||
@@ -18,36 +19,36 @@ export const reducer = (state, action) => {
|
||||
};
|
||||
}
|
||||
case ACTIONS.NOTEBOOKS: {
|
||||
let notebooks = [...db.getNotebooks()];
|
||||
let notebooks = [...db.notebooks.all];
|
||||
return {
|
||||
...state,
|
||||
notebooks: notebooks,
|
||||
};
|
||||
}
|
||||
case ACTIONS.TRASH: {
|
||||
let trash = [...db.getTrash()];
|
||||
|
||||
let trash = [];
|
||||
// TODO
|
||||
return {
|
||||
...state,
|
||||
trash: trash,
|
||||
};
|
||||
}
|
||||
case ACTIONS.PINNED: {
|
||||
let pinned = [...db.getPinned()];
|
||||
let pinned = [...db.notes.pinned];
|
||||
return {
|
||||
...state,
|
||||
pinned: pinned,
|
||||
};
|
||||
}
|
||||
case ACTIONS.TAGS: {
|
||||
let tagList = db.getTags();
|
||||
let tagList = db.notes.tags;
|
||||
return {
|
||||
...state,
|
||||
tags: [...tagList],
|
||||
};
|
||||
}
|
||||
case ACTIONS.FAVORITES: {
|
||||
let favorites = [...db.getFavorites()];
|
||||
let favorites = [...db.notes.favorites];
|
||||
|
||||
return {
|
||||
...state,
|
||||
@@ -74,7 +75,7 @@ export const reducer = (state, action) => {
|
||||
} else {
|
||||
selectedItems.push(action.item);
|
||||
}
|
||||
console.log(action.item, selectedItems);
|
||||
|
||||
return {
|
||||
...state,
|
||||
selectedItemsList: selectedItems,
|
||||
@@ -101,7 +102,7 @@ export const reducer = (state, action) => {
|
||||
case ACTIONS.CURRENT_EDITING_NOTE: {
|
||||
return {
|
||||
...state,
|
||||
currentEditingNote: action.dateCreated,
|
||||
currentEditingNote: action.id,
|
||||
};
|
||||
}
|
||||
default:
|
||||
|
||||
@@ -3,11 +3,13 @@ import FastStorage from 'react-native-fast-storage';
|
||||
var Aes = NativeModules.Aes;
|
||||
|
||||
async function read(key) {
|
||||
return await FastStorage.getItem(key);
|
||||
let json = await FastStorage.getItem(key);
|
||||
return JSON.parse(json);
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
@@ -39,7 +39,7 @@ import {AnimatedSafeAreaView} from '../Home';
|
||||
|
||||
let EditorWebView;
|
||||
let note = {};
|
||||
let timestamp = null;
|
||||
let id = null;
|
||||
let dateEdited = null;
|
||||
var content = null;
|
||||
var title = null;
|
||||
@@ -65,7 +65,7 @@ const Editor = ({navigation, noMenu}) => {
|
||||
}, []);
|
||||
|
||||
const loadNote = item => {
|
||||
if (note && note.dateCreated) {
|
||||
if (note && note.id) {
|
||||
saveNote(true).then(() => {
|
||||
dispatch({type: ACTIONS.NOTES});
|
||||
if (item && item.type === 'new') {
|
||||
@@ -75,7 +75,7 @@ const Editor = ({navigation, noMenu}) => {
|
||||
if (DDS.isTab) {
|
||||
dispatch({
|
||||
type: ACTIONS.CURRENT_EDITING_NOTE,
|
||||
dateCreated: item.dateCreated,
|
||||
id: item.id,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ const Editor = ({navigation, noMenu}) => {
|
||||
if (DDS.isTab) {
|
||||
dispatch({
|
||||
type: ACTIONS.CURRENT_EDITING_NOTE,
|
||||
dateCreated: item.dateCreated,
|
||||
id: item.id,
|
||||
});
|
||||
}
|
||||
updateEditor();
|
||||
@@ -100,7 +100,7 @@ const Editor = ({navigation, noMenu}) => {
|
||||
};
|
||||
|
||||
const clearEditor = () => {
|
||||
timestamp = null;
|
||||
id = null;
|
||||
title = null;
|
||||
content = null;
|
||||
note = {};
|
||||
@@ -163,24 +163,24 @@ const Editor = ({navigation, noMenu}) => {
|
||||
};
|
||||
}
|
||||
|
||||
let dateCreated = await db.addNote({
|
||||
let rId = await db.notes.add({
|
||||
title,
|
||||
content: {
|
||||
text: content.text,
|
||||
delta: content.delta,
|
||||
},
|
||||
dateCreated: timestamp,
|
||||
id: id,
|
||||
});
|
||||
|
||||
if (timestamp !== dateCreated) {
|
||||
timestamp = dateCreated;
|
||||
if (id !== rId) {
|
||||
id = rId;
|
||||
|
||||
note = db.getNote(timestamp);
|
||||
note = db.notes.note(id);
|
||||
|
||||
if (DDS.isTab) {
|
||||
dispatch({
|
||||
type: ACTIONS.CURRENT_EDITING_NOTE,
|
||||
dateCreated: timestamp,
|
||||
id: id,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -191,10 +191,11 @@ const Editor = ({navigation, noMenu}) => {
|
||||
});
|
||||
}
|
||||
saveCounter++;
|
||||
if (timestamp) {
|
||||
let lockednote = db.getNote(timestamp);
|
||||
if (id) {
|
||||
let lockednote = db.notes.note(id);
|
||||
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) {
|
||||
note = navigation.state.params.note;
|
||||
updateEditor();
|
||||
} else if (note && note.dateCreated) {
|
||||
} else if (note && note.id) {
|
||||
updateEditor();
|
||||
} else {
|
||||
post('focusTitle');
|
||||
@@ -258,9 +259,9 @@ const Editor = ({navigation, noMenu}) => {
|
||||
}, timeout);
|
||||
});
|
||||
|
||||
const updateEditor = () => {
|
||||
const updateEditor = async () => {
|
||||
title = note.title;
|
||||
timestamp = note.dateCreated;
|
||||
id = note.id;
|
||||
dateEdited = note.dateEditted;
|
||||
content = note.content;
|
||||
saveCounter = 0;
|
||||
@@ -279,7 +280,9 @@ const Editor = ({navigation, noMenu}) => {
|
||||
if (note.content.text === '' && note.content.delta === null) {
|
||||
post('clear');
|
||||
} else if (note.content.delta) {
|
||||
post(JSON.stringify(note.content.delta));
|
||||
let delta = await db.notes.note(id).delta();
|
||||
|
||||
post(JSON.stringify(delta));
|
||||
} else {
|
||||
post(JSON.stringify({type: 'text', value: note.content.text}));
|
||||
}
|
||||
@@ -420,7 +423,7 @@ const Editor = ({navigation, noMenu}) => {
|
||||
}}>
|
||||
<Text
|
||||
onPress={() => {
|
||||
simpleDialogEvent(TEMPLATE_INFO(timestamp));
|
||||
simpleDialogEvent(TEMPLATE_INFO(note.dateCreated));
|
||||
}}
|
||||
style={{
|
||||
color: colors.icon,
|
||||
@@ -505,7 +508,7 @@ const Editor = ({navigation, noMenu}) => {
|
||||
}
|
||||
title = null;
|
||||
content = null;
|
||||
timestamp = null;
|
||||
id = null;
|
||||
timer = null;
|
||||
};
|
||||
}, [noMenu]);
|
||||
|
||||
@@ -120,7 +120,7 @@ export const Folders = ({navigation}) => {
|
||||
<>
|
||||
<FlatList
|
||||
data={pinned}
|
||||
keyExtractor={(item, index) => item.dateCreated.toString()}
|
||||
keyExtractor={(item, index) => item.id.toString()}
|
||||
renderItem={({item, index}) =>
|
||||
item.type === 'notebook' ? (
|
||||
<SelectionWrapper item={item}>
|
||||
@@ -213,7 +213,7 @@ export const Folders = ({navigation}) => {
|
||||
</View>
|
||||
}
|
||||
data={notebooks}
|
||||
keyExtractor={(item, index) => item.dateCreated.toString()}
|
||||
keyExtractor={(item, index) => item.id.toString()}
|
||||
renderItem={({item, index}) => (
|
||||
<SelectionWrapper item={item}>
|
||||
<NotebookItem
|
||||
|
||||
@@ -11,7 +11,7 @@ import {ACTIONS} from '../../provider/actions';
|
||||
import {eSendEvent} from '../../services/eventManager';
|
||||
import NavigationService from '../../services/NavigationService';
|
||||
import {SideMenuEvent} from '../../utils/utils';
|
||||
|
||||
let count = 0;
|
||||
export const AnimatedSafeAreaView = Animatable.createAnimatableComponent(
|
||||
SafeAreaView,
|
||||
);
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
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 {db} from '../../../App';
|
||||
import {SIZE, WEIGHT} from '../../common/common';
|
||||
import Container from '../../components/Container';
|
||||
import {AddTopicEvent} from '../../components/DialogManager';
|
||||
import {NotebookItem} from '../../components/NotebookItem';
|
||||
import SelectionWrapper from '../../components/SelectionWrapper';
|
||||
import {useTracked} from '../../provider';
|
||||
import {
|
||||
eSendEvent,
|
||||
@@ -12,13 +15,9 @@ import {
|
||||
} from '../../services/eventManager';
|
||||
import {
|
||||
eMoveNoteDialogNavigateBack,
|
||||
eScrollEvent,
|
||||
eOnNewTopicAdded,
|
||||
eScrollEvent,
|
||||
} 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}) => {
|
||||
const [state, dispatch] = useTracked();
|
||||
@@ -29,24 +28,27 @@ export const Notebook = ({navigation}) => {
|
||||
let notebook;
|
||||
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(() => {
|
||||
params = navigation.state.params;
|
||||
let topic = params.notebook.topics;
|
||||
notebook = params.notebook;
|
||||
console.log(navigation);
|
||||
setTopics([...topic]);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
eSubscribeEvent(eOnNewTopicAdded, () => {
|
||||
notebook = db.getNotebook(navigation.state.params.notebook.dateCreated);
|
||||
setTopics([...notebook.topics]);
|
||||
});
|
||||
eSubscribeEvent(eOnNewTopicAdded, onLoad);
|
||||
return () => {
|
||||
eUnSubscribeEvent(eOnNewTopicAdded, () => {
|
||||
notebook = db.getNotebook(navigation.state.params.notebook.dateCreated);
|
||||
setTopics([...notebook.topics]);
|
||||
});
|
||||
eUnSubscribeEvent(eOnNewTopicAdded, onLoad);
|
||||
};
|
||||
}, []);
|
||||
|
||||
@@ -89,7 +91,7 @@ export const Notebook = ({navigation}) => {
|
||||
});
|
||||
}}
|
||||
noteToMove={params.note}
|
||||
notebookID={params.notebook.dateCreated}
|
||||
notebookID={params.notebook.id}
|
||||
isMove={params.isMove}
|
||||
refresh={() => {}}
|
||||
item={item}
|
||||
@@ -143,7 +145,6 @@ export const Notebook = ({navigation}) => {
|
||||
canGoBack={true}
|
||||
data={topics}
|
||||
bottomButtonOnPress={() => {
|
||||
console.log(navigation.state.params.notebook);
|
||||
let n = navigation.state.params.notebook;
|
||||
AddTopicEvent(n);
|
||||
}}>
|
||||
|
||||
@@ -26,10 +26,12 @@ export const Notes = ({navigation}) => {
|
||||
|
||||
useEffect(() => {
|
||||
if (params.type === 'tag') {
|
||||
let notesInTag = db.getTag(params.tag.title);
|
||||
let notesInTag = db.notes.tagged(params.tag.title);
|
||||
setNotes([...notesInTag]);
|
||||
} 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) {
|
||||
setNotes(allNotes);
|
||||
}
|
||||
|
||||
@@ -2,21 +2,18 @@ import React, {useEffect, useState} from 'react';
|
||||
import {
|
||||
Dimensions,
|
||||
FlatList,
|
||||
SafeAreaView,
|
||||
Text,
|
||||
View,
|
||||
TouchableOpacity,
|
||||
RefreshControl,
|
||||
Platform,
|
||||
RefreshControl,
|
||||
Text,
|
||||
TouchableOpacity,
|
||||
View,
|
||||
} from 'react-native';
|
||||
import {pv, SIZE, WEIGHT} from '../../common/common';
|
||||
import {Header} from '../../components/header';
|
||||
import Container from '../../components/Container';
|
||||
import {TagsPlaceHolder} from '../../components/ListPlaceholders';
|
||||
import {useTracked} from '../../provider';
|
||||
import {ACTIONS} from '../../provider/actions';
|
||||
import {db} from '../../../App';
|
||||
import NavigationService from '../../services/NavigationService';
|
||||
import Container from '../../components/Container';
|
||||
const w = Dimensions.get('window').width;
|
||||
const h = Dimensions.get('window').height;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user