diff --git a/apps/mobile/app/components/attachments/attachment-item.js b/apps/mobile/app/components/attachments/attachment-item.js index c32286f9f..80e20713f 100644 --- a/apps/mobile/app/components/attachments/attachment-item.js +++ b/apps/mobile/app/components/attachments/attachment-item.js @@ -22,7 +22,6 @@ import { TouchableOpacity, View } from "react-native"; import Icon from "react-native-vector-icons/MaterialCommunityIcons"; import { db } from "../../common/database"; import { useAttachmentProgress } from "../../hooks/use-attachment-progress"; -import { useAttachmentStore } from "../../stores/use-attachment-store"; import { useThemeStore } from "../../stores/use-theme-store"; import { formatBytes } from "../../utils"; import { SIZE } from "../../utils/size"; @@ -47,9 +46,7 @@ export const AttachmentItem = ({ attachment, encryption, setAttachments }) => { attachment, encryption ); - const encryptionProgress = useAttachmentStore( - (state) => state.encryptionProgress - ); + const onPress = () => { Actions.present(attachment, setAttachments, attachment.metadata.hash); }; @@ -125,9 +122,7 @@ export const AttachmentItem = ({ attachment, encryption, setAttachments }) => { - {currentProgress || - (encryptionProgress && encryptionProgress !== "0.00") || - encryption ? ( + {currentProgress ? ( { @@ -144,13 +139,7 @@ export const AttachmentItem = ({ attachment, encryption, setAttachments }) => { > null, item }) => { } async function showAttachments() { - AttachmentDialog.present(); + AttachmentDialog.present(item); } async function exportNote() { diff --git a/apps/mobile/app/hooks/use-attachment-progress.ts b/apps/mobile/app/hooks/use-attachment-progress.ts index a47bbfad5..3c3a8c122 100644 --- a/apps/mobile/app/hooks/use-attachment-progress.ts +++ b/apps/mobile/app/hooks/use-attachment-progress.ts @@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -import { useState } from "react"; +import { useEffect, useState } from "react"; import { useAttachmentStore } from "../stores/use-attachment-store"; type AttachmentProgress = { @@ -41,22 +41,24 @@ export const useAttachmentProgress = ( : undefined ); - const attachmentProgress = progress?.[attachment.metadata.hash]; - if (attachmentProgress) { - const type = attachmentProgress.type; - const loaded = - attachmentProgress.type === "download" - ? attachmentProgress.recieved - : attachmentProgress.sent; - const value = loaded / attachmentProgress.total; - setCurrentProgress({ - value: value * 100, - percent: (value * 100).toFixed(0) + "%", - type: type - }); - } else { - setCurrentProgress(undefined); - } + useEffect(() => { + const attachmentProgress = progress?.[attachment.metadata.hash]; + if (attachmentProgress) { + const type = attachmentProgress.type; + const loaded = + attachmentProgress.type === "download" + ? attachmentProgress.recieved + : attachmentProgress.sent; + const value = loaded / attachmentProgress.total; + setCurrentProgress({ + value: value * 100, + percent: (value * 100).toFixed(0) + "%", + type: type + }); + } else { + setCurrentProgress(undefined); + } + }, [attachment.metadata.hash, progress]); return [currentProgress, setCurrentProgress]; };