Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

feat: add support for encryption progress

ammarahm-edbfd7ba523233
diff --git a/apps/mobile/src/components/AttachmentDialog/index.js b/apps/mobile/src/components/AttachmentDialog/index.js
index 692a90c54..bfdb42c57 100644
--- a/apps/mobile/src/components/AttachmentDialog/index.js
+++ b/apps/mobile/src/components/AttachmentDialog/index.js
@@ -1,26 +1,22 @@
-import React, {useEffect, useRef, useState} from 'react';
-import {Platform, TouchableOpacity, View} from 'react-native';
-import {FlatList} from 'react-native-gesture-handler';
+import React, { useEffect, useRef, useState } from 'react';
+import { TouchableOpacity, View } from 'react-native';
+import { FlatList } from 'react-native-gesture-handler';
import * as Progress from 'react-native-progress';
-import * as ScopedStorage from 'react-native-scoped-storage';
-import Sodium from 'react-native-sodium';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
-import {useTracked} from '../../provider';
-import {useAttachmentStore} from '../../provider/stores';
+import { useTracked } from '../../provider';
+import { useAttachmentStore } from '../../provider/stores';
import {
eSubscribeEvent,
- eUnSubscribeEvent,
- ToastEvent
+ eUnSubscribeEvent
} from '../../services/EventManager';
-import {db} from '../../utils/database';
+import { db } from '../../utils/database';
import {
eCloseAttachmentDialog,
eOpenAttachmentsDialog
} from '../../utils/Events';
import filesystem from '../../utils/filesystem';
-import {SIZE} from '../../utils/SizeUtils';
-import Storage from '../../utils/storage';
-import {ActionIcon} from '../ActionIcon';
+import { SIZE } from '../../utils/SizeUtils';
+import { ActionIcon } from '../ActionIcon';
import ActionSheetWrapper from '../ActionSheetComponent/ActionSheetWrapper';
import DialogHeader from '../Dialog/dialog-header';
import Paragraph from '../Typography/Paragraph';
@@ -45,7 +41,7 @@ export const AttachmentDialog = () => {
const open = item => {
setNote(item);
setVisible(true);
- let _attachments = db.attachments.ofNote(item.id)
+ let _attachments = db.attachments.ofNote(item.id,"files");
setAttachments(_attachments);
};
@@ -132,11 +128,14 @@ function getFileExtension(filename) {
return ext == null ? '' : ext[1];
}
-const Attachment = ({attachment, note, setNote}) => {
+export const Attachment = ({attachment,encryption}) => {
const [state] = useTracked();
const colors = state.colors;
const progress = useAttachmentStore(state => state.progress);
- const [currentProgress, setCurrentProgress] = useState(null);
+ const [currentProgress, setCurrentProgress] = useState(encryption ? {
+ type:"encrypt"
+ }: null);
+ const encryptionProgress = encryption ? useAttachmentStore(state => state.encryptionProgress) : null
const onPress = async () => {
if (currentProgress) {
@@ -227,10 +226,11 @@ const Attachment = ({attachment, note, setNote}) => {
</View>
</View>
- {currentProgress ? (
+ {currentProgress || encryptionProgress ? (
<TouchableOpacity
activeOpacity={0.9}
onPress={() => {
+ if (encryption) return;
db.fs.cancel(attachment.metadata.hash);
setCurrentProgress(null);
}}
@@ -242,7 +242,7 @@ const Attachment = ({attachment, note, setNote}) => {
}}>
<Progress.Circle
size={SIZE.xxl}
- progress={currentProgress?.value ? currentProgress?.value / 100 : 0}
+ progress={encryptionProgress ? encryptionProgress : currentProgress?.value ? currentProgress?.value / 100 : 0}
showsText
textStyle={{
fontSize: 10
@@ -255,7 +255,7 @@ const Attachment = ({attachment, note, setNote}) => {
</TouchableOpacity>
) : (
<ActionIcon
- onPress={() => onPress(attachment)}
+ onPress={() => !encryption && onPress(attachment)}
name="download"
size={SIZE.lg}
color={colors.pri}
diff --git a/apps/mobile/src/components/ProgressDialog/index.js b/apps/mobile/src/components/ProgressDialog/index.js
index 9ee26377f..4167c4a30 100644
--- a/apps/mobile/src/components/ProgressDialog/index.js
+++ b/apps/mobile/src/components/ProgressDialog/index.js
@@ -59,7 +59,7 @@ const ProgressDialog = () => {
marginBottom: 10,
paddingHorizontal: 12
}}>
- {!dialogData?.noProgress ? (
+ {!dialogData?.noProgress && !dialogData.component ? (
<ActivityIndicator size={50} color={colors.accent} />
) : dialogData?.noIcon ? null : (
<Icon
@@ -74,7 +74,7 @@ const ProgressDialog = () => {
{dialogData?.paragraph ? (
<Paragraph style={{textAlign: 'center'}}>
{dialogData?.paragraph}
- {!dialogData?.noProgress ? (
+ {!dialogData?.noProgress && !dialogData?.nowarn ? (
<Paragraph color={colors.errorText}>
{' '}
Do not close the app.
diff --git a/apps/mobile/src/provider/stores.ts b/apps/mobile/src/provider/stores.ts
index 4984b66cd..751111d59 100644
--- a/apps/mobile/src/provider/stores.ts
+++ b/apps/mobile/src/provider/stores.ts
@@ -160,22 +160,26 @@ interface AttachmentStore {
type: "upload" | "download",
}
},
- remove:(hash:string) => void
- setProgress: (sent: number, total: number, hash: string, recieved: number, type: "upload" | "download") => void
+ encryptionProgress: number,
+ setEncryptionProgress: (encryptionProgress) => void
+ remove: (hash: string) => void
+ setProgress: (sent: number, total: number, hash: string, recieved: number, type: "upload" | "download") => void,
+ loading:{total:number,current:number},
+ setLoading:(data:{total:number,current:number}) => void
}
export const useAttachmentStore = create<AttachmentStore>((set, get) => ({
progress: {},
- remove:(hash) => {
+ remove: (hash) => {
let _p = get().progress;
_p[hash] = null
tiny.call(EditorWebView, `
(function() {
let progress = ${JSON.stringify({
- loaded:1,
- total:1,
- hash
- })}
+ loaded: 1,
+ total: 1,
+ hash
+ })}
tinymce.activeEditor.execCommand("mceUpdateAttachmentProgress",progress);
})()`);
set({ progress: { ..._p } });
@@ -191,6 +195,10 @@ export const useAttachmentStore = create<AttachmentStore>((set, get) => ({
})()`);
set({ progress: { ..._p } });
},
+ encryptionProgress: null,
+ setEncryptionProgress: (encryptionProgress) => set({ encryptionProgress: encryptionProgress }),
+ loading:{total:0,current:0},
+ setLoading:(data) => set({loading:data})
}));
let { width, height } = Dimensions.get('window');