mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 15:09:33 +01:00
fix vault
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -339,7 +339,7 @@ export const ActionSheetComponent = ({
|
|||||||
|
|
||||||
if (note.locked) {
|
if (note.locked) {
|
||||||
close();
|
close();
|
||||||
openVault(note, true, false, true, false, false);
|
openVault(note, true, true, true, false, false);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import {AddTopicDialog} from '../AddTopicDialog';
|
|||||||
import {Dialog} from '../Dialog';
|
import {Dialog} from '../Dialog';
|
||||||
import LoginDialog from '../LoginDialog';
|
import LoginDialog from '../LoginDialog';
|
||||||
import MoveNoteDialog from '../MoveNoteDialog';
|
import MoveNoteDialog from '../MoveNoteDialog';
|
||||||
import {VaultDialog} from '../VaultDialog';
|
import {VaultDialog, openVault} from '../VaultDialog';
|
||||||
import {timeConverter, hexToRGBA} from '../../utils/utils';
|
import {timeConverter, hexToRGBA} from '../../utils/utils';
|
||||||
import {Platform} from 'react-native';
|
import {Platform} from 'react-native';
|
||||||
|
|
||||||
@@ -334,7 +334,12 @@ export class DialogManager extends Component {
|
|||||||
if (this.show) {
|
if (this.show) {
|
||||||
switch (this.show) {
|
switch (this.show) {
|
||||||
case 'delete': {
|
case 'delete': {
|
||||||
this._showSimpleDialog(TEMPLATE_DELETE(this.state.item.type));
|
if (this.state.item.locked) {
|
||||||
|
openVault(this.state.item, true, true, false, false, false, true);
|
||||||
|
} else {
|
||||||
|
this._showSimpleDialog(TEMPLATE_DELETE(this.state.item.type));
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'permanant_delete': {
|
case 'permanant_delete': {
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ export default class NoteItem extends React.Component {
|
|||||||
this.props.onLongPress();
|
this.props.onLongPress();
|
||||||
return;
|
return;
|
||||||
} else if (item.locked) {
|
} else if (item.locked) {
|
||||||
openVault(item, false, true, false, true, false);
|
openVault(item, true, true, false, true, false);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import {SIZE, ph, pv, opacity, WEIGHT} from '../../common/common';
|
|||||||
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
|
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
|
||||||
import {TextInput} from 'react-native-gesture-handler';
|
import {TextInput} from 'react-native-gesture-handler';
|
||||||
import {db, DDS} from '../../../App';
|
import {db, DDS} from '../../../App';
|
||||||
import {getElevation, ToastEvent} from '../../utils/utils';
|
import {getElevation, ToastEvent, editing} from '../../utils/utils';
|
||||||
|
|
||||||
import {updateEvent} from '../DialogManager';
|
import {updateEvent} from '../DialogManager';
|
||||||
import Share from 'react-native-share';
|
import Share from 'react-native-share';
|
||||||
@@ -17,6 +17,7 @@ import {
|
|||||||
eOnLoadNote,
|
eOnLoadNote,
|
||||||
eOpenVaultDialog,
|
eOpenVaultDialog,
|
||||||
eCloseVaultDialog,
|
eCloseVaultDialog,
|
||||||
|
refreshNotesPage,
|
||||||
} from '../../services/events';
|
} from '../../services/events';
|
||||||
import {openEditorAnimation} from '../../utils/animations';
|
import {openEditorAnimation} from '../../utils/animations';
|
||||||
import {ACTIONS} from '../../provider/actions';
|
import {ACTIONS} from '../../provider/actions';
|
||||||
@@ -31,14 +32,17 @@ export const openVault = (
|
|||||||
permanant = false,
|
permanant = false,
|
||||||
editor = false,
|
editor = false,
|
||||||
share = false,
|
share = false,
|
||||||
|
deleteNote = false,
|
||||||
) => {
|
) => {
|
||||||
|
console.log(editor, 'hello');
|
||||||
eSendEvent(eOpenVaultDialog, {
|
eSendEvent(eOpenVaultDialog, {
|
||||||
item,
|
item,
|
||||||
novault,
|
novault,
|
||||||
locked,
|
locked,
|
||||||
permanant,
|
permanant,
|
||||||
editor,
|
goToEditor: editor,
|
||||||
share,
|
share,
|
||||||
|
deleteNote,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -55,6 +59,7 @@ export class VaultDialog extends Component {
|
|||||||
goToEditor: false,
|
goToEditor: false,
|
||||||
share: false,
|
share: false,
|
||||||
passwordsDontMatch: false,
|
passwordsDontMatch: false,
|
||||||
|
deleteNote: false,
|
||||||
};
|
};
|
||||||
this.password = null;
|
this.password = null;
|
||||||
}
|
}
|
||||||
@@ -76,7 +81,9 @@ export class VaultDialog extends Component {
|
|||||||
permanant = false,
|
permanant = false,
|
||||||
goToEditor = false,
|
goToEditor = false,
|
||||||
share = false,
|
share = false,
|
||||||
|
deleteNote = false,
|
||||||
}) => {
|
}) => {
|
||||||
|
console.log(goToEditor, 'goToEditor');
|
||||||
this.setState({
|
this.setState({
|
||||||
visible: true,
|
visible: true,
|
||||||
note: item,
|
note: item,
|
||||||
@@ -85,6 +92,7 @@ export class VaultDialog extends Component {
|
|||||||
permanant,
|
permanant,
|
||||||
goToEditor,
|
goToEditor,
|
||||||
share,
|
share,
|
||||||
|
deleteNote,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -99,6 +107,7 @@ export class VaultDialog extends Component {
|
|||||||
goToEditor: false,
|
goToEditor: false,
|
||||||
share: false,
|
share: false,
|
||||||
novault: false,
|
novault: false,
|
||||||
|
deleteNote: false,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -121,11 +130,17 @@ export class VaultDialog extends Component {
|
|||||||
} else if (this.state.locked) {
|
} else if (this.state.locked) {
|
||||||
if (!this.password || this.password.trim() === 0) {
|
if (!this.password || this.password.trim() === 0) {
|
||||||
ToastAndroid.show('Please enter a valid password', 300);
|
ToastAndroid.show('Please enter a valid password', 300);
|
||||||
|
this.setState({
|
||||||
|
wrongPassword: true,
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
db.vault
|
db.vault
|
||||||
.unlock(this.password)
|
.unlock(this.password)
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
|
this.setState({
|
||||||
|
wrongPassword: false,
|
||||||
|
});
|
||||||
if (this.state.note.locked) {
|
if (this.state.note.locked) {
|
||||||
await this._unlockNote();
|
await this._unlockNote();
|
||||||
} else {
|
} else {
|
||||||
@@ -164,12 +179,28 @@ export class VaultDialog extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async _openNote() {
|
async _openNote() {
|
||||||
let note = await db.vault.open(this.state.note.id, this.password);
|
db.vault
|
||||||
if (this.state.goToEditor) {
|
.open(this.state.note.id, this.password)
|
||||||
this._openInEditor(note);
|
.then(async () => {
|
||||||
} else if (this.state.share) {
|
if (this.state.goToEditor) {
|
||||||
this._shareNote(note);
|
this._openInEditor(note);
|
||||||
}
|
} else if (this.state.share) {
|
||||||
|
this._shareNote(note);
|
||||||
|
} else if (this.state.deleteNote) {
|
||||||
|
await this._deleteNote();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(e => {
|
||||||
|
this._takeErrorAction(e);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
async _deleteNote() {
|
||||||
|
await db.notes.delete(this.state.note.id);
|
||||||
|
updateEvent({type: ACTIONS.NOTES});
|
||||||
|
updateEvent({type: ACTIONS.FAVORITES});
|
||||||
|
eSendEvent(refreshNotesPage);
|
||||||
|
this.close();
|
||||||
|
ToastEvent.show('Note deleted', 'success');
|
||||||
}
|
}
|
||||||
|
|
||||||
async _createVault() {
|
async _createVault() {
|
||||||
@@ -282,8 +313,14 @@ export class VaultDialog extends Component {
|
|||||||
{!novault
|
{!novault
|
||||||
? 'Create vault'
|
? 'Create vault'
|
||||||
: note.locked
|
: note.locked
|
||||||
? 'Unlock Note'
|
? this.state.deleteNote
|
||||||
: 'Lock Note'}
|
? 'Delete note'
|
||||||
|
: this.state.share
|
||||||
|
? 'Share note'
|
||||||
|
: this.state.goToEditor
|
||||||
|
? 'Unlock note'
|
||||||
|
: 'Unlock note'
|
||||||
|
: 'Lock note'}
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
@@ -303,7 +340,13 @@ export class VaultDialog extends Component {
|
|||||||
: permanant
|
: permanant
|
||||||
? 'Enter password to remove note from vault.'
|
? 'Enter password to remove note from vault.'
|
||||||
: note.locked
|
: note.locked
|
||||||
? 'Enter vault password to unlock note.'
|
? this.state.deleteNote
|
||||||
|
? 'Unlock note to delete it.'
|
||||||
|
: this.state.share
|
||||||
|
? 'Unlock note to share it.'
|
||||||
|
: this.state.goToEditor
|
||||||
|
? 'Unlock note to open it in editor'
|
||||||
|
: 'Enter vault password to unlock note.'
|
||||||
: 'Do you want to lock this note?'}
|
: 'Do you want to lock this note?'}
|
||||||
</Text>
|
</Text>
|
||||||
|
|
||||||
@@ -414,7 +457,15 @@ export class VaultDialog extends Component {
|
|||||||
color: 'white',
|
color: 'white',
|
||||||
fontSize: SIZE.sm,
|
fontSize: SIZE.sm,
|
||||||
}}>
|
}}>
|
||||||
{note.locked ? 'Unlock' : 'Lock'}
|
{note.locked
|
||||||
|
? this.state.deleteNote
|
||||||
|
? 'Delete'
|
||||||
|
: this.state.share
|
||||||
|
? 'Share '
|
||||||
|
: this.state.goToEditor
|
||||||
|
? 'Open'
|
||||||
|
: 'Unlock'
|
||||||
|
: 'Lock'}
|
||||||
</Text>
|
</Text>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
|
|
||||||
|
|||||||
@@ -172,87 +172,91 @@ const Editor = ({navigation, noMenu}) => {
|
|||||||
delta: {ops: []},
|
delta: {ops: []},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
let lockedNote = id ? db.notes.note(id).data.locked : null;
|
||||||
console.log(id, title, content);
|
if (!lockedNote) {
|
||||||
let rId = await db.notes.add({
|
let rId = await db.notes.add({
|
||||||
title,
|
title,
|
||||||
content: {
|
content: {
|
||||||
text: content.text,
|
text: content.text,
|
||||||
delta: content.delta,
|
delta: content.delta,
|
||||||
},
|
},
|
||||||
id: id,
|
|
||||||
});
|
|
||||||
if (id !== rId && !note?.locked) {
|
|
||||||
id = rId;
|
|
||||||
note = db.notes.note(id);
|
|
||||||
if (note) {
|
|
||||||
note = note.data;
|
|
||||||
} else {
|
|
||||||
setTimeout(() => {
|
|
||||||
note = db.notes.note(id);
|
|
||||||
if (note) {
|
|
||||||
note = note.data;
|
|
||||||
}
|
|
||||||
}, 500);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (id) {
|
|
||||||
switch (editing.actionAfterFirstSave.type) {
|
|
||||||
case 'topic': {
|
|
||||||
await db.notes.move(
|
|
||||||
{
|
|
||||||
topic: editing.actionAfterFirstSave.id,
|
|
||||||
id: editing.actionAfterFirstSave.notebook,
|
|
||||||
},
|
|
||||||
id,
|
|
||||||
);
|
|
||||||
editing.actionAfterFirstSave = {
|
|
||||||
type: null,
|
|
||||||
};
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'tag': {
|
|
||||||
await db.notes.note(note.id).tag(editing.actionAfterFirstSave.id);
|
|
||||||
editing.actionAfterFirstSave = {
|
|
||||||
type: null,
|
|
||||||
};
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'color': {
|
|
||||||
await db.notes.note(id).color(editing.actionAfterFirstSave.id);
|
|
||||||
|
|
||||||
editing.actionAfterFirstSave = {
|
|
||||||
type: null,
|
|
||||||
};
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dispatch({
|
|
||||||
type: ACTIONS.CURRENT_EDITING_NOTE,
|
|
||||||
id: id,
|
id: id,
|
||||||
});
|
});
|
||||||
}
|
if (id !== rId) {
|
||||||
|
id = rId;
|
||||||
|
note = db.notes.note(id);
|
||||||
|
if (note) {
|
||||||
|
note = note.data;
|
||||||
|
} else {
|
||||||
|
setTimeout(() => {
|
||||||
|
note = db.notes.note(id);
|
||||||
|
if (note) {
|
||||||
|
note = note.data;
|
||||||
|
}
|
||||||
|
}, 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (content.text.length < 200 || saveCounter < 2) {
|
if (id) {
|
||||||
dispatch({
|
switch (editing.actionAfterFirstSave.type) {
|
||||||
type: ACTIONS.NOTES,
|
case 'topic': {
|
||||||
});
|
await db.notes.move(
|
||||||
eSendEvent(refreshNotesPage);
|
{
|
||||||
}
|
topic: editing.actionAfterFirstSave.id,
|
||||||
saveCounter++;
|
id: editing.actionAfterFirstSave.notebook,
|
||||||
if (id) {
|
},
|
||||||
let lockednote = db.notes.note(id).data;
|
id,
|
||||||
|
);
|
||||||
|
editing.actionAfterFirstSave = {
|
||||||
|
type: null,
|
||||||
|
};
|
||||||
|
|
||||||
if (lockNote && lockednote && lockednote.locked) {
|
break;
|
||||||
await db.notes.note(id).lock('password');
|
}
|
||||||
|
case 'tag': {
|
||||||
|
await db.notes.note(note.id).tag(editing.actionAfterFirstSave.id);
|
||||||
|
editing.actionAfterFirstSave = {
|
||||||
|
type: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'color': {
|
||||||
|
await db.notes.note(id).color(editing.actionAfterFirstSave.id);
|
||||||
|
|
||||||
|
editing.actionAfterFirstSave = {
|
||||||
|
type: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dispatch({
|
||||||
|
type: ACTIONS.CURRENT_EDITING_NOTE,
|
||||||
|
id: id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (content.text.length < 200 || saveCounter < 2) {
|
||||||
|
dispatch({
|
||||||
|
type: ACTIONS.NOTES,
|
||||||
|
});
|
||||||
|
eSendEvent(refreshNotesPage);
|
||||||
|
}
|
||||||
|
saveCounter++;
|
||||||
|
} else {
|
||||||
|
if (id) {
|
||||||
|
await db.vault.save({
|
||||||
|
title,
|
||||||
|
content: {
|
||||||
|
text: content.text,
|
||||||
|
delta: content.delta,
|
||||||
|
},
|
||||||
|
id: id,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -591,7 +595,7 @@ const Editor = ({navigation, noMenu}) => {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
cacheMode="LOAD_DEFAULT"
|
cacheMode="LOAD_DEFAULT"
|
||||||
cacheEnabled={true}
|
cacheEnabled={false}
|
||||||
domStorageEnabled={true}
|
domStorageEnabled={true}
|
||||||
scrollEnabled={false}
|
scrollEnabled={false}
|
||||||
bounces={false}
|
bounces={false}
|
||||||
|
|||||||
Reference in New Issue
Block a user