fix vault dialog not opening on ios

This commit is contained in:
ammarahm-ed
2020-04-18 13:49:24 +05:00
parent 6f3c4b5c38
commit 6f416b2e07
2 changed files with 187 additions and 205 deletions

View File

@@ -1,4 +1,4 @@
import React, { createRef, useEffect, useState } from 'react'; import React, {createRef, useEffect, useState} from 'react';
import { import {
Dimensions, Dimensions,
StatusBar, StatusBar,
@@ -22,19 +22,19 @@ import {
SIZE, SIZE,
WEIGHT, WEIGHT,
} from '../../common/common'; } from '../../common/common';
import { useTracked } from '../../provider'; import {useTracked} from '../../provider';
import { ACTIONS } from '../../provider/actions'; import {ACTIONS} from '../../provider/actions';
import NavigationService from '../../services/NavigationService'; import NavigationService from '../../services/NavigationService';
import { timeConverter, ToastEvent, DDS, db } from '../../utils/utils'; import {timeConverter, ToastEvent, DDS, db} from '../../utils/utils';
import { openVault, eSendEvent } from '../../services/eventManager'; import {openVault, eSendEvent} from '../../services/eventManager';
import { refreshNotesPage } from '../../services/events'; import {refreshNotesPage} 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;
const tagsInputRef = createRef(); const tagsInputRef = createRef();
export const ActionSheetComponent = ({ export const ActionSheetComponent = ({
close = () => { }, close = () => {},
item, item,
hasColors = false, hasColors = false,
hasTags = false, hasTags = false,
@@ -42,35 +42,35 @@ export const ActionSheetComponent = ({
columnItems = [], columnItems = [],
}) => { }) => {
const [state, dispatch] = useTracked(); const [state, dispatch] = useTracked();
const { colors, tags, currentEditingNote } = state; const {colors, tags, currentEditingNote} = state;
const [focused, setFocused] = useState(false); const [focused, setFocused] = useState(false);
const [note, setNote] = useState( const [note, setNote] = useState(
item item
? item ? item
: { : {
colors: [], colors: [],
tags: [], tags: [],
pinned: false, pinned: false,
favorite: false, favorite: false,
locked: false, locked: false,
content: { content: {
text: null, text: null,
delta: null, delta: null,
},
dateCreated: null,
}, },
dateCreated: null,
},
); );
function changeColorScheme(colors = COLOR_SCHEME, accent = ACCENT) { function changeColorScheme(colors = COLOR_SCHEME, accent = ACCENT) {
let newColors = setColorScheme(colors, accent); let newColors = setColorScheme(colors, accent);
StatusBar.setBarStyle(colors.night ? 'light-content' : 'dark-content'); StatusBar.setBarStyle(colors.night ? 'light-content' : 'dark-content');
dispatch({ type: ACTIONS.THEME, colors: newColors }); dispatch({type: ACTIONS.THEME, colors: newColors});
} }
useEffect(() => { useEffect(() => {
if (item.dateCreated !== null) { if (item.dateCreated !== null) {
setNote({ ...item }); setNote({...item});
} }
}, [item]); }, [item]);
@@ -96,8 +96,8 @@ export const ActionSheetComponent = ({
await db.notes.note(note.id).tag(tag); await db.notes.note(note.id).tag(tag);
setNote({ ...db.notes.note(note.id).data }); setNote({...db.notes.note(note.id).data});
dispatch({ type: ACTIONS.TAGS }); dispatch({type: ACTIONS.TAGS});
tagToAdd = ''; tagToAdd = '';
}; };
@@ -112,14 +112,14 @@ export const ActionSheetComponent = ({
backPressCount = 0; backPressCount = 0;
let tagInputValue = note.tags[note.tags.length - 1]; let tagInputValue = note.tags[note.tags.length - 1];
let oldProps = { ...note }; let oldProps = {...note};
if (oldProps.tags.length === 0) return; if (oldProps.tags.length === 0) return;
await db.notes await db.notes
.note(note.id) .note(note.id)
.untag(oldProps.tags[oldProps.tags.length - 1]); .untag(oldProps.tags[oldProps.tags.length - 1]);
setNote({ ...db.notes.note(note.id).data }); setNote({...db.notes.note(note.id).data});
tagsInputRef.current?.setNativeProps({ tagsInputRef.current?.setNativeProps({
text: tagInputValue, text: tagInputValue,
@@ -183,11 +183,11 @@ export const ActionSheetComponent = ({
if (!toAdd || !toAdd.id) return; if (!toAdd || !toAdd.id) return;
if (!nodispatch) { if (!nodispatch) {
dispatch({ type: type }); dispatch({type: type});
dispatch({ type: ACTIONS.PINNED }); dispatch({type: ACTIONS.PINNED});
dispatch({ type: ACTIONS.FAVORITES }); dispatch({type: ACTIONS.FAVORITES});
} }
setNote({ ...toAdd }); setNote({...toAdd});
}; };
const rowItemsData = [ const rowItemsData = [
@@ -195,8 +195,8 @@ export const ActionSheetComponent = ({
name: 'Add to', name: 'Add to',
icon: 'book-outline', icon: 'book-outline',
func: () => { func: () => {
dispatch({ type: ACTIONS.MODAL_NAVIGATOR, enabled: true }); dispatch({type: ACTIONS.MODAL_NAVIGATOR, enabled: true});
dispatch({ type: ACTIONS.SELECTED_ITEMS, item: note }); dispatch({type: ACTIONS.SELECTED_ITEMS, item: note});
close('movenote'); close('movenote');
}, },
@@ -260,7 +260,7 @@ export const ActionSheetComponent = ({
icon: 'delete-restore', icon: 'delete-restore',
func: async () => { func: async () => {
await db.trash.restore(note.id); await db.trash.restore(note.id);
dispatch({ type: ACTIONS.TRASH }); dispatch({type: ACTIONS.TRASH});
localRefresh(note.type); localRefresh(note.type);
ToastEvent.show( ToastEvent.show(
item.type === 'note' ? 'Note restored' : 'Notebook restored', item.type === 'note' ? 'Note restored' : 'Notebook restored',
@@ -284,10 +284,10 @@ export const ActionSheetComponent = ({
icon: 'theme-light-dark', icon: 'theme-light-dark',
func: () => { func: () => {
if (!colors.night) { if (!colors.night) {
MMKV.setStringAsync('theme', JSON.stringify({ night: true })); MMKV.setStringAsync('theme', JSON.stringify({night: true}));
changeColorScheme(COLOR_SCHEME_DARK); changeColorScheme(COLOR_SCHEME_DARK);
} else { } else {
MMKV.setStringAsync('theme', JSON.stringify({ night: false })); MMKV.setStringAsync('theme', JSON.stringify({night: false}));
changeColorScheme(COLOR_SCHEME_LIGHT); changeColorScheme(COLOR_SCHEME_LIGHT);
} }
}, },
@@ -305,7 +305,7 @@ export const ActionSheetComponent = ({
} else { } else {
await db.notebooks.notebook(note.id).pin(); await db.notebooks.notebook(note.id).pin();
} }
dispatch({ type: ACTIONS.PINNED }); dispatch({type: ACTIONS.PINNED});
localRefresh(item.type); localRefresh(item.type);
}, },
close: false, close: false,
@@ -322,7 +322,7 @@ export const ActionSheetComponent = ({
} else { } else {
await db.notebooks.notebook(note.id).favorite(); await db.notebooks.notebook(note.id).favorite();
} }
dispatch({ type: ACTIONS.FAVORITES }); dispatch({type: ACTIONS.FAVORITES});
localRefresh(item.type); localRefresh(item.type);
}, },
close: false, close: false,
@@ -336,28 +336,25 @@ export const ActionSheetComponent = ({
if (!note.id) return; if (!note.id) return;
if (note.locked) { if (note.locked) {
close(); close('unlock');
openVault(note, true, true, true, false, false);
return; return;
} else { } else {
db.vault db.vault
.add(note.id) .add(note.id)
.then(() => { .then(() => {
dispatch({ type: ACTIONS.NOTES }) dispatch({type: ACTIONS.NOTES});
eSendEvent(refreshNotesPage); eSendEvent(refreshNotesPage);
dispatch({ type: ACTIONS.PINNED }); dispatch({type: ACTIONS.PINNED});
close(); close();
}) })
.catch(async e => { .catch(async e => {
switch (e.message) { switch (e.message) {
case db.vault.ERRORS.noVault: case db.vault.ERRORS.noVault:
openVault(note, false); close('novault');
close();
break; break;
case db.vault.ERRORS.vaultLocked: case db.vault.ERRORS.vaultLocked:
openVault(note, true, true); close('valutlocked');
close();
break; break;
case db.vault.ERRORS.wrongPassword: case db.vault.ERRORS.wrongPassword:
close(); close();
@@ -376,13 +373,13 @@ export const ActionSheetComponent = ({
<TouchableOpacity <TouchableOpacity
key={tag} key={tag}
onPress={async () => { onPress={async () => {
let oldProps = { ...note }; let oldProps = {...note};
try { try {
await db.notes await db.notes
.note(note.id) .note(note.id)
.untag(oldProps.tags[oldProps.tags.indexOf(tag)]); .untag(oldProps.tags[oldProps.tags.indexOf(tag)]);
localRefresh(oldProps.type); localRefresh(oldProps.type);
dispatch({ type: ACTIONS.TAGS }); dispatch({type: ACTIONS.TAGS});
} catch (e) { } catch (e) {
localRefresh(oldProps.type); localRefresh(oldProps.type);
} }
@@ -423,7 +420,7 @@ export const ActionSheetComponent = ({
} else { } else {
await db.notes.note(note.id).color(color); await db.notes.note(note.id).color(color);
} }
dispatch({ type: ACTIONS.COLORS }); dispatch({type: ACTIONS.COLORS});
localRefresh(note.type); localRefresh(note.type);
}} }}
style={{ style={{
@@ -488,64 +485,64 @@ export const ActionSheetComponent = ({
const _renderColumnItem = item => const _renderColumnItem = item =>
(note.id && 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}
activeOpacity={opacity} activeOpacity={opacity}
onPress={() => { onPress={() => {
item.func(); item.func();
}} }}
style={{
width: '100%',
alignSelf: 'center',
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'flex-end',
paddingHorizontal: 12,
paddingVertical: pv,
}}>
<View
style={{ style={{
width: '100%',
alignSelf: 'center',
flexDirection: 'row', flexDirection: 'row',
justifyContent: 'space-between', alignItems: 'center',
alignItems: 'flex-end',
paddingHorizontal: 12,
paddingVertical: pv,
}}> }}>
<View <Icon
style={{ style={{
flexDirection: 'row', width: 30,
alignItems: 'center', }}
name={item.icon}
color={colors.pri}
size={SIZE.md}
/>
<Text
style={{
fontFamily: WEIGHT.regular,
fontSize: SIZE.sm,
color: colors.pri,
}}> }}>
<Icon {item.name}
style={{ </Text>
width: 30, </View>
}} {item.switch ? (
name={item.icon} <Icon
color={colors.pri} size={SIZE.lg + 2}
size={SIZE.md} color={item.on ? colors.accent : colors.icon}
/> name={item.on ? 'toggle-switch' : 'toggle-switch-off'}
<Text />
style={{ ) : (
fontFamily: WEIGHT.regular, undefined
fontSize: SIZE.sm, )}
color: colors.pri, {item.check ? (
}}> <Icon
{item.name} name={
</Text> item.on ? 'check-circle-outline' : 'checkbox-blank-circle-outline'
</View> }
{item.switch ? ( color={item.on ? colors.accent : colors.icon}
<Icon size={SIZE.lg + 2}
size={SIZE.lg + 2} />
color={item.on ? colors.accent : colors.icon} ) : null}
name={item.on ? 'toggle-switch' : 'toggle-switch-off'} </TouchableOpacity>
/> ) : null;
) : (
undefined
)}
{item.check ? (
<Icon
name={
item.on ? 'check-circle-outline' : 'checkbox-blank-circle-outline'
}
color={item.on ? colors.accent : colors.icon}
size={SIZE.lg + 2}
/>
) : null}
</TouchableOpacity>
) : null;
return ( return (
<View <View
@@ -572,73 +569,73 @@ export const ActionSheetComponent = ({
Please start writing to save your note. Please start writing to save your note.
</Text> </Text>
) : ( ) : (
<View <View
style={{
paddingHorizontal: 12,
alignItems: 'center',
marginVertical: 10,
}}>
<Text
numberOfLines={1}
style={{ style={{
paddingHorizontal: 12, color: colors.pri,
alignItems: 'center', fontSize: SIZE.sm + 1,
marginVertical: 10, fontFamily: WEIGHT.bold,
maxWidth: '100%',
}}> }}>
<Text {note.title.replace('\n', '')}
numberOfLines={1} </Text>
<Text
numberOfLines={2}
style={{
fontSize: SIZE.sm - 1,
color: colors.pri + 'B3',
fontFamily: WEIGHT.regular,
width: '100%',
textAlign: 'center',
maxWidth: '100%',
}}>
{note.type === 'notebook' && note.description
? note.description
: null}
{note.type === 'note'
? note.headline[item.headline.length - 1] === '\n'
? note.headline.slice(0, note.headline.length - 1)
: note.headline
: null}
</Text>
<Text
style={{
color: colors.icon,
fontSize: SIZE.xs - 1,
textAlignVertical: 'center',
fontFamily: WEIGHT.regular,
marginTop: 2.5,
}}>
{note.type === 'note'
? 'Last edited on ' + timeConverter(note.dateEdited)
: null}
{note.type !== 'note' && !note.dateDeleted
? 'Created on ' + timeConverter(note.dateCreated)
: null}
{note.dateDeleted
? 'Deleted on ' + timeConverter(note.dateDeleted)
: null}
</Text>
{note.type !== 'notebook' ? null : (
<View
style={{ style={{
color: colors.pri, flexDirection: 'row',
fontSize: SIZE.sm + 1, alignItems: 'center',
fontFamily: WEIGHT.bold, justifyContent: 'center',
maxWidth: '100%',
}}>
{note.title.replace('\n', '')}
</Text>
<Text
numberOfLines={2}
style={{
fontSize: SIZE.sm - 1,
color: colors.pri + 'B3',
fontFamily: WEIGHT.regular,
width: '100%', width: '100%',
textAlign: 'center',
maxWidth: '100%', maxWidth: '100%',
flexWrap: 'wrap',
}}> }}>
{note.type === 'notebook' && note.description {note && note.topics
? note.description ? note.topics.slice(1, 4).map(topic => (
: null}
{note.type === 'note'
? note.headline[item.headline.length - 1] === '\n'
? note.headline.slice(0, note.headline.length - 1)
: note.headline
: null}
</Text>
<Text
style={{
color: colors.icon,
fontSize: SIZE.xs - 1,
textAlignVertical: 'center',
fontFamily: WEIGHT.regular,
marginTop: 2.5,
}}>
{note.type === 'note'
? 'Last edited on ' + timeConverter(note.dateEdited)
: null}
{note.type !== 'note' && !note.dateDeleted
? 'Created on ' + timeConverter(note.dateCreated)
: null}
{note.dateDeleted
? 'Deleted on ' + timeConverter(note.dateDeleted)
: null}
</Text>
{note.type !== 'notebook' ? null : (
<View
style={{
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
width: '100%',
maxWidth: '100%',
flexWrap: 'wrap',
}}>
{note && note.topics
? note.topics.slice(1, 4).map(topic => (
<View <View
key={topic.dateCreated.toString() + topic.title} key={topic.dateCreated.toString() + topic.title}
style={{ style={{
@@ -661,29 +658,29 @@ export const ActionSheetComponent = ({
</Text> </Text>
</View> </View>
)) ))
: null} : null}
</View> </View>
)} )}
{note.type !== 'note' ? null : ( {note.type !== 'note' ? null : (
<Text <Text
style={{ style={{
color: colors.accent, color: colors.accent,
fontSize: SIZE.xs - 1, fontSize: SIZE.xs - 1,
textAlignVertical: 'center', textAlignVertical: 'center',
fontFamily: WEIGHT.regular, fontFamily: WEIGHT.regular,
marginTop: 2, marginTop: 2,
borderWidth: 1, borderWidth: 1,
textAlign: 'center', textAlign: 'center',
borderColor: colors.accent, borderColor: colors.accent,
paddingHorizontal: 5, paddingHorizontal: 5,
borderRadius: 2, borderRadius: 2,
}}> }}>
Synced Synced
</Text> </Text>
)} )}
</View> </View>
)} )}
{note.id || note.dateCreated ? ( {note.id || note.dateCreated ? (
<View <View
@@ -809,7 +806,8 @@ export const ActionSheetComponent = ({
position: 'absolute', position: 'absolute',
width: '100%', width: '100%',
height: '100%', height: '100%',
}}></TouchableOpacity> }}
/>
{note && note.tags ? note.tags.map(_renderTag) : null} {note && note.tags ? note.tags.map(_renderTag) : null}
<TextInput <TextInput
style={{ style={{

View File

@@ -210,31 +210,15 @@ export class DialogManager extends Component {
this._showSimpleDialog(TEMPLATE_PERMANANT_DELETE); this._showSimpleDialog(TEMPLATE_PERMANANT_DELETE);
break; break;
} }
case 'lock': {
this._showVaultDialog();
break;
}
case 'novault': { case 'novault': {
this.setState({ openVault(this.state.item, false);
vaultExists: false, }
}); case 'vaultlocked': {
this._showVaultDialog(); openVault(this.state.item, true, true);
break;
} }
case 'unlock': { case 'unlock': {
this.setState({ openVault(this.state.item, true, true, true, false, false);
isPerm: true,
});
this._showVaultDialog();
break;
}
case 'unlock_share': {
this.setState({
isPerm: false,
shareAfterUnlock: true,
});
this._showVaultDialog();
break;
} }
case 'notebook': { case 'notebook': {
this.showAddNotebook({item: this.state.item}); this.showAddNotebook({item: this.state.item});