From f6aba87097b0566bbf2bb0bc975ddaf24bb1c98e Mon Sep 17 00:00:00 2001 From: zubiden <19638254+zubiden@users.noreply.github.com> Date: Wed, 4 Jun 2025 20:41:10 +0200 Subject: [PATCH] Pin Message Modal: Use checkbox for parameter (#5965) Co-authored-by: Arno van Liere <46238387+arnovanliere@users.noreply.github.com> --- src/components/common/PinMessageModal.tsx | 44 ++++++++++++----------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/src/components/common/PinMessageModal.tsx b/src/components/common/PinMessageModal.tsx index 07d66bfc3..5f80620a7 100644 --- a/src/components/common/PinMessageModal.tsx +++ b/src/components/common/PinMessageModal.tsx @@ -1,5 +1,4 @@ -import type { FC } from '../../lib/teact/teact'; -import React, { memo, useCallback } from '../../lib/teact/teact'; +import React, { memo, useState } from '../../lib/teact/teact'; import { getActions, withGlobal } from '../../global'; import { @@ -13,9 +12,11 @@ import { selectChat, selectIsChatWithSelf, selectUser } from '../../global/selec import { isUserId } from '../../util/entities/ids'; import renderText from './helpers/renderText'; +import useLastCallback from '../../hooks/useLastCallback'; import useOldLang from '../../hooks/useOldLang'; import Button from '../ui/Button'; +import Checkbox from '../ui/Checkbox'; import Modal from '../ui/Modal'; export type OwnProps = { @@ -35,7 +36,7 @@ type StateProps = { contactName?: string; }; -const PinMessageModal: FC = ({ +const PinMessageModal = ({ isOpen, chatId, messageId, @@ -45,22 +46,21 @@ const PinMessageModal: FC = ({ canPinForAll, contactName, onClose, -}) => { +}: OwnProps & StateProps) => { const { pinMessage } = getActions(); - const handlePinMessageForAll = useCallback(() => { - pinMessage({ - chatId, messageId, isUnpin: false, - }); - onClose(); - }, [chatId, messageId, onClose]); + const [shouldPinForAll, setShouldPinForAll] = useState(true); - const handlePinMessage = useCallback(() => { + const handlePinMessage = useLastCallback(() => { pinMessage({ - chatId, messageId, isUnpin: false, isOneSide: true, isSilent: true, + chatId, + messageId, + isUnpin: false, + isOneSide: !shouldPinForAll, + isSilent: !shouldPinForAll, }); onClose(); - }, [chatId, messageId, onClose]); + }); const lang = useOldLang(); @@ -84,17 +84,19 @@ const PinMessageModal: FC = ({ title={lang('PinMessageAlertTitle')} >

{renderMessage()}

-
+ {canPinForAll && ( + + )} +
- {canPinForAll && ( - - )}