fix saving note

This commit is contained in:
ammarahm-ed
2021-02-05 10:15:16 +05:00
parent cdf38bf5bf
commit 046b832620
8 changed files with 56 additions and 13 deletions

View File

@@ -71,7 +71,10 @@ export default class NotesnookShare extends Component {
let add = async () => { let add = async () => {
await db.notes.add({ await db.notes.add({
title: this.state.title, title: this.state.title,
content: `<${tag}>${this.state.text}<${tag}/>`, content: {
type:'tiny',
data:`<${tag}>${this.state.text}<${tag}/>`
},
id: null, id: null,
}); });
}; };

View File

@@ -1,6 +1,5 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="utf-8" /> <meta charset="utf-8" />

View File

@@ -12,6 +12,8 @@ function reactNativeEventHandler(type, value) {
} }
let changeTimer = null; let changeTimer = null;
let isLoading = true;
function init_tiny(size) { function init_tiny(size) {
tinymce.init({ tinymce.init({
selector: '#tiny_textarea', selector: '#tiny_textarea',
@@ -46,7 +48,12 @@ function init_tiny(size) {
reactNativeEventHandler('status', true); reactNativeEventHandler('status', true);
editor.on('SelectionChange', function (e) { editor.on('SelectionChange', function (e) {
clearTimeout(changeTimer); clearTimeout(changeTimer);
if (isLoading) {
isLoading = false;
return;
}
changeTimer = setTimeout(() => { changeTimer = setTimeout(() => {
if (editor.plugins.wordcount.getCount() === 0) return;
selectchange(); selectchange();
reactNativeEventHandler('tiny', editor.getContent()); reactNativeEventHandler('tiny', editor.getContent());
reactNativeEventHandler('history', { reactNativeEventHandler('history', {
@@ -60,7 +67,13 @@ function init_tiny(size) {
}); });
editor.on('Change', function (e) { editor.on('Change', function (e) {
clearTimeout(changeTimer); clearTimeout(changeTimer);
if (isLoading) {
isLoading = false;
return;
}
changeTimer = setTimeout(() => { changeTimer = setTimeout(() => {
if (editor.plugins.wordcount.getCount() === 0) return;
selectchange(); selectchange();
reactNativeEventHandler('tiny', editor.getContent()); reactNativeEventHandler('tiny', editor.getContent());
reactNativeEventHandler('history', { reactNativeEventHandler('history', {
@@ -70,7 +83,7 @@ function init_tiny(size) {
}, 5); }, 5);
}); });
editor.on('ExecCommand', function (e) { editor.on('ExecCommand', function (e) {
reactNativeEventHandler(e); //reactNativeEventHandler(e);
}); });
}, },
}); });

View File

@@ -12,6 +12,8 @@ function reactNativeEventHandler(type, value) {
} }
let changeTimer = null; let changeTimer = null;
let isLoading = true;
function init_tiny(size) { function init_tiny(size) {
tinymce.init({ tinymce.init({
selector: '#tiny_textarea', selector: '#tiny_textarea',
@@ -46,7 +48,12 @@ function init_tiny(size) {
reactNativeEventHandler('status', true); reactNativeEventHandler('status', true);
editor.on('SelectionChange', function (e) { editor.on('SelectionChange', function (e) {
clearTimeout(changeTimer); clearTimeout(changeTimer);
if (isLoading) {
isLoading = false;
return;
}
changeTimer = setTimeout(() => { changeTimer = setTimeout(() => {
if (editor.plugins.wordcount.getCount() === 0) return;
selectchange(); selectchange();
reactNativeEventHandler('tiny', editor.getContent()); reactNativeEventHandler('tiny', editor.getContent());
reactNativeEventHandler('history', { reactNativeEventHandler('history', {
@@ -60,7 +67,13 @@ function init_tiny(size) {
}); });
editor.on('Change', function (e) { editor.on('Change', function (e) {
clearTimeout(changeTimer); clearTimeout(changeTimer);
if (isLoading) {
isLoading = false;
return;
}
changeTimer = setTimeout(() => { changeTimer = setTimeout(() => {
if (editor.plugins.wordcount.getCount() === 0) return;
selectchange(); selectchange();
reactNativeEventHandler('tiny', editor.getContent()); reactNativeEventHandler('tiny', editor.getContent());
reactNativeEventHandler('history', { reactNativeEventHandler('history', {
@@ -70,7 +83,7 @@ function init_tiny(size) {
}, 5); }, 5);
}); });
editor.on('ExecCommand', function (e) { editor.on('ExecCommand', function (e) {
reactNativeEventHandler(e); //reactNativeEventHandler(e);
}); });
}, },
}); });

View File

@@ -549,7 +549,7 @@ export const ActionSheetComponent = ({
{note.type === 'notebook' && note.description {note.type === 'notebook' && note.description
? note.description ? note.description
: null} : null}
{note.type === 'note' {note.type === 'note' && item.headline
? note.headline[item.headline.length - 1] === '\n' ? note.headline[item.headline.length - 1] === '\n'
? note.headline.slice(0, note.headline.length - 1) ? note.headline.slice(0, note.headline.length - 1)
: note.headline : note.headline

View File

@@ -128,11 +128,13 @@ export default class NoteItem extends React.Component {
{item.title.replace('\n', '')} {item.title.replace('\n', '')}
</Heading> </Heading>
<Paragraph numberOfLines={2}> {item.headline && (
{item.headline[item.headline.length - 1] === '\n' <Paragraph numberOfLines={2}>
? item.headline.slice(0, item.headline.length - 1) {item.headline[item.headline.length - 1] === '\n'
: item.headline} ? item.headline.slice(0, item.headline.length - 1)
</Paragraph> : item.headline}
</Paragraph>
)}
<View <View
style={{ style={{

View File

@@ -238,8 +238,12 @@ export const _onMessage = async (evt) => {
case 'history': case 'history':
eSendEvent('historyEvent', message.value); eSendEvent('historyEvent', message.value);
break; break;
case 'change': case 'tiny':
content = message; console.log('change',message);
content = {
type:message.type,
data:message.value
};
onNoteChange(); onNoteChange();
break; break;
case 'title': case 'title':
@@ -299,6 +303,7 @@ function onNoteChange() {
} }
export async function clearEditor() { export async function clearEditor() {
tiny.call(EditorWebView,tiny.isLoading);
clearTimer(); clearTimer();
tiny.call(EditorWebView, tiny.reset); tiny.call(EditorWebView, tiny.reset);
if (noteEdited && id) { if (noteEdited && id) {
@@ -386,6 +391,8 @@ export async function saveNote() {
return; return;
} }
let locked = id ? db.notes.note(id).data.locked : null; let locked = id ? db.notes.note(id).data.locked : null;
console.log(content,"SAVE Content");
let noteData = { let noteData = {
title, title,
content: { content: {

View File

@@ -103,7 +103,12 @@ const updateTheme = (value) => `
`; `;
const isLoading =`
isLoading = true;
`;
const html = (value) => ` const html = (value) => `
isLoading = true;
editor.setContent("${value}"); editor.setContent("${value}");
info.querySelector('#infowords').innerText = info.querySelector('#infowords').innerText =
editor.plugins.wordcount.getCount() + " words"; editor.plugins.wordcount.getCount() + " words";
@@ -151,5 +156,6 @@ export default {
updateSavingState, updateSavingState,
updateTheme, updateTheme,
setTitle, setTitle,
restoreRange restoreRange,
isLoading
}; };