fix empty note creation

This commit is contained in:
ammarahm-ed
2020-04-11 12:16:05 +05:00
parent 7a6c186959
commit 41df9483e7
2 changed files with 24 additions and 21 deletions

View File

@@ -128,7 +128,7 @@ const MergeEditor = () => {
}; };
const onMessageFromPrimaryWebView = evt => { const onMessageFromPrimaryWebView = evt => {
alert('helloworld');
if (evt.nativeEvent.data !== '') { if (evt.nativeEvent.data !== '') {
let data = JSON.parse(evt.nativeEvent.data); let data = JSON.parse(evt.nativeEvent.data);
primaryDelta = data.delta; primaryDelta = data.delta;

View File

@@ -1,4 +1,4 @@
import React, {createRef, useEffect, useState} from 'react'; import React, { createRef, useEffect, useState } from 'react';
import { import {
BackHandler, BackHandler,
KeyboardAvoidingView, KeyboardAvoidingView,
@@ -12,7 +12,7 @@ import {
} from 'react-native'; } from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import WebView from 'react-native-webview'; import WebView from 'react-native-webview';
import {normalize, SIZE, WEIGHT} from '../../common/common'; import { normalize, SIZE, WEIGHT } from '../../common/common';
import { import {
ActionSheetEvent, ActionSheetEvent,
simpleDialogEvent, simpleDialogEvent,
@@ -21,8 +21,8 @@ import {
TEMPLATE_EXIT_FULLSCREEN, TEMPLATE_EXIT_FULLSCREEN,
TEMPLATE_INFO, TEMPLATE_INFO,
} from '../../components/DialogManager/templates'; } from '../../components/DialogManager/templates';
import {useTracked} from '../../provider'; import { useTracked } from '../../provider';
import {ACTIONS} from '../../provider/actions'; import { ACTIONS } from '../../provider/actions';
import { import {
eSendEvent, eSendEvent,
eSubscribeEvent, eSubscribeEvent,
@@ -35,9 +35,9 @@ import {
eOpenFullscreenEditor, eOpenFullscreenEditor,
refreshNotesPage, refreshNotesPage,
} from '../../services/events'; } from '../../services/events';
import {exitEditorAnimation} from '../../utils/animations'; import { exitEditorAnimation } from '../../utils/animations';
import {sideMenuRef} from '../../utils/refs'; import { sideMenuRef } from '../../utils/refs';
import {db, DDS, editing, timeConverter, ToastEvent} from '../../utils/utils'; import { db, DDS, editing, timeConverter, ToastEvent } from '../../utils/utils';
const EditorWebView = createRef(); const EditorWebView = createRef();
let note = {}; let note = {};
@@ -48,10 +48,10 @@ let timer = null;
let saveCounter = 0; let saveCounter = 0;
let tapCount = 0; let tapCount = 0;
let canSave = false; let canSave = false;
const Editor = ({noMenu}) => { const Editor = ({ noMenu }) => {
// Global State // Global State
const [state, dispatch] = useTracked(); const [state, dispatch] = useTracked();
const {colors} = state; const { colors } = state;
const [fullscreen, setFullscreen] = useState(false); const [fullscreen, setFullscreen] = useState(false);
const [dateEdited, setDateEdited] = useState(0); const [dateEdited, setDateEdited] = useState(0);
// FUNCTIONS // FUNCTIONS
@@ -60,7 +60,7 @@ const Editor = ({noMenu}) => {
EditorWebView.current?.postMessage(JSON.stringify(message)); EditorWebView.current?.postMessage(JSON.stringify(message));
useEffect(() => { useEffect(() => {
let c = {...colors}; let c = { ...colors };
c.factor = normalize(1); c.factor = normalize(1);
post({ post({
type: 'theme', type: 'theme',
@@ -80,7 +80,7 @@ const Editor = ({noMenu}) => {
//EditorWebView.current?.requestFocus(); //EditorWebView.current?.requestFocus();
noMenu ? null : sideMenuRef.current?.setGestureEnabled(false); noMenu ? null : sideMenuRef.current?.setGestureEnabled(false);
if (note && note.id) { if (note && note.id) {
dispatch({type: ACTIONS.NOTES}); dispatch({ type: ACTIONS.NOTES });
if (item && item.type === 'new') { if (item && item.type === 'new') {
await clearEditor(); await clearEditor();
post({ post({
@@ -97,7 +97,7 @@ const Editor = ({noMenu}) => {
updateEditor(); updateEditor();
} }
} else { } else {
dispatch({type: ACTIONS.NOTES}); dispatch({ type: ACTIONS.NOTES });
if (item && item.type === 'new') { if (item && item.type === 'new') {
await clearEditor(); await clearEditor();
post({ post({
@@ -249,10 +249,13 @@ const Editor = ({noMenu}) => {
const saveNote = async (lockNote = true) => { const saveNote = async (lockNote = true) => {
if (!canSave) return; if (!canSave) return;
if (!title && !content) return; if (!title && !content) return;
if (content && content.text.trim().length === 0 && title && title.trim().length == 0) return;
if (!content && title && title.trim().length === 0) return;
if (!title && content && content.text.trim.length === 0) return;
if (!content) { if (!content) {
content = { content = {
text: '', text: '',
delta: {ops: []}, delta: { ops: [] },
}; };
} }
@@ -344,7 +347,7 @@ const Editor = ({noMenu}) => {
type: 'focusTitle', type: 'focusTitle',
}); });
} }
let c = {...colors}; let c = { ...colors };
c.factor = normalize(1); c.factor = normalize(1);
post({ post({
type: 'theme', type: 'theme',
@@ -356,7 +359,7 @@ const Editor = ({noMenu}) => {
title = note.title; title = note.title;
id = note.id; id = note.id;
setDateEdited(note.dateEdited); setDateEdited(note.dateEdited);
content = {...note.content}; content = { ...note.content };
saveCounter = 0; saveCounter = 0;
if (title !== null || title === '') { if (title !== null || title === '') {
@@ -391,7 +394,7 @@ const Editor = ({noMenu}) => {
value: delta, value: delta,
}); });
} else { } else {
post({type: 'text', value: note.content.text}); post({ type: 'text', value: note.content.text });
} }
}; };
@@ -655,7 +658,7 @@ const Editor = ({noMenu}) => {
originWhitelist={['*']} originWhitelist={['*']}
source={ source={
Platform.OS === 'ios' Platform.OS === 'ios'
? {uri: sourceUri} ? { uri: sourceUri }
: { : {
uri: 'file:///android_asset/texteditor.html', uri: 'file:///android_asset/texteditor.html',
baseUrl: 'file:///android_asset/', baseUrl: 'file:///android_asset/',