From 15960fa5ac586bc1a18f6f9d24c86d5c4c7a652c Mon Sep 17 00:00:00 2001 From: balzack Date: Fri, 3 Jan 2025 09:57:43 -0800 Subject: [PATCH] support message delete --- app/client/mobile/src/message/Message.tsx | 41 ++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/app/client/mobile/src/message/Message.tsx b/app/client/mobile/src/message/Message.tsx index c4aa893c..53a27cd9 100644 --- a/app/client/mobile/src/message/Message.tsx +++ b/app/client/mobile/src/message/Message.tsx @@ -10,6 +10,7 @@ import { BinaryAsset } from './binaryAsset/BinaryAsset'; import { useMessage } from './useMessage.hook'; import {styles} from './Message.styled'; import { MediaAsset } from '../conversation/Conversatin'; +import { Confirm } from '../confirm/Confirm'; export function Message({ topic, card, profile, host, select, selected }: { topic: Topic, card: Card | null, profile: Profile | null, host: boolean, select: (id: null | string)=>void, selected: string }) { const { state, actions } = useMessage(); @@ -23,6 +24,43 @@ export function Message({ topic, card, profile, host, select, selected }: { topi const [editing, setEditing] = useState(false); const [editText, setEditText] = useState(''); const [saving, setSaving] = useState(false); + const [confirmParams, setConfirmParams] = useState({}); + const [confirmShow, setConfirmShow] = useState(false); + const [removing, setRemoving] = useState(false); + + const remove = () => { + setConfirmParams({ + title: state.strings.deleteMessage, + prompt: state.strings.messageHint, + cancel: { + label: state.strings.cancel, + action: () => setConfirmShow(false), + }, + confirm: { + label: state.strings.remove, + action: async () => { + if (!removing) { + setRemoving(true); + try { + await actions.remove(topicId); + } catch (err) { + console.log(err); + setConfirmParams({ + title: state.strings.operationFailed, + prompt: state.strings.tryAgain, + cancel: { + label: state.strings.cancel, + action: () => setConfirmShow(false), + }, + }); + } + setRemoving(false); + } + } + }, + }); + setConfirmShow(true); + }; const media = !assets ? [] : assets.map((asset: MediaAsset, index: number) => { if (asset.image || asset.encrypted?.type === 'image') { @@ -86,12 +124,13 @@ export function Message({ topic, card, profile, host, select, selected }: { topi {}} /> {}} /> - {}} /> + {}} /> {}} /> )} + ); }